Closed Bug 1920450 Opened 5 months ago Closed 1 month ago

Entirely avoid free and shrinking realloc during shutdown

Categories

(Core :: Memory Allocator, enhancement)

enhancement

Tracking

()

RESOLVED WONTFIX

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

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.

The PoC patch needs most likely to be re-worked quite a bit.

Attachment #9426447 - Attachment description: WIP: Bug 1920450 - PoC: Avoid purge in our memory allocator after shutdown started. → WIP: Bug 1920450 - PoC: Avoid needless memory releases after shutdown started.
Assignee: nobody → jstutte
Attachment #9426447 - Attachment description: WIP: Bug 1920450 - PoC: Avoid needless memory releases after shutdown started. → Bug 1920450 - Avoid needless memory releases after shutdown started. r?pbone,smaug
Status: NEW → ASSIGNED
Attachment #9426447 - Attachment description: Bug 1920450 - Avoid needless memory releases after shutdown started. r?pbone,smaug → Bug 1920450 - Avoid (more) needless memory releases after shutdown started. r?pbone,smaug
Attachment #9426447 - Attachment is obsolete: true

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.
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → WONTFIX
See Also: → 1809115
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: