Repository navigation
Conversation
default_numa_policy kept its node -> thread-index table in a function-local static std::vector wrapped in __indestructible, so it was deliberately never destroyed. That was introduced to avoid a static destruction order problem back when the policy was a thread_local object that a pool referred to by pointer. The policy is a value type now and the pool owns its copy, so there is no reason for the table to be global anymore. Because it was never destroyed, the heap block was leaked every time a shared library using static_thread_pool was unloaded (dlopen/dlclose in a loop grew the heap by one block per cycle). LeakSanitizer can't see it either, since the static keeps pointing at the block while the library is loaded. Make the table a member of default_numa_policy, computed in its constructor, so its lifetime is tied to the pool that uses it. Behavior is unchanged: the same values are computed the same way. Fixes NVIDIA#1370
ericniebler
approved these changes
Nov 23, 2026
Collaborator
|
/ok to test b5ea160 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! This is for #1370, the NUMA policy in
static_thread_poolleaking an object at shutdown.What was going on
default_numa_policykept its node -> thread-index table in a function-localstatic std::vector<int>wrapped in__indestructible, so it was never destroyed on purpose. #1369 did that to dodge a static destruction order problem, back when the policy was athread_localobject that the pool held by pointer.But the policy is a type-erased value type now and the pool stores its own copy, so the table doesn't need to outlive anything except the pool that uses it. The global is leftover from the old design, and since it's immortal it leaks one block every time a shared library that uses
static_thread_poolis unloaded. LeakSanitizer can't flag it because the static still points at the block while the library is loaded, which is probably why it went unnoticed.The fix
The table is now a member of
default_numa_policy, built in its constructor with the same logic as before, so its lifetime is tied to the pool that holds the policy. That removes_node_to_thread_indexand the__indestructibleuse there. I kept thenodemask::any()one sincenodemaskis trivially destructible, so it can't leak.How I checked it
.sothat builds astatic_thread_pool(withSTDEXEC_ENABLE_NUMAon), loaded and unloaded 300 times withdlopen/dlclose, confirming each time that the library really unloaded. Heap in use grew by 32 bytes per cycle (9600 bytes over 300 cycles) before the change and by 0 bytes after, using the same script back to back.get_numa_policy()gives the same results before and after (node count, per-node CPU count,thread_index_to_nodefor the first 64 indices), and a copy of the policy behaves the same.test_static_thread_pool.cpppasses with NUMA enabled (11 test cases), and the two benchmark examples that derive fromdefault_numa_policystill compile.Some caveats: I only have a single-NUMA-node machine (WSL), so I couldn't exercise a multi-node layout. The calculation itself is unchanged and I'd welcome a run on real multi-node hardware. There's also no regression test in the repo, since NUMA is off by default and showing the leak needs a
dlopenloop. Happy to add one if you'd like. Also, the table is now computed once per policy rather than once per process, so eachget_numa_policy()call does a few libnuma queries. Pool creation already spawns threads, so I don't expect that to matter.