Snapshot the list of arenas before processing them
Categories
(Core :: Memory Allocator, enhancement)
Tracking
()
People
(Reporter: pbone, Unassigned)
References
(Depends on 2 open bugs)
Details
Bug 1364359 will add reference counting for arenas. While working on it this code could cause a problem.
MutexAutoLock lock(mLock);
for (RefPtr<arena_t> arena : iter()) {
if (!arena->IsMainThreadOnly() || IsOnMainThreadWeak()) {
RemoveFromOutstandingPurges(arena);
arena->PurgeLoop(aCond, aCaller);
}
}
if the last reference to an arena is in the list of outstanding purges then the reference could be dropped by this loop. This is bad because arena_t destructor needs to remove a weak reference in the arena collection, but that's already locked by this code.
I will have Bug 1364359 work-around this but a future solution might be to build a temporary ref counted collection of arenas while holding the lock, then release the lock while processing them. This means the lock would be held for a MUCH shorter duration and may block other threads less, Currently the only performance-sensitive code using this lock is in jemalloc_stats_lite which is used by the profiler. Note that GetById doesn't use this lock in any of our builds since Bug 2004860.
| Reporter | ||
Comment 1•2 months ago
|
||
Actually this is simpler than the work-around I had in mind so I'll do it ahead of Bug 1364359.
| Reporter | ||
Comment 2•2 months ago
|
||
The changes to the iterator can go in Bug 1364359, they need the reference counting there as a dependency anyway.
Description
•