Entirely avoid free and shrinking realloc during shutdown
Categories
(Core :: Memory Allocator, enhancement)
Tracking
()
People
(Reporter: jstutte, Assigned: jstutte)
References
Details
Attachments
(1 obsolete file)
Bug 1903758 already suppresses the scheduling of purges entirely during shutdown. We could avoid more book-keeping efforts regarding free
and realloc
, that is we could:
- skip any
free
entirely, just leaking the memory - skip shrinking reallocs, returning just the original memory
Assignee | ||
Comment 1•5 months ago
|
||
When a process is about to shutdown, there is no point in spending effort to purge our memory, once it exits it will be returned to the system, anyways. Rather than having explicit different code paths everywhere, we can signal jemalloc via a global flag, that it can stop to bother. Once flipped, jemalloc will not execute any purge, and also realloc will only have effect if the new size is bigger than the old.
For content processes, we flip the flag when shutdown is first notified. This notification also interrupts content JS execution, such that there should be no more significant allocations until shutdown.
For the parent process, this patch chooses the highest risk by associating the flip with entering shutdown phase AppShutdownConfirmed, just to verify the potential impact. FWIW, given we only block purge, we do not expect to see unnecessary allocations of system memory.
There might be room for doing more on huge object free, which currently is unaltered.
Note that in leak checking builds we do not skip anything, of course.
This is a PoC patch and might want some adjustment to integrate better with jemalloc. There might be relevant telemetry already in place to monitor the effect.
Note that the profiler currently gets fooled about memory consumption as we bail out at lower levels and would probably need some adjustment, if we want to go this route.
Assignee | ||
Comment 2•5 months ago
|
||
The PoC patch needs most likely to be re-worked quite a bit.
Updated•2 months ago
|
Updated•1 month ago
|
Updated•1 month ago
|
Updated•1 month ago
|
Assignee | ||
Comment 3•1 month ago
|
||
Bug 1903758 will already bring us most of the value this patch wanted to achieve. There might be two things here:
- Bug 1809115 is still valid, as lazy purge will reduce the jank from the large tree walk by "only" ~30%
- In the (unlikely) case we decide to not enable lazy purge everywhere, we could just force enable it when shutdown has started.
Description
•