From dc0c9160173d2a5b40e9d6e29c1800102b17b1ec Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Mon, 26 Jun 2023 14:26:51 +0300 Subject: vm: Allow coalescing a VM object with itself If a mapping of an object is made right next to another mapping of the same object have the same properties (protection, inheritance, etc.), Mach will now expand the previous VM map entry to cover the new address range instead of creating a new entry. Message-Id: <20230626112656.435622-3-bugaevc@gmail.com> --- vm/vm_object.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'vm/vm_object.c') diff --git a/vm/vm_object.c b/vm/vm_object.c index b5be3f81..b00e90d2 100644 --- a/vm/vm_object.c +++ b/vm/vm_object.c @@ -2693,7 +2693,8 @@ void vm_object_page_remove( * returns TRUE if objects were combined. * * NOTE: Only works at the moment if the second object is NULL - - * if it's not, which object do we lock first? + * or if the objects are the same - otherwise, which + * object do we lock first? * * Parameters: * prev_object First object to coalesce @@ -2718,12 +2719,23 @@ boolean_t vm_object_coalesce( { vm_size_t newsize; - if (next_object != VM_OBJECT_NULL) { - return FALSE; + if (prev_object == next_object) { + /* + * If neither object actually exists, + * the offsets don't matter. + */ + if (prev_object == VM_OBJECT_NULL) + return TRUE; + + return prev_offset + prev_size == next_offset; } - if (prev_object == VM_OBJECT_NULL) { - return TRUE; + if (next_object != VM_OBJECT_NULL) { + /* + * Don't know how to merge two different + * objects yet. + */ + return FALSE; } vm_object_lock(prev_object); -- cgit v1.2.3