From 5944426158880baf8b40d31b26fd23add753dd93 Mon Sep 17 00:00:00 2001 From: mpi Date: Sat, 22 May 2021 08:38:29 +0000 Subject: [PATCH] Use atomic operations for reference counting VM maps. This is necessary to do this accounting without the KERNEL_LOCK(). ok mvs@, kettenis@ --- sys/uvm/uvm_map.c | 15 ++++++++------- sys/uvm/uvm_map.h | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sys/uvm/uvm_map.c b/sys/uvm/uvm_map.c index c3d9190ca78..459045b01f1 100644 --- a/sys/uvm/uvm_map.c +++ b/sys/uvm/uvm_map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_map.c,v 1.274 2021/03/26 13:40:05 mpi Exp $ */ +/* $OpenBSD: uvm_map.c,v 1.275 2021/05/22 08:38:29 mpi Exp $ */ /* $NetBSD: uvm_map.c,v 1.86 2000/11/27 08:40:03 chs Exp $ */ /* @@ -491,12 +491,13 @@ uvm_mapent_addr_remove(struct vm_map *map, struct vm_map_entry *entry) /* * uvm_map_reference: add reference to a map * - * XXX check map reference counter lock + * => map need not be locked */ -#define uvm_map_reference(_map) \ - do { \ - map->ref_count++; \ - } while (0) +void +uvm_map_reference(struct vm_map *map) +{ + atomic_inc_int(&map->ref_count); +} /* * Calculate the dused delta. @@ -4292,7 +4293,7 @@ uvm_map_deallocate(vm_map_t map) int c; struct uvm_map_deadq dead; - c = --map->ref_count; + c = atomic_dec_int_nv(&map->ref_count); if (c > 0) { return; } diff --git a/sys/uvm/uvm_map.h b/sys/uvm/uvm_map.h index 531d6f2ef06..12092ebfcd2 100644 --- a/sys/uvm/uvm_map.h +++ b/sys/uvm/uvm_map.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_map.h,v 1.69 2021/03/12 14:15:49 jsg Exp $ */ +/* $OpenBSD: uvm_map.h,v 1.70 2021/05/22 08:38:29 mpi Exp $ */ /* $NetBSD: uvm_map.h,v 1.24 2001/02/18 21:19:08 chs Exp $ */ /* @@ -259,6 +259,7 @@ RBT_PROTOTYPE(uvm_map_addr, vm_map_entry, daddrs.addr_entry, * read_locks and write_locks are used in lock debugging code. * * Locks used to protect struct members in this file: + * a atomic operations * I immutable after creation or exec(2) * v `vm_map_lock' (this map `lock' or `mtx') */ @@ -272,7 +273,7 @@ struct vm_map { struct uvm_map_addr addr; /* [v] Entry tree, by addr */ vsize_t size; /* virtual size */ - int ref_count; /* Reference count */ + int ref_count; /* [a] Reference count */ int flags; /* flags */ struct mutex flags_lock; /* flags lock */ unsigned int timestamp; /* Version number */ -- 2.20.1