Repository navigation
Description
Environment Information
- UMF version (hash commit or a tag): main
- OS(es) version(s): Ubuntu 22.04.5 LTS
Please provide a reproduction of the bug:
I have created PR #902 as a reproducer for this bug.
How often bug is revealed:
The bug is always reproduced on Ubuntu 22.04.4, but works fine on Ubuntu 24.04.1. Probably it is caused by different versions of libjemalloc library.
Actual behavior:
Tests are crashed with SEGFAULT. The reason is that the jemalloc pool calls memory provider with an invalid pointer and an internal check of the base allocator caught this.
Here is an output of the test enabled in the PR #902 with UMF logs.
Run on the Ubuntu22.04.4:
svinogra@gkdse-dnp-01:~/unified-memory-framework/build$ UMF_LOG="level:debug;flush:debug;output:stdout" LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH ./test/umf_test-jemalloc_pool --gtest_filter=jemallocPoolTest/umfPoolTest.allocFree/1
[INFO UMF] utils_log_init: Logger enabled (UMF version: 0.10.0-dev.git311.ga3050d4, level: DEBUG, flush: DEBUG, pid: no, timestamp: no)
[DEBUG UMF] umfMemoryTrackerCreate: tracker created, handle=0x7ff9754ad068, segment map=0x7ff9754a6008
Running main() from /user/svinogra/unified-memory-framework/build/_deps/googletest-src/googletest/src/gtest_main.cc
Note: Google Test filter = jemallocPoolTest/umfPoolTest.allocFree/1
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from jemallocPoolTest/umfPoolTest
[ RUN ] jemallocPoolTest/umfPoolTest.allocFree/1
[DEBUG UMF] umfTrackingMemoryProviderCreate: upstream=0x7ff9741f7068, tracker=0x7ff9754ad068, pool=0x7ff9754a80e8, ipcCache=0x7ff974c5e008, hIpcMappedCache=0x7ff9754b0068
[INFO UMF] umfPoolCreateInternal: Memory pool created: 0x7ff9754a80e8
[DEBUG UMF] umfMemoryTrackerAdd: memory region is added, tracker=0x7ff9754ad068, ptr=0x7ff9717ff000, pool=0x7ff9754a80e8, size=2097152
[ERROR UMF] trackingAllocationSplit: upstream provider failed to split the region
[DEBUG UMF] umfMemoryTrackerAdd: memory region is added, tracker=0x7ff9754ad068, ptr=0x7ff9741e7000, pool=0x7ff9754a80e8, size=4096
[DEBUG UMF] umfMemoryTrackerRemove: memory region removed: tracker=0x7ff9754ad068, ptr=0x7ff9741e7000, size=4096
[ERROR UMF] umfMemoryTrackerRemove: pointer 0x7ff971a00000 not found in the map
[ERROR UMF] trackingFree: failed to remove the region from the tracker, ptr=0x7ff971a00000, size=2097152, ret = 2147483646
umf_test-jemalloc_pool: /user/svinogra/unified-memory-framework/src/base_alloc/base_alloc.c:281: umf_ba_free: Assertion `pool_contains_pointer(pool, ptr)' failed.
Aborted (core dumped)
The jemalloc pool does two allocations from memory provider (see umfMemoryTrackerAdd in the log). AS a result it gets two buffers: ptr=0x7ff9717ff000, size=2097152 and ptr=0x7ff9741e7000, size=4096. At the end of the test, the jemalloc pool deallocates these buffers (see umfMemoryTrackerRemove), but one of the pointers is incorrect: [ERROR UMF] umfMemoryTrackerRemove: pointer 0x7ff971a00000 not found in the map.
Run on the Ubuntu 24.04.01:
❯ UMF_LOG="level:debug;flush:debug;output:stdout" LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH ./test/umf_test-jemalloc_pool --gtest_filter=jemallocPoolTest/umfPoolTest.allocFree/1
[INFO UMF] utils_log_init: Logger enabled (UMF version: 0.10.0-dev.git308.g64456b7, level: DEBUG, flush: DEBUG, pid: no, timestamp: no)
[DEBUG UMF] umfMemoryTrackerCreate: tracker created, handle=0x7d2c6903e068, segment map=0x7d2c69037008
Running main() from /home/vinser52/repos/unified-memory-framework/build/_deps/googletest-src/googletest/src/gtest_main.cc
Note: Google Test filter = jemallocPoolTest/umfPoolTest.allocFree/1
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from jemallocPoolTest/umfPoolTest
[ RUN ] jemallocPoolTest/umfPoolTest.allocFree/1
[DEBUG UMF] umfTrackingMemoryProviderCreate: upstream=0x7d2c68f08068, tracker=0x7d2c6903e068, pool=0x7d2c690390e8, ipcCache=0x7d2c69036008, hIpcMappedCache=0x7d2c69041068
[INFO UMF] umfPoolCreateInternal: Memory pool created: 0x7d2c690390e8
[DEBUG UMF] umfMemoryTrackerAdd: memory region is added, tracker=0x7d2c6903e068, ptr=0x7d2c67001000, pool=0x7d2c690390e8, size=2097152
[ERROR UMF] trackingAllocationSplit: upstream provider failed to split the region
[DEBUG UMF] umfMemoryTrackerAdd: memory region is added, tracker=0x7d2c6903e068, ptr=0x7d2c68eef000, pool=0x7d2c690390e8, size=4096
[DEBUG UMF] umfMemoryTrackerRemove: memory region removed: tracker=0x7d2c6903e068, ptr=0x7d2c68eef000, size=4096
[ERROR UMF] clear_tracker_for_the_pool: tracking provider of pool 0x7d2c690390e8 is not empty! (1 items left)
[INFO UMF] umfPoolDestroy: Memory pool destroyed: 0x7d2c690390e8
[ OK ] jemallocPoolTest/umfPoolTest.allocFree/1 (0 ms)
[----------] 1 test from jemallocPoolTest/umfPoolTest (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.
As you can see on the Ubuntu 24.04.01 tests passed. But there is only one deallocation (see umfMemoryTrackerRemove) while jemalloc still allocates two buffers (see umfMemoryTrackerAdd).
Expected behavior:
Test with BA_PROVIDER should pass
Details
Additional information about Priority and Help Requested:
I think there is an issue with libjemalloc. Need to confirm. If so, we need to fix our CI to use appropriate version of libjemalloc.
Requested priority: High. It blocks PR #901
Activity
Fix umf_ba_free() - do not assert on unknown pointer
vinser52 commentedon Nov 18, 2024
I just checked how it works with the OS provider on Ubuntu 22.04:
As you can see there are two
umfMemoryTrackerAddcalls and threeumfMemoryTrackerRemovecalls - the last one has invalid pointer again. So the issue is not memory provider-specific and is not related to split/merge functionality (OS provider supports it, right?).ldorau commentedon Nov 18, 2024
With jemalloc v5.3.0:
it does not crash:
vinser52 commentedon Nov 18, 2024
It is the same what I see on the Ubuntu 24.04. But still there is an issue. Even the test did not crash the jemalloc makes 2 allocations from the provider but return back only one. As a result we have the following error in the log:
If I remember in the past we had an assert if tracker is not empty for the pool. @ldorau did we change the logic of this check?
ldorau commentedon Nov 18, 2024
Yes, there was an assert and it was removed:
vinser52 commentedon Nov 18, 2024
But again, it is a memory leak and we just deleted an assert that detected this leak instead of trying to fix the issue itself.
igchor commentedon Nov 18, 2024
Just a note: having the assertion there was wrong, in my opinion. In general, we shouldn't force the application to not have any leaks. We can produce some logs or enable checking for leaks under some option (or, ideally, just properly support memcheck and asan), but by default, we should not assert/crash.
vinser52 commentedon Nov 18, 2024
In general, I agree that we should not force applications to not have memory leaks.
But two thoughts from my side regarding this particular case:
BTW, do we understand why jemalloc behaves in such way?
igchor commentedon Nov 18, 2024
From what I remember, this assert will be triggered if an application does not free all allocations prior to calling pool/provider destroy, so this is not only a check for internal consistency.
vinser52 commentedon Nov 18, 2024
In that case I agree.
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
ldorau commentedon Dec 2, 2024
@vinser52 The fix is ready, please review: #941
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS
Link statically with custom jemalloc with disabled initial TLS