Tidy up vm_map_simplify_entry() and its recently introduced helper

functions.  Notably, reflow the text of some comments so that they
occupy fewer lines, and introduce an assertion in one of the new
helper functions so that it is not misused by a future caller.

In collaboration with:	Doug Moore <dougm@rice.edu>
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D17635
This commit is contained in:
Alan Cox 2018-11-18 01:27:17 +00:00
parent 835998c210
commit 92e78c1012

View File

@ -1644,16 +1644,25 @@ vm_map_find_min(vm_map_t map, vm_object_t object, vm_ooffset_t offset,
}
}
/*
* A map entry with any of the following flags set must not be merged with
* another entry.
*/
#define MAP_ENTRY_NOMERGE_MASK (MAP_ENTRY_GROWS_DOWN | MAP_ENTRY_GROWS_UP | \
MAP_ENTRY_IN_TRANSITION | MAP_ENTRY_IS_SUB_MAP)
static bool
vm_map_mergeable_neighbors(vm_map_entry_t prev, vm_map_entry_t entry)
{
vm_size_t prevsize;
prevsize = prev->end - prev->start;
KASSERT((prev->eflags & MAP_ENTRY_NOMERGE_MASK) == 0 ||
(entry->eflags & MAP_ENTRY_NOMERGE_MASK) == 0,
("vm_map_mergeable_neighbors: neither %p nor %p are mergeable",
prev, entry));
return (prev->end == entry->start &&
prev->object.vm_object == entry->object.vm_object &&
(prev->object.vm_object == NULL ||
prev->offset + prevsize == entry->offset) &&
prev->offset + (prev->end - prev->start) == entry->offset) &&
prev->eflags == entry->eflags &&
prev->protection == entry->protection &&
prev->max_protection == entry->max_protection &&
@ -1667,18 +1676,14 @@ vm_map_merged_neighbor_dispose(vm_map_t map, vm_map_entry_t entry)
{
/*
* If the backing object is a vnode object,
* vm_object_deallocate() calls vrele().
* However, vrele() does not lock the vnode
* because the vnode has additional
* references. Thus, the map lock can be kept
* without causing a lock-order reversal with
* the vnode lock.
* If the backing object is a vnode object, vm_object_deallocate()
* calls vrele(). However, vrele() does not lock the vnode because
* the vnode has additional references. Thus, the map lock can be
* kept without causing a lock-order reversal with the vnode lock.
*
* Since we count the number of virtual page
* mappings in object->un_pager.vnp.writemappings,
* the writemappings value should not be adjusted
* when the entry is disposed of.
* Since we count the number of virtual page mappings in
* object->un_pager.vnp.writemappings, the writemappings value
* should not be adjusted when the entry is disposed of.
*/
if (entry->object.vm_object != NULL)
vm_object_deallocate(entry->object.vm_object);
@ -1704,10 +1709,8 @@ vm_map_simplify_entry(vm_map_t map, vm_map_entry_t entry)
{
vm_map_entry_t next, prev;
if ((entry->eflags & (MAP_ENTRY_GROWS_DOWN | MAP_ENTRY_GROWS_UP |
MAP_ENTRY_IN_TRANSITION | MAP_ENTRY_IS_SUB_MAP)) != 0)
if ((entry->eflags & MAP_ENTRY_NOMERGE_MASK) != 0)
return;
prev = entry->prev;
if (vm_map_mergeable_neighbors(prev, entry)) {
vm_map_entry_unlink(map, prev);
@ -1717,7 +1720,6 @@ vm_map_simplify_entry(vm_map_t map, vm_map_entry_t entry)
vm_map_entry_resize_free(map, entry->prev);
vm_map_merged_neighbor_dispose(map, prev);
}
next = entry->next;
if (vm_map_mergeable_neighbors(entry, next)) {
vm_map_entry_unlink(map, next);
@ -1726,6 +1728,7 @@ vm_map_simplify_entry(vm_map_t map, vm_map_entry_t entry)
vm_map_merged_neighbor_dispose(map, next);
}
}
/*
* vm_map_clip_start: [ internal use only ]
*