git: c5b19cef3609 - main - vm_map: wrap map->system_map checks into wrapper
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 09 Dec 2024 03:28:34 UTC
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c5b19cef3609211e692d6b21abcddef877c94af7 commit c5b19cef3609211e692d6b21abcddef877c94af7 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-12-06 23:51:08 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-12-09 03:27:44 +0000 vm_map: wrap map->system_map checks into wrapper Reviewed by: alc Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D47934 --- sys/vm/vm_fault.c | 2 +- sys/vm/vm_map.c | 49 ++++++++++++++++++++++++------------------------- sys/vm/vm_map.h | 6 ++++++ sys/vm/vm_pageout.c | 2 +- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 6e0415b30600..8c7fe9e37af1 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -1355,7 +1355,7 @@ vm_fault_getpages(struct faultstate *fs, int *behindp, int *aheadp) MPASS(status == FAULT_CONTINUE || status == FAULT_RESTART); if (status == FAULT_RESTART) return (status); - KASSERT(fs->vp == NULL || !fs->map->system_map, + KASSERT(fs->vp == NULL || !vm_map_is_system(fs->map), ("vm_fault: vnode-backed object mapped by system map")); /* diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index c3aa499e0dc7..f7847a244586 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -523,7 +523,7 @@ void _vm_map_lock(vm_map_t map, const char *file, int line) { - if (map->system_map) + if (vm_map_is_system(map)) mtx_lock_flags_(&map->system_mtx, 0, file, line); else sx_xlock_(&map->lock, file, line); @@ -614,7 +614,7 @@ static void _vm_map_assert_locked(vm_map_t map, const char *file, int line) { - if (map->system_map) + if (vm_map_is_system(map)) mtx_assert_(&map->system_mtx, MA_OWNED, file, line); else sx_assert_(&map->lock, SA_XLOCKED, file, line); @@ -657,7 +657,7 @@ _vm_map_unlock(vm_map_t map, const char *file, int line) { VM_MAP_UNLOCK_CONSISTENT(map); - if (map->system_map) { + if (vm_map_is_system(map)) { #ifndef UMA_USE_DMAP if (map == kernel_map && (map->flags & MAP_REPLENISH) != 0) { uma_prealloc(kmapentzone, 1); @@ -675,7 +675,7 @@ void _vm_map_lock_read(vm_map_t map, const char *file, int line) { - if (map->system_map) + if (vm_map_is_system(map)) mtx_lock_flags_(&map->system_mtx, 0, file, line); else sx_slock_(&map->lock, file, line); @@ -685,7 +685,7 @@ void _vm_map_unlock_read(vm_map_t map, const char *file, int line) { - if (map->system_map) { + if (vm_map_is_system(map)) { KASSERT((map->flags & MAP_REPLENISH) == 0, ("%s: MAP_REPLENISH leaked", __func__)); mtx_unlock_flags_(&map->system_mtx, 0, file, line); @@ -700,7 +700,7 @@ _vm_map_trylock(vm_map_t map, const char *file, int line) { int error; - error = map->system_map ? + error = vm_map_is_system(map) ? !mtx_trylock_flags_(&map->system_mtx, 0, file, line) : !sx_try_xlock_(&map->lock, file, line); if (error == 0) @@ -713,7 +713,7 @@ _vm_map_trylock_read(vm_map_t map, const char *file, int line) { int error; - error = map->system_map ? + error = vm_map_is_system(map) ? !mtx_trylock_flags_(&map->system_mtx, 0, file, line) : !sx_try_slock_(&map->lock, file, line); return (error == 0); @@ -734,7 +734,7 @@ _vm_map_lock_upgrade(vm_map_t map, const char *file, int line) { unsigned int last_timestamp; - if (map->system_map) { + if (vm_map_is_system(map)) { mtx_assert_(&map->system_mtx, MA_OWNED, file, line); } else { if (!sx_try_upgrade_(&map->lock, file, line)) { @@ -760,7 +760,7 @@ void _vm_map_lock_downgrade(vm_map_t map, const char *file, int line) { - if (map->system_map) { + if (vm_map_is_system(map)) { KASSERT((map->flags & MAP_REPLENISH) == 0, ("%s: MAP_REPLENISH leaked", __func__)); mtx_assert_(&map->system_mtx, MA_OWNED, file, line); @@ -780,10 +780,9 @@ int vm_map_locked(vm_map_t map) { - if (map->system_map) + if (vm_map_is_system(map)) return (mtx_owned(&map->system_mtx)); - else - return (sx_xlocked(&map->lock)); + return (sx_xlocked(&map->lock)); } /* @@ -806,7 +805,7 @@ _vm_map_unlock_and_wait(vm_map_t map, int timo, const char *file, int line) VM_MAP_UNLOCK_CONSISTENT(map); mtx_lock(&map_sleep_mtx); - if (map->system_map) { + if (vm_map_is_system(map)) { KASSERT((map->flags & MAP_REPLENISH) == 0, ("%s: MAP_REPLENISH leaked", __func__)); mtx_unlock_flags_(&map->system_mtx, 0, file, line); @@ -864,7 +863,7 @@ vm_map_wait_busy(vm_map_t map) VM_MAP_ASSERT_LOCKED(map); while (map->busy) { vm_map_modflags(map, MAP_BUSY_WAKEUP, 0); - if (map->system_map) + if (vm_map_is_system(map)) msleep(&map->busy, &map->system_mtx, 0, "mbusy", 0); else sx_sleep(&map->busy, &map->lock, 0, "mbusy", 0); @@ -927,7 +926,7 @@ vm_map_init_system(vm_map_t map, pmap_t pmap, vm_offset_t min, vm_offset_t max) static void vm_map_entry_dispose(vm_map_t map, vm_map_entry_t entry) { - uma_zfree(map->system_map ? kmapentzone : mapentzone, entry); + uma_zfree(vm_map_is_system(map) ? kmapentzone : mapentzone, entry); } /* @@ -961,7 +960,7 @@ vm_map_entry_create(vm_map_t map) } } else #endif - if (map->system_map) { + if (vm_map_is_system(map)) { new_entry = uma_zalloc(kmapentzone, M_NOWAIT); } else { new_entry = uma_zalloc(mapentzone, M_WAITOK); @@ -2428,7 +2427,7 @@ vm_map_entry_charge_object(vm_map_t map, vm_map_entry_t entry) VM_MAP_ASSERT_LOCKED(map); KASSERT((entry->eflags & MAP_ENTRY_IS_SUB_MAP) == 0, ("map entry %p is a submap", entry)); - if (entry->object.vm_object == NULL && !map->system_map && + if (entry->object.vm_object == NULL && !vm_map_is_system(map) && (entry->eflags & MAP_ENTRY_GUARD) == 0) vm_map_entry_back(entry); else if (entry->object.vm_object != NULL && @@ -2493,7 +2492,7 @@ vm_map_clip_start(vm_map_t map, vm_map_entry_t entry, vm_offset_t startaddr) vm_map_entry_t new_entry; int bdry_idx; - if (!map->system_map) + if (!vm_map_is_system(map)) WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s: map %p entry %p start 0x%jx", __func__, map, entry, (uintmax_t)startaddr); @@ -2536,7 +2535,7 @@ vm_map_lookup_clip_start(vm_map_t map, vm_offset_t start, vm_map_entry_t entry; int rv; - if (!map->system_map) + if (!vm_map_is_system(map)) WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s: map %p start 0x%jx prev %p", __func__, map, (uintmax_t)start, prev_entry); @@ -2566,7 +2565,7 @@ vm_map_clip_end(vm_map_t map, vm_map_entry_t entry, vm_offset_t endaddr) vm_map_entry_t new_entry; int bdry_idx; - if (!map->system_map) + if (!vm_map_is_system(map)) WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s: map %p entry %p end 0x%jx", __func__, map, entry, (uintmax_t)endaddr); @@ -3936,7 +3935,7 @@ vm_map_entry_delete(vm_map_t map, vm_map_entry_t entry) MPASS(entry->cred == NULL); MPASS((entry->eflags & MAP_ENTRY_IS_SUB_MAP) == 0); MPASS(object == NULL); - vm_map_entry_deallocate(entry, map->system_map); + vm_map_entry_deallocate(entry, vm_map_is_system(map)); return; } @@ -3987,7 +3986,7 @@ vm_map_entry_delete(vm_map_t map, vm_map_entry_t entry) } VM_OBJECT_WUNLOCK(object); } - if (map->system_map) + if (vm_map_is_system(map)) vm_map_entry_deallocate(entry, TRUE); else { entry->defer_next = curthread->td_map_def_user; @@ -4710,7 +4709,7 @@ vm_map_growstack(vm_map_t map, vm_offset_t addr, vm_map_entry_t gap_entry) p->p_textvp == NULL)) return (KERN_FAILURE); - MPASS(!map->system_map); + MPASS(!vm_map_is_system(map)); lmemlim = lim_cur(curthread, RLIMIT_MEMLOCK); stacklim = lim_cur(curthread, RLIMIT_STACK); @@ -5118,7 +5117,7 @@ RetryLookupLocked: /* * Create an object if necessary. */ - if (entry->object.vm_object == NULL && !map->system_map) { + if (entry->object.vm_object == NULL && !vm_map_is_system(map)) { if (vm_map_lock_upgrade(map)) goto RetryLookup; entry->object.vm_object = vm_object_allocate_anon(atop(size), @@ -5206,7 +5205,7 @@ vm_map_lookup_locked(vm_map_t *var_map, /* IN/OUT */ /* * Fail if an object should be created. */ - if (entry->object.vm_object == NULL && !map->system_map) + if (entry->object.vm_object == NULL && !vm_map_is_system(map)) return (KERN_FAILURE); /* diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 5ecec0531e1c..ed1106734951 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -278,6 +278,12 @@ vm_map_range_valid(vm_map_t map, vm_offset_t start, vm_offset_t end) return (true); } +static inline bool +vm_map_is_system(vm_map_t map) +{ + return ((map->system_map)); +} + #endif /* KLD_MODULE */ #endif /* _KERNEL */ diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index f6c5e6291692..28a54a83fd49 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -1844,7 +1844,7 @@ vm_pageout_oom_pagecount(struct vmspace *vmspace) long res; map = &vmspace->vm_map; - KASSERT(!map->system_map, ("system map")); + KASSERT(!vm_map_is_system(map), ("system map")); sx_assert(&map->lock, SA_LOCKED); res = 0; VM_MAP_ENTRY_FOREACH(entry, map) {