atproto relay implementation in zig zlay.waow.tech
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

add malloc_trim(0) to GC loop — diagnostic for RSS fragmentation

calls malloc_trim(0) every 10 minutes to ask glibc to return free
pages to the OS. if RSS drops after each trim, the linear growth is
malloc fragmentation rather than a true leak.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

zzstoatzz df3d9bfe 8ab77ea7

+7
+7
src/main.zig
··· 262 262 log.info("relay stopped cleanly", .{}); 263 263 } 264 264 265 + const malloc_h = @cImport(@cInclude("malloc.h")); 266 + 265 267 fn gcLoop(dp: *event_log_mod.DiskPersist) void { 266 268 const gc_interval: u64 = 10 * 60; // 10 minutes in seconds 267 269 while (!shutdown_flag.load(.acquire)) { ··· 277 279 dp.gc() catch |err| { 278 280 log.warn("event log GC failed: {s}", .{@errorName(err)}); 279 281 }; 282 + 283 + // ask glibc to return free pages to the OS — diagnostic for malloc fragmentation. 284 + // if RSS drops after each trim, the growth is fragmentation, not a leak. 285 + _ = malloc_h.malloc_trim(0); 286 + log.info("gc: malloc_trim complete", .{}); 280 287 } 281 288 } 282 289