Open Bug 1406304 Opened 9 years ago Updated 15 days ago

Properly support madvise(MADV_FREE) on linux

Categories

(Core :: Memory Allocator, enhancement, P3)

enhancement

Tracking

()

ASSIGNED

People

(Reporter: glandium, Assigned: Benjamin)

Details

Attachments

(1 external file)

When building against a recent enough glibc, MADV_FREE is defined, and we don't end up having the define setting it to MADV_DONTNEED. Which means something built with a new glibc won't run properly on an old kernel because madvise(MADV_FREE) will return EINVAL. Also, it could be desirable to use madvise(MADV_FREE) instead of madvise(MADV_DONTNEED) on newer kernels, even when building against an older glibc like we do.
Priority: -- → P3

Hi Glandium.

What's the difference between MADV_FREE and MADV_DONTNEED. The descriptions are so similar.

Flags: needinfo?(mh+mozilla)

I'm not glandium, but my understanding is that MADV_DONTNEED will free the pages immediately and synchronously; in contrast, MADV_FREE permits the kernel to free them at a later point, meaning that if there isn't memory pressure before we use the pages again then we don't have the overhead of removing and reestablishing the page table entries.

Severity: normal → S3

Note that MADV_FREE may make Firefox much more attractive to the OOM-killer on linux (though it's likely fairly attractive already): https://stackoverflow.com/questions/74358183/why-golang-madv-free-leads-to-oom-sometimes

MADV_FREE will make us appear to use more RSS; jlebar landed code a Long Time Ago to purge MADV_FREE pages on Mac before we measure RSS: bug 693404. This helps us in our internal RSS measurements (for about:memory), but not for any external measurements

Note that MADV_FREE until kernel 4.12 on an swapless, system will immediately free memory on MADV_FREE, and other issues make MADV_FREE on linux <4.12 problematic:
https://kernelnewbies.org/Linux_4.12#Memory_management

MADV_FREE has several issues that make it unusable in software like jemalloc: doesn't support system without swap enabled, increases memory pressure, and accounting problems. This release puts MADV_FREE pages into the LRU_INACTIVE_FILE list, enables MADV_FREE for swapless systems and improves statistic accounting

4.12 looks like it was released in 2017

Flags: needinfo?(mh+mozilla)

memory/build/Constants.h had this block that would appear to force Linux to always use MADV_DONTNEED:

// Newer Linux systems support MADV_FREE, but we're not supporting
// that properly. bug #1406304.

Unfortunately, Constants.h doesn't include <sys/mman.h>. A later inclusion of <sys/mman.h> will silently override MADV_FREE back to MADV_FREE. That appears to be happening with the current unified build, resulting in PurgeDirtyPages using "real" MADV_FREE despite this Constants.h block.

Assignee: nobody → benjamin
Status: NEW → ASSIGNED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: