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.)
This commit is contained in:
Augustin Cavalier 2025-01-25 15:44:23 -05:00
parent ab25a42387
commit 2cee2502c5

View File

@ -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);