You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory leak: arena_extent_dalloc() is not called for extents for which arena_extent_split() failed #2815
Thanks for reporting and tracking this down. It looks there's custom hooks installed, can you share the path leading to the split hook? Did it reach this function?
@ldorau thanks for following up. The error path is triggered by the extent split failure, which I suspect is not the expected behavior by your custom extent hooks -- can you please check if your split hook is set to split allowed (i.e. returning false)? Usually there is no much point disallowing split / merge of extents on mmap based systems.
@ldorau thanks for following up. The error path is triggered by the extent split failure, which I suspect is not the expected behavior by your custom extent hooks -- can you please check if your split hook is set to split allowed (i.e. returning false)? Usually there is no much point disallowing split / merge of extents on mmap based systems.
The failure of the extent split hook IS the expected behavior in my case. I use an own simple allocator that does not support splitting and merging.
That's exactly what this issue is about: there is a memory leak in jemalloc: arena_extent_dalloc() is not called for extents for which arena_extent_split() fails.
When split / merge isn't allowed, you will need to disable retain. that option always attempts to over-reserve but doesn't help without split. In fact when retain is enabled, dalloc will never be called by default (purge will be called instead to only return the physical memory).
Try setting "MALLOC_CONF=retain:false" which will do the alloc / dalloc pair you are looking for.
As for the error handling inside the retain path, it can be improved indeed (see the comments around extents_abandon_vm). But at the same time it's not the intended use case for no split, so avoiding the retain option should be the right solution for you.
Running with MALLOC_CONF="retain:false" nor adding const char *malloc_conf = "retain:false"; to the code does not help, the output is the same like it had been before:
$ MALLOC_CONF="retain:false" ./test/test_jemalloc_pool --gtest_filter="*.allocFree/1*"
[PID:20456 TID:20456 INFO UMF] utils_log_init: Logger enabled (UMF version: 0.11.0-dev4.git12.g10516cf3, level: DEBUG, flush: DEBUG, pid: yes, timestamp: no)
[PID:20456 TID:20456 DEBUG UMF] umf_ba_create_global: UMF base allocator created
[PID:20456 TID:20456 DEBUG UMF] umfMemoryTrackerCreate: tracker created, handle=0x7fa8e5928068, alloc_segments_map=0x7fa8e5928070
[PID:20456 TID:20456 DEBUG UMF] umfInit: UMF tracker created
[PID:20456 TID:20456 DEBUG UMF] umfInit: UMF IPC cache initialized
[PID:20456 TID:20456 DEBUG UMF] umfInit: UMF library initialized
[PID:20456 TID:20456 INFO UMF] utils_log_init: Logger enabled (UMF version: 0.11.0-dev4.git12.g10516cf3, level: DEBUG, flush: DEBUG, pid: yes, timestamp: no)
Running main() from /home/ldorau/work/unified-memory-framework/build/_deps/googletest-src/googletest/src/gtest_main.cc
Note: Google Test filter = *.allocFree/1*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from jemallocPoolTest/umfPoolTest
[ RUN ] jemallocPoolTest/umfPoolTest.allocFree/1
[PID:20456 TID:20456 DEBUG UMF] umfTrackingMemoryProviderCreate: upstream=0x7fa8e5928168, tracker=0x7fa8e5928068, pool=0x7fa8e5928268, ipcCache=0x7fa8e5916008, hIpcMappedCache=0x7fa8e5939068
[PID:20456 TID:20456 INFO UMF] umfPoolCreateInternal: Memory pool created: 0x7fa8e5928268
[PID:20456 TID:20456 DEBUG UMF] umfMemoryTrackerAddAtLevel: memory region is added, tracker=0x7fa8e5928068, level=0, pool=0x7fa8e5928268, ptr=0x7fa8e49ff000, size=2097152
[PID:20456 TID:20456 ERROR UMF] trackingAllocationSplit: upstream provider failed to split the region
[PID:20456 TID:20456 ERROR UMF] trackingAllocationSplit: failed to split memory region: ptr=0x7fa8e49ff000, totalSize=2097152, firstSize=4096
[PID:20456 TID:20456 DEBUG UMF] umfMemoryTrackerAddAtLevel: memory region is added, tracker=0x7fa8e5928068, level=0, pool=0x7fa8e5928268, ptr=0x7fa8e5900000, size=4096
[PID:20456 TID:20456 DEBUG UMF] umfMemoryTrackerRemove: memory region removed: tracker=0x7fa8e5928068, level=0, pool=0x7fa8e5928268, ptr=0x7fa8e5900000, size=4096
[PID:20456 TID:20456 ERROR UMF] check_if_tracker_is_empty: [0] ptr = 0x7fa8e49ff000, pool = 0x7fa8e5928268, size = 2097152
[PID:20456 TID:20456 ERROR UMF] check_if_tracker_is_empty: tracking provider of pool 0x7fa8e5928268 is not empty! (1 items left)
test_jemalloc_pool: /home/ldorau/work/unified-memory-framework/src/provider/provider_tracking.c:827: check_if_tracker_is_empty: Assertion `n_items == 0 && "tracking provider is not empty!"' failed.
Aborted
Did you build with a custom prefix? If so you need to prefix the malloc_conf as well. One quick way to check if it takes effect is, adding a garbage string into it, e.g. "abort_conf:true,abcd:1234" which will abort on init.
When retain is disabled, the extent_alloc_retained path isn't called so that can't be the source of the issue anymore.
Did you build with a custom prefix? If so you need to prefix the malloc_conf as well.
Yes, we build jemalloc with a custom prefix, but we cannot disable retain permanently, because it is needed in most cases (splitting is supported in most cases).
Can retain be disabled in runtime somehow? Unfortunately setting the environment variable MALLOC_CONF="retain:false" does not work in our case (see #2815 (comment) above),
Activity
interwq commentedon Mar 14, 2025
Thanks for reporting and tracking this down. It looks there's custom hooks installed, can you share the path leading to the split hook? Did it reach this function?
jemalloc/src/extent.c
Line 738 in 81f35e0
I wonder if we are missing some error handling after the split failure somewhere or the above case
ldorau commentedon Mar 15, 2025
The path leading to the split hook:
ldorau commentedon Mar 15, 2025
Hi @interwq I have prepared a reproducer for you:
GH branch: https://github.com/ldorau/unified-memory-framework/tree/refs/heads/jemalloc_issue_2815
repro on GHA CI: https://github.com/ldorau/unified-memory-framework/actions/runs/13873571710/job/38823137456
You can clone my repo https://github.com/ldorau/unified-memory-framework/tree/refs/heads/jemalloc_issue_2815 at the jemalloc_issue_2815 branch and reproduce the issue locally or on the GHA CI:
ldorau commentedon May 13, 2025
ping, any updates on this issue?
interwq commentedon May 14, 2025
@ldorau thanks for following up. The error path is triggered by the extent split failure, which I suspect is not the expected behavior by your custom extent hooks -- can you please check if your split hook is set to split allowed (i.e. returning false)? Usually there is no much point disallowing split / merge of extents on
mmapbased systems.ldorau commentedon May 14, 2025
@interwq
arena_extent_dalloc()is not called for extents for whicharena_extent_split()fails.interwq commentedon May 14, 2025
When split / merge isn't allowed, you will need to disable retain. that option always attempts to over-reserve but doesn't help without split. In fact when retain is enabled, dalloc will never be called by default (purge will be called instead to only return the physical memory).
Try setting "MALLOC_CONF=retain:false" which will do the alloc / dalloc pair you are looking for.
As for the error handling inside the retain path, it can be improved indeed (see the comments around extents_abandon_vm). But at the same time it's not the intended use case for no split, so avoiding the retain option should be the right solution for you.
ldorau commentedon May 14, 2025
Running with
MALLOC_CONF="retain:false"nor addingconst char *malloc_conf = "retain:false";to the code does not help, the output is the same like it had been before:interwq commentedon May 14, 2025
Did you build with a custom prefix? If so you need to prefix the
malloc_confas well. One quick way to check if it takes effect is, adding a garbage string into it, e.g. "abort_conf:true,abcd:1234" which will abort on init.When retain is disabled, the extent_alloc_retained path isn't called so that can't be the source of the issue anymore.
ldorau commentedon May 15, 2025
Yes, we build jemalloc with a custom prefix, but we cannot disable retain permanently, because it is needed in most cases (splitting is supported in most cases).
Can retain be disabled in runtime somehow? Unfortunately setting the environment variable
MALLOC_CONF="retain:false"does not work in our case (see #2815 (comment) above),