From 4e993df9e9569dfc13c407baa75ff78910ee3dc5 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 13 Dec 2024 14:27:25 -0500 Subject: [PATCH] kernel/vm: Consider cache overcommit status in copy_area and mprotect. In copy_on_write_area, the copied cache should have the same overcommit status as the original area, and in set_memory_protection, we shouldn't change the committed size at all if the cache is overcommitting (otherwise, we'd wind up shrinking cache's commit sizes below the actual number of pages they contained in some cases.) --- src/system/kernel/vm/vm.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 98deb5750a..5b59a2d5d9 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -2733,7 +2733,8 @@ vm_copy_on_write_area(VMCache* lowerCache, // deeper and we create a new cache inbetween. // create an anonymous cache - status_t status = VMCacheFactory::CreateAnonymousCache(upperCache, false, 0, + status_t status = VMCacheFactory::CreateAnonymousCache(upperCache, + lowerCache->CanOvercommit(), 0, lowerCache->GuardSize() / B_PAGE_SIZE, dynamic_cast(lowerCache) == NULL, VM_PRIORITY_USER); @@ -6317,7 +6318,7 @@ _user_set_memory_protection(void* _address, size_t size, uint32 protection) cacheChainLocker.LockAllSourceCaches(); // Adjust the committed size, if necessary. - if (topCache->temporary) { + if (topCache->temporary && !topCache->CanOvercommit()) { const bool becomesWritable = (protection & B_WRITE_AREA) != 0; ssize_t commitmentChange = 0; const off_t areaCacheBase = area->Base() - area->cache_offset;