Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 728128cdbd4f5af9f66d7b353bbec180745c706c
https://github.com/WebKit/WebKit/commit/728128cdbd4f5af9f66d7b353bbec180745c706c
Author: Marcus Plutowski <[email protected]>
Date: 2025-06-17 (Tue, 17 Jun 2025)
Changed paths:
M Source/bmalloc/libpas/src/libpas/pas_page_malloc.c
Log Message:
-----------
[libpas] Use madvise(MADV_ZERO) instead of mmap to zero memory
https://bugs.webkit.org/show_bug.cgi?id=294583
rdar://153560968
Reviewed by Yusuke Suzuki.
When zeroing sufficiently large regions in libpas, we currently use mmap
to make the OS give us new pages (instead of having to memset them
ourselves). On Darwin, however, this approach is pessimizing in many
cases (e.g. the page is still in lazy-zero-fill state, and so notionally
could just be left in-place), and moreover causes issues with
fragmentation inside the kernel that we want to avoid.
The better alternative is to use madvise(p, sz, MADV_ZERO) whenever
possible.
This is not supported on Linux or older Darwin versions, so we will need
to check for the presence of MADV_ZERO. Moreover, madvise can sometimes
fail (e.g. for CoW pages -- though that in particular should not
happen for us), so we need to still support mmap as a fallback.
So in total, there are three places where we may fall back onto mmap:
1. At compile time, if MADV_ZERO is not defined;
2. At runtime, if on the first time madvise(MADV_ZERO) was called
it returned ENOTSUP and thus the latch is set to skip madvise
thereafter;
3. At runtime, if for any particular call to madvise(MADV_ZERO) it
returns an error (e.g. if we use it on a CoW-page).
* Source/bmalloc/libpas/src/libpas/pas_page_malloc.c:
(pas_page_malloc_zero_fill_latch_if_madv_zero_is_supported):
(pas_page_malloc_zero_fill):
Canonical link: https://commits.webkit.org/296321@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes