From 09d0fae2c6d267cce4d4a757988f5c889aa70531 Mon Sep 17 00:00:00 2001 From: dylanbobb Date: Sun, 14 Aug 2022 23:05:42 -0400 Subject: [PATCH] Kernel: Allow release of a specific amount of of clean pages Previously, we could only release *all* clean pages. This patch makes it possible to release a specific amount of clean pages. If the attempted number of pages to release is more than the amount of clean pages, all clean pages will be released. --- Kernel/Memory/InodeVMObject.cpp | 19 +++++++++++++++++++ Kernel/Memory/InodeVMObject.h | 1 + 2 files changed, 20 insertions(+) diff --git a/Kernel/Memory/InodeVMObject.cpp b/Kernel/Memory/InodeVMObject.cpp index 77cacf7e533..3ef50758660 100644 --- a/Kernel/Memory/InodeVMObject.cpp +++ b/Kernel/Memory/InodeVMObject.cpp @@ -67,6 +67,25 @@ int InodeVMObject::release_all_clean_pages() return count; } +int InodeVMObject::try_release_clean_pages(int page_amount) +{ + SpinlockLocker locker(m_lock); + + int count = 0; + for (size_t i = 0; i < page_count() && count < page_amount; ++i) { + if (!m_dirty_pages.get(i) && m_physical_pages[i]) { + m_physical_pages[i] = nullptr; + ++count; + } + } + if (count) { + for_each_region([](auto& region) { + region.remap(); + }); + } + return count; +} + u32 InodeVMObject::writable_mappings() const { u32 count = 0; diff --git a/Kernel/Memory/InodeVMObject.h b/Kernel/Memory/InodeVMObject.h index 6f9500c9336..1f09c5b2636 100644 --- a/Kernel/Memory/InodeVMObject.h +++ b/Kernel/Memory/InodeVMObject.h @@ -23,6 +23,7 @@ public: size_t amount_clean() const; int release_all_clean_pages(); + int try_release_clean_pages(int page_amount); u32 writable_mappings() const; u32 executable_mappings() const;