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 4ddde212..7e3e5686 100644 --- a/vm/vm_map.c +++ b/vm/vm_map.c @@ -1100,6 +1100,12 @@ kern_return_t vm_map_enter( map->size += size; entry->vme_end = end; vm_map_gap_update(&map->hdr, entry); + /* + * 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); } } @@ -1129,6 +1135,12 @@ kern_return_t vm_map_enter( map->size += size; next_entry->vme_start = start; vm_map_gap_update(&map->hdr, entry); + /* + * 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); } } @@ -1607,6 +1619,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); @@ -1682,9 +1695,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); @@ -1708,6 +1728,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); @@ -1725,9 +1746,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