From 77034a15f87fd3bd2d7de2e458c26c48f53afce3 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 11 Mar 2022 14:24:28 -0500 Subject: [PATCH] kernel/vm: Let _user_set_memory_protection change area->protection if possible. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If mprotect() is being run over an entire area, and the area does not have per-page protections, then we can just invoke set_area_protection instead of allocating a protections array. This is a major efficiency increase, as every page fault would otherwise have to use the protections array if it was allocated. Testing with QtWebEngine shows this new path being hit relatively often (multiple hundred times in loading a single webpage). Change-Id: I60258d56f681060861602922f3fbdbce2fd380d6 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5097 Tested-by: Commit checker robot Reviewed-by: Jérôme Duval --- src/system/kernel/vm/vm.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 367f43030d..492668b142 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -6706,6 +6706,13 @@ _user_set_memory_protection(void* _address, size_t size, uint32 protection) if (area->page_protections == NULL) { if (area->protection == protection) continue; + if (offset == 0 && rangeSize == area->Size()) { + status_t status = vm_set_area_protection(area->address_space->ID(), + area->id, protection, false); + if (status != B_OK) + return status; + continue; + } status_t status = allocate_area_page_protections(area); if (status != B_OK)