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.
This commit is contained in:
dylanbobb 2022-08-14 23:05:42 -04:00 committed by Andreas Kling
parent 072dde9387
commit 09d0fae2c6
Notes: sideshowbarker 2024-07-17 08:13:21 +09:00
2 changed files with 20 additions and 0 deletions

View file

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

View file

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