From 2cee2502c5d07735c6353bc255dbfabbbca4a161 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 25 Jan 2025 15:44:23 -0500 Subject: [PATCH] kernel/vm: Unlock lower caches before allocating clean pages on page fault. The documentation comment says that only "caches starting from the top cache to at least the cache the page lives in" are guaranteed to be locked. So it should be safe to unlock all the lower caches that we didn't find the page in here, and leave only the topmost cache locked, to reduce contention. (We can't do this in the CoW case, since there we may have to unmap the read-only page when mapping in the new read-write page. But for clean pages, since no lower cache had the page in question, we shouldn't have anything mapped at all, and thus unlocking the lower caches ought to be safe.) --- src/system/kernel/vm/vm.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 396ea5c62a..a78d029e40 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -4370,6 +4370,10 @@ fault_get_page(PageFaultContext& context) // There was no adequate page. Insert a clean one into the topmost cache. cache = context.topCache; + // We don't need the other caches anymore. + context.cacheChainLocker.Unlock(context.topCache); + context.cacheChainLocker.SetTo(context.topCache); + // allocate a clean page page = vm_page_allocate_page(&context.reservation, PAGE_STATE_ACTIVE | VM_PAGE_ALLOC_CLEAR);