git: d529f396b7e8 - stable/13 - vm_fault: Fix some nits in vm_fault_copy_entry()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 25 Jul 2022 13:54:54 UTC
The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d529f396b7e876cf5bc10bc373376a2b37869d0c commit d529f396b7e876cf5bc10bc373376a2b37869d0c Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2022-07-11 19:27:54 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-07-25 13:44:45 +0000 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 Sponsored by: The FreeBSD Foundation (cherry picked from commit b57be759d079d40aa6ec75207faadce5ae1484a2) --- sys/vm/vm_fault.c | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 8981be84b5d2..a6c7a6092f40 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -1952,10 +1952,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. @@ -1963,7 +1963,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) { @@ -1973,14 +1973,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); @@ -2002,16 +2013,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")); @@ -2027,19 +2035,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