summaryrefslogtreecommitdiff
path: root/vm
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-07-05 17:16:39 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-11-27 17:12:30 +0100
commit1ca3a6d9aa0d287df4e375f8798536901474dabd (patch)
tree514b3e78f73a427d11b27ec2a417d4ebd27feaf2 /vm
parent87e8ddc7adac201aebe932b2d6f45b36c79849dd (diff)
vm: Coalesce map entries
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. Message-ID: <20230705141639.85792-4-bugaevc@gmail.com>
Diffstat (limited to 'vm')
-rw-r--r--vm/vm_map.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/vm/vm_map.c b/vm/vm_map.c
index d4280de3..26e18676 100644
--- a/vm/vm_map.c
+++ b/vm/vm_map.c
@@ -1075,6 +1075,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);
}
}
@@ -1104,6 +1110,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);
}
}
@@ -1582,6 +1594,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);
@@ -1657,9 +1670,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);
@@ -1683,6 +1703,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);
@@ -1700,9 +1721,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);
}