mozjemalloc: add compile-time purge instrumentation to measure released and refaulted pages
Categories
(Core :: Memory Allocator, task)
Tracking
()
People
(Reporter: jstutte, Assigned: jstutte)
References
Details
Attachments
(1 external file)
Tuning when mozjemalloc purges dirty pages (lazy purge, reuse grace, the low water purge from bug 2070900) is a trade-off between resident memory and the cost of faulting released pages back in. Today we can only see one side of it: about:memory and AWSY show what stays resident, but nothing tells us what a purge released, why, or whether those pages were needed again shortly after. Whole-process minor fault counts (/proc/<pid>/stat, perf stat -e minor-faults) include everything else the process touches, so they cannot attribute a change to the allocator, let alone to one kind of purge.
During the bug 2070900 work we used local try-only patches that logged this from inside the allocator. This bug is about turning the useful part of them into a patch that stays in the tree, compiled out by default (behind a define such as MOZJEMALLOC_PURGE_LOG), so that the next person looking at purge behaviour does not have to rebuild the tooling.
What we want to measure:
- Every purge, one line per
arena_t::PurgeLoopcall:- arena id and label (DOM, JS, Default, ...), caller, purge condition (threshold, unconditional, low water target) and result
- dirty pages before and after, the arena's dirty page limit, the target of a low water purge and the low water mark it was sized from
- pages released, and how many of them came from spare chunks
- duration
- Refaults: pages that a purge released and that the allocator later hands out again (
SplitAndAllocRuntaking a madvised or decommitted page). Cumulative per arena, and separately for pages released by low water purges, which are tagged in the page map when they are released. This is the number that tells whether a purge released pages the arena still needed. - Arena growth: new chunks mapped, spare chunks reused, number of spare chunks and the dirty pages in them.
Output: one line per event on stderr with a timestamp, pid and tid, so that a run can be split by process (parent, tab, extension, ...) after the fact. Logging is enabled at runtime with an environment variable, so one build serves both arms of a comparison.
Caveats to document with it:
- On Linux mozjemalloc uses
MADV_DONTNEED, so handing out a released page means a zero-fill fault on first touch. On Windows the pages are decommitted and recommitted. On macOSMADV_FREEpages do not necessarily fault when reused. So the refault counter is a page count, an upper bound on faults on Linux and Windows, not a fault count everywhere. - The counters come from allocator bookkeeping, so they should be cross-checked against kernel fault counts (e.g.
perf stat -e minor-faultson the content process) at least once per platform.
The profiler purge markers (MOZJEMALLOC_PROFILING_CALLBACKS) already show individual purges. They do not cover refaults or the low water state, and they need a profiled run, which changes allocation behaviour itself. Adding some of these fields to the markers could be a follow-up.
| Assignee | ||
Comment 1•21 days ago
|
||
Tuning when mozjemalloc purges needs to know what a purge released and
whether the arena needed those pages again soon after. Whole-process page
fault counts cannot attribute that to the allocator.
Add a log of every purge, compiled in only when MOZJEMALLOC_PURGE_LOG is
defined and written to stderr when the environment variable of the same
name is set. Besides the purge itself it counts the pages a purge released
that the arena allocates again, separately for target purges, and the
chunks the arena maps or reuses.
purge_log_stats.py summarizes a log per process and arena.
Updated•21 days ago
|
Description
•