vm_fault: Fix some nits in vm_fault_copy_entry()

- Correct the description (vm_fault_copy_entry() does not create a
  shadow object).
- Move some initialization and assertions out of the scope of the object
  locks, when doing so makes sense.
- Merge a pair of conditional blocks.
- Use __unused when appropriate.

No functional change intended.

Reviewed by:	alc
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mark Johnston 2022-07-11 15:27:54 -04:00
parent 1228a047aa
commit b57be759d0

View file

@ -1951,10 +1951,10 @@ error:
* Routine:
* vm_fault_copy_entry
* Function:
* Create new shadow object backing dst_entry with private copy of
* all underlying pages. When src_entry is equal to dst_entry,
* function implements COW for wired-down map entry. Otherwise,
* it forks wired entry into dst_map.
* Create new object backing dst_entry with private copy of all
* underlying pages. When src_entry is equal to dst_entry, function
* implements COW for wired-down map entry. Otherwise, it forks
* wired entry into dst_map.
*
* In/out conditions:
* The source and destination maps must be locked for write.
@ -1962,7 +1962,7 @@ error:
* entry corresponding to a main map entry that is wired down).
*/
void
vm_fault_copy_entry(vm_map_t dst_map, vm_map_t src_map,
vm_fault_copy_entry(vm_map_t dst_map, vm_map_t src_map __unused,
vm_map_entry_t dst_entry, vm_map_entry_t src_entry,
vm_ooffset_t *fork_charge)
{
@ -1972,14 +1972,25 @@ vm_fault_copy_entry(vm_map_t dst_map, vm_map_t src_map,
vm_offset_t vaddr;
vm_page_t dst_m;
vm_page_t src_m;
boolean_t upgrade;
#ifdef lint
src_map++;
#endif /* lint */
bool upgrade;
upgrade = src_entry == dst_entry;
KASSERT(upgrade || dst_entry->object.vm_object == NULL,
("vm_fault_copy_entry: vm_object not NULL"));
/*
* If not an upgrade, then enter the mappings in the pmap as
* read and/or execute accesses. Otherwise, enter them as
* write accesses.
*
* A writeable large page mapping is only created if all of
* the constituent small page mappings are modified. Marking
* PTEs as modified on inception allows promotion to happen
* without taking potentially large number of soft faults.
*/
access = prot = dst_entry->protection;
if (!upgrade)
access &= ~VM_PROT_WRITE;
src_object = src_entry->object.vm_object;
src_pindex = OFF_TO_IDX(src_entry->offset);
@ -2001,16 +2012,13 @@ vm_fault_copy_entry(vm_map_t dst_map, vm_map_t src_map,
#endif
dst_object->domain = src_object->domain;
dst_object->charge = dst_entry->end - dst_entry->start;
}
VM_OBJECT_WLOCK(dst_object);
KASSERT(upgrade || dst_entry->object.vm_object == NULL,
("vm_fault_copy_entry: vm_object not NULL"));
if (src_object != dst_object) {
dst_entry->object.vm_object = dst_object;
dst_entry->offset = 0;
dst_entry->eflags &= ~MAP_ENTRY_VN_EXEC;
}
VM_OBJECT_WLOCK(dst_object);
if (fork_charge != NULL) {
KASSERT(dst_entry->cred == NULL,
("vm_fault_copy_entry: leaked swp charge"));
@ -2026,19 +2034,6 @@ vm_fault_copy_entry(vm_map_t dst_map, vm_map_t src_map,
dst_entry->cred = NULL;
}
/*
* If not an upgrade, then enter the mappings in the pmap as
* read and/or execute accesses. Otherwise, enter them as
* write accesses.
*
* A writeable large page mapping is only created if all of
* the constituent small page mappings are modified. Marking
* PTEs as modified on inception allows promotion to happen
* without taking potentially large number of soft faults.
*/
if (!upgrade)
access &= ~VM_PROT_WRITE;
/*
* Loop through all of the virtual pages within the entry's
* range, copying each page from the source object to the