kernel/vm: Choose pre-map size based on cache fault count.

The GCC "cc1plus" binary is over 40MB, so pre-faulting at most 10MB
of it only helped so much. Now, we map 1 MB for every time the cache
has been faulted "in full". This should warm up quite rapidly during
compile jobs, and stabilize after that (with future faults mostly
being CoW.)

Only active (accessed+used) pages will get pre-mapped anyway, so if
on a long-running system the page daemon debuffs all the pages in a
cache, we would just iterate through all of them but not map any here.
If that overhead proves to be a problem in the future, we can optimize
for it then (probably by keeping track of how many pages are eligible
for pre-mapping in this way.)

This significantly reduces lock contention in compile jobs. Compiling
libroot with a generated directory on ramfs and -j4, best of 3 runs:

before:
real    0m43.017s
user    1m2.811s
sys     0m24.900s

after:
real    0m29.367s
user    1m0.321s
sys     0m13.373s
Change-Id: I441abf43803c8666cdc13c6d007bc04439698b0b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8874
Reviewed-by: Michael Lotz <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-01-28 21:23:38 +00:00
committed by waddlesplash
parent 17c3890ce1
commit 382ddca7fc
+4 -3
View File
@@ -2417,10 +2417,11 @@ _vm_map_file(team_id team, const char* name, void** _address,
cache->ReleaseRefLocked();
}
if (status == B_OK && (protection & B_READ_AREA) != 0) {
// Pre-map at most 10MB worth of pages.
if (status == B_OK && (protection & B_READ_AREA) != 0 && cache->page_count > 0) {
// Pre-map up to 1 MB for every time the cache has been faulted "in full".
pre_map_area_pages(area, cache, &reservation,
(10LL * 1024 * 1024) / B_PAGE_SIZE);
(cache->FaultCount() / cache->page_count)
* ((1 * 1024 * 1024) / B_PAGE_SIZE));
}
cache->Unlock();