diff --git a/headers/private/kernel/vm_page.h b/headers/private/kernel/vm_page.h index 7b4a16019b..707b439fd9 100644 --- a/headers/private/kernel/vm_page.h +++ b/headers/private/kernel/vm_page.h @@ -46,6 +46,7 @@ void vm_page_schedule_write_page_range(struct VMCache *cache, void vm_page_unreserve_pages(uint32 count); void vm_page_reserve_pages(uint32 count); +bool vm_page_try_reserve_pages(uint32 count); struct vm_page *vm_page_allocate_page(int pageState, bool reserved); status_t vm_page_allocate_pages(int pageState, struct vm_page **pages, diff --git a/src/system/kernel/vm/vm_page.cpp b/src/system/kernel/vm/vm_page.cpp index 2042410a77..2e774aae2f 100644 --- a/src/system/kernel/vm/vm_page.cpp +++ b/src/system/kernel/vm/vm_page.cpp @@ -1756,6 +1756,25 @@ vm_page_reserve_pages(uint32 count) } +bool +vm_page_try_reserve_pages(uint32 count) +{ + if (count == 0) + return true; + + InterruptsSpinLocker locker(sPageLock); + + T(ReservePages(count)); + + size_t freePages = free_page_queue_count(); + if (sReservedPages + count > freePages) + return false; + + sReservedPages += count; + return true; +} + + vm_page * vm_page_allocate_page(int pageState, bool reserved) {