When - extending an existing entry, - changing protection or inheritance of a range of entries, we can get several entries that could be coalesced. Attempt to do that. --- vm/vm_map.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/vm/vm_map.c b/vm/vm_map.c index fc7c4381..e31ad3aa 100644 --- a/vm/vm_map.c +++ b/vm/vm_map.c @@ -1099,6 +1099,12 @@ kern_return_t vm_map_enter( entry->vme_end = end; vm_map_gap_update(&map->hdr, entry); vm_object_deallocate(object); + /* + * Now that we did, perhaps we could simplify + * things even further by coalescing the next + * entry into the one we just extended. + */ + vm_map_coalesce_entry(map, next_entry); RETURN(KERN_SUCCESS); } } @@ -1128,6 +1134,12 @@ kern_return_t vm_map_enter( next_entry->offset -= size; vm_map_gap_update(&map->hdr, entry); vm_object_deallocate(object); + /* + * Now that we did, perhaps we could simplify + * things even further by coalescing the + * entry into the previous one. + */ + vm_map_coalesce_entry(map, next_entry); RETURN(KERN_SUCCESS); } } @@ -1606,6 +1618,7 @@ kern_return_t vm_map_protect( { vm_map_entry_t current; vm_map_entry_t entry; + vm_map_entry_t next; vm_map_lock(map); @@ -1681,9 +1694,16 @@ kern_return_t vm_map_protect( current->vme_end, current->protection); } - current = current->vme_next; + + next = current->vme_next; + vm_map_coalesce_entry(map, current); + current = next; } + next = current->vme_next; + if (vm_map_coalesce_entry(map, current)) + current = next; + /* Returns with the map read-locked if successful */ vm_map_pageable_scan(map, entry, current); @@ -1707,6 +1727,7 @@ kern_return_t vm_map_inherit( { vm_map_entry_t entry; vm_map_entry_t temp_entry; + vm_map_entry_t next; vm_map_lock(map); @@ -1724,9 +1745,13 @@ kern_return_t vm_map_inherit( entry->inheritance = new_inheritance; - entry = entry->vme_next; + next = entry->vme_next; + vm_map_coalesce_entry(map, entry); + entry = next; } + vm_map_coalesce_entry(map, entry); + vm_map_unlock(map); return(KERN_SUCCESS); } -- 2.41.0