mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 21:23:06 +00:00
Allow resuming per-CPU arena selection via thread.arena (#2957)
* Allow resuming per-CPU arena selection via thread.arena With percpu_arena enabled, thread.arena control is one-directional. A thread can be bound to a manually created arena (an index at or above the per-CPU auto range) to route a bounded region of work to a dedicated, long-lived arena, but there is no way back: thread_arena_ctl returns EPERM for any index within the auto range, and arena_choose_impl only re-selects a per-CPU arena for threads whose current arena is already in that range. So once a thread is bound to a manual arena it stays pinned there forever, and its later allocations land there instead of following the CPU. Treat setting thread.arena to an index within the per-CPU range as a request to resume automatic per-CPU selection: hand the thread back to percpu management (rebinding it to the current CPU's arena via percpu_arena_update) and return 0 instead of EPERM. Binding to a manual arena is unchanged. The requested index is advisory; under percpu the thread is governed by its current CPU, so it resumes on the current CPU's arena regardless of the value passed. Add test/unit/percpu_arena_resume covering the manual-arena to resume round trip with allocs & dallocs happening meanwhile, and update test_thread_arena, which asserted the old EPERM. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -764,12 +764,17 @@ TEST_BEGIN(test_thread_arena) {
|
||||
0, "Unexpected mallctl() failure");
|
||||
new_arena_ind = percpu_arena_ind_limit(opt_percpu_arena) - 1;
|
||||
if (old_arena_ind != new_arena_ind) {
|
||||
/*
|
||||
* Setting thread.arena to an index within the per-CPU
|
||||
* range resumes automatic per-CPU selection rather than
|
||||
* failing (see test/unit/percpu_arena_resume.c).
|
||||
*/
|
||||
expect_d_eq(
|
||||
mallctl("thread.arena", (void *)&old_arena_ind, &sz,
|
||||
(void *)&new_arena_ind, sizeof(unsigned)),
|
||||
EPERM,
|
||||
"thread.arena ctl "
|
||||
"should not be allowed with percpu arena");
|
||||
0,
|
||||
"thread.arena within the per-CPU range should "
|
||||
"resume per-CPU selection");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user