diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-18 22:43:32 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-18 22:43:32 +0100 |
commit | 1d4d6f16b23c464224497e1c7f08eb543f886f8e (patch) | |
tree | c759d5fb955394541c2a7a7bd7e1dc1395ab2e8e /Kernel/VM | |
parent | c0e81b26b6a86ce6e7c5e0402075b9ee4e7edc52 (diff) | |
download | serenity-1d4d6f16b23c464224497e1c7f08eb543f886f8e.zip |
Kernel: Add a specific-page variant of Region::commit()
Diffstat (limited to 'Kernel/VM')
-rw-r--r-- | Kernel/VM/Region.cpp | 36 | ||||
-rw-r--r-- | Kernel/VM/Region.h | 3 |
2 files changed, 26 insertions, 13 deletions
diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 3148be84b7..5e31c404d9 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -90,25 +90,37 @@ NonnullOwnPtr<Region> Region::clone() return clone_region; } -int Region::commit() +bool Region::commit() { InterruptDisabler disabler; #ifdef MM_DEBUG dbgprintf("MM: commit %u pages in Region %p (VMO=%p) at V%p\n", vmobject().page_count(), this, &vmobject(), vaddr().get()); #endif for (size_t i = 0; i < page_count(); ++i) { - auto& vmobject_physical_page_entry = vmobject().physical_pages()[first_page_index() + i]; - if (!vmobject_physical_page_entry.is_null()) - continue; - auto physical_page = MM.allocate_user_physical_page(MemoryManager::ShouldZeroFill::Yes); - if (!physical_page) { - kprintf("MM: commit was unable to allocate a physical page\n"); - return -ENOMEM; - } - vmobject_physical_page_entry = move(physical_page); - remap_page(i); + if (!commit(i)) + return false; } - return 0; + return true; +} + +bool Region::commit(size_t page_index) +{ + ASSERT(vmobject().is_anonymous() || vmobject().is_purgeable()); + InterruptDisabler disabler; +#ifdef MM_DEBUG + dbgprintf("MM: commit single page (%zu) in Region %p (VMO=%p) at V%p\n", page_index, vmobject().page_count(), this, &vmobject(), vaddr().get()); +#endif + auto& vmobject_physical_page_entry = vmobject().physical_pages()[first_page_index() + page_index]; + if (!vmobject_physical_page_entry.is_null()) + return true; + auto physical_page = MM.allocate_user_physical_page(MemoryManager::ShouldZeroFill::Yes); + if (!physical_page) { + kprintf("MM: commit was unable to allocate a physical page\n"); + return false; + } + vmobject_physical_page_entry = move(physical_page); + remap_page(page_index); + return true; } u32 Region::cow_pages() const diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index eb76b3accb..7ec0fb9737 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -98,7 +98,8 @@ public: return m_offset_in_vmo; } - int commit(); + bool commit(); + bool commit(size_t page_index); size_t amount_resident() const; size_t amount_shared() const; |