From 382ddca7fc29a8e6ef748ed39b2414a1e8609bd9 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 28 Jan 2025 15:55:27 -0500 Subject: [PATCH] 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 --- src/system/kernel/vm/vm.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 78bf6776cd..6b52cf4182 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -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();