From 97df206a85f64774e3ec195293def30107444d51 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 13 Dec 2024 16:36:56 -0500 Subject: [PATCH] kernel/vm: Accept negative (no) priority in VMCache's Resize and Rebase. This means that we won't try and change the commitment at all, and it will be up to the caller to do that instead. Also move the commitment change from the beginning to the end of Rebase, matching Resize. This way, we won't trip the new asserts added to Commit() in the previous commits. Add a relevant assert to vm_try_reserve_memory to make sure the negative priority doesn't end up down that far. --- src/system/kernel/vm/VMCache.cpp | 26 ++++++++++++++------------ src/system/kernel/vm/vm.cpp | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/system/kernel/vm/VMCache.cpp b/src/system/kernel/vm/VMCache.cpp index 49c586e5c7..da02f6f080 100644 --- a/src/system/kernel/vm/VMCache.cpp +++ b/src/system/kernel/vm/VMCache.cpp @@ -1172,15 +1172,16 @@ VMCache::Resize(off_t newSize, int priority) >> PAGE_SHIFT); if (newPageCount < oldPageCount) { - // we need to remove all pages in the cache outside of the new virtual - // size + // Remove all pages in the cache outside of the new virtual size. while (_FreePageRange(pages.GetIterator(newPageCount, true, true))) ; } - status_t status = Commit(newSize - virtual_base, priority); - if (status != B_OK) - return status; + if (priority >= 0) { + status_t status = Commit(newSize - virtual_base, priority); + if (status != B_OK) + return status; + } virtual_end = newSize; return B_OK; @@ -1200,23 +1201,24 @@ VMCache::Rebase(off_t newBase, int priority) { TRACE(("VMCache::Rebase(cache %p, newBase %lld) old base %lld\n", this, newBase, this->virtual_base)); - this->AssertLocked(); - T(Rebase(this, newBase)); - status_t status = Commit(virtual_end - newBase, priority); - if (status != B_OK) - return status; + AssertLocked(); page_num_t basePage = (page_num_t)(newBase >> PAGE_SHIFT); if (newBase > virtual_base) { - // we need to remove all pages in the cache outside of the new virtual - // base + // Remove all pages in the cache outside of the new virtual base. while (_FreePageRange(pages.GetIterator(), &basePage)) ; } + if (priority >= 0) { + status_t status = Commit(virtual_end - newBase, priority); + if (status != B_OK) + return status; + } + virtual_base = newBase; return B_OK; } diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 5b59a2d5d9..516f2fd141 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -4710,6 +4710,7 @@ vm_unreserve_memory(size_t amount) status_t vm_try_reserve_memory(size_t amount, int priority, bigtime_t timeout) { + ASSERT(priority >= 0 && priority < (int)B_COUNT_OF(kMemoryReserveForPriority)); size_t reserve = kMemoryReserveForPriority[priority]; MutexLocker locker(sAvailableMemoryLock);