kernel/vm: Let _user_set_memory_protection change area->protection if possible.

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 <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
Augustin Cavalier 2022-03-11 14:24:28 -05:00 committed by waddlesplash
parent a09dd6bb6c
commit 77034a15f8

View File

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