diff --git a/sys/vm/vm_meter.c b/sys/vm/vm_meter.c index fde1f4983347..935979ae017d 100644 --- a/sys/vm/vm_meter.c +++ b/sys/vm/vm_meter.c @@ -95,8 +95,10 @@ vmtotal(SYSCTL_HANDLER_ARGS) * Mark all objects as inactive. */ GIANT_REQUIRED; + mtx_lock(&vm_object_list_mtx); TAILQ_FOREACH(object, &vm_object_list, object_list) vm_object_clear_flag(object, OBJ_ACTIVE); + mtx_unlock(&vm_object_list_mtx); /* * Calculate process statistics. */ @@ -164,6 +166,7 @@ vmtotal(SYSCTL_HANDLER_ARGS) /* * Calculate object memory usage statistics. */ + mtx_lock(&vm_object_list_mtx); TAILQ_FOREACH(object, &vm_object_list, object_list) { /* * devices, like /dev/mem, will badly skew our totals @@ -186,6 +189,7 @@ vmtotal(SYSCTL_HANDLER_ARGS) } } } + mtx_unlock(&vm_object_list_mtx); totalp->t_free = cnt.v_free_count + cnt.v_cache_count; return (sysctl_handle_opaque(oidp, totalp, sizeof total, req)); } diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c index 37c329d85fca..5d13cac63575 100644 --- a/sys/vm/vm_object.c +++ b/sys/vm/vm_object.c @@ -137,7 +137,7 @@ static int vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int cur */ struct object_q vm_object_list; -static struct mtx vm_object_list_mtx; /* lock for object list and count */ +struct mtx vm_object_list_mtx; /* lock for object list and count */ vm_object_t kernel_object; vm_object_t kmem_object; static struct vm_object kernel_object_store; @@ -222,7 +222,9 @@ _vm_object_allocate(objtype_t type, vm_size_t size, vm_object_t object) object->generation++; + mtx_lock(&vm_object_list_mtx); TAILQ_INSERT_TAIL(&vm_object_list, object, object_list); + mtx_unlock(&vm_object_list_mtx); object_hash_rand = object->hash_rand; } @@ -1511,11 +1513,13 @@ vm_object_collapse(vm_object_t object) KASSERT(backing_object->ref_count == 1, ("backing_object %p was somehow re-referenced during collapse!", backing_object)); KASSERT(TAILQ_FIRST(&backing_object->memq) == NULL, ("backing_object %p somehow has left over pages during collapse!", backing_object)); + mtx_lock(&vm_object_list_mtx); TAILQ_REMOVE( &vm_object_list, backing_object, object_list ); + mtx_unlock(&vm_object_list_mtx); uma_zfree(obj_zone, backing_object); diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h index 1256e850c063..62244a91a8f0 100644 --- a/sys/vm/vm_object.h +++ b/sys/vm/vm_object.h @@ -160,6 +160,7 @@ struct vm_object { TAILQ_HEAD(object_q, vm_object); extern struct object_q vm_object_list; /* list of allocated objects */ +extern struct mtx vm_object_list_mtx; /* lock for object list and count */ extern vm_object_t kernel_object; /* the single kernel object */ extern vm_object_t kmem_object;