Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/sys Add vmem_xfreeall(), which frees all allocated regio...
details: https://anonhg.NetBSD.org/src/rev/0b21402d3a5d
branches: trunk
changeset: 973024:0b21402d3a5d
user: thorpej <thorpej%NetBSD.org@localhost>
date: Tue Jun 16 01:29:00 2020 +0000
description:
Add vmem_xfreeall(), which frees all allocated regions in the specified arena.
All outstanding allocations MUST have been performed with vmem_xalloc() or
else the behavior is undefined. (This also implies that the arena must also
not have a quantum cache; note this in the documentation.)
diffstat:
distrib/sets/lists/comp/mi | 5 ++++-
share/man/man9/Makefile | 5 +++--
share/man/man9/vmem.9 | 25 +++++++++++++++++++++++--
sys/kern/subr_vmem.c | 43 ++++++++++++++++++++++++++++++++++++++++---
sys/sys/vmem.h | 3 ++-
5 files changed, 72 insertions(+), 9 deletions(-)
diffs (200 lines):
diff -r cd9f15c48beb -r 0b21402d3a5d distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Tue Jun 16 00:47:21 2020 +0000
+++ b/distrib/sets/lists/comp/mi Tue Jun 16 01:29:00 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.2337 2020/06/15 23:41:55 christos Exp $
+# $NetBSD: mi,v 1.2338 2020/06/16 01:29:01 thorpej Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@@ -12439,6 +12439,7 @@
./usr/share/man/cat9/vmem_free.0 comp-sys-catman .cat
./usr/share/man/cat9/vmem_xalloc.0 comp-sys-catman .cat
./usr/share/man/cat9/vmem_xfree.0 comp-sys-catman .cat
+./usr/share/man/cat9/vmem_xfreeall.0 comp-sys-catman .cat
./usr/share/man/cat9/vn_bwrite.0 comp-sys-catman .cat
./usr/share/man/cat9/vn_close.0 comp-sys-catman .cat
./usr/share/man/cat9/vn_closefile.0 comp-sys-catman .cat
@@ -20543,6 +20544,7 @@
./usr/share/man/html9/vmem_free.html comp-sys-htmlman html
./usr/share/man/html9/vmem_xalloc.html comp-sys-htmlman html
./usr/share/man/html9/vmem_xfree.html comp-sys-htmlman html
+./usr/share/man/html9/vmem_xfreeall.html comp-sys-htmlman html
./usr/share/man/html9/vn_bwrite.html comp-sys-htmlman html
./usr/share/man/html9/vn_close.html comp-sys-htmlman html
./usr/share/man/html9/vn_closefile.html comp-sys-htmlman html
@@ -28886,6 +28888,7 @@
./usr/share/man/man9/vmem_free.9 comp-sys-man .man
./usr/share/man/man9/vmem_xalloc.9 comp-sys-man .man
./usr/share/man/man9/vmem_xfree.9 comp-sys-man .man
+./usr/share/man/man9/vmem_xfreeall.9 comp-sys-man .man
./usr/share/man/man9/vn_bwrite.9 comp-sys-man .man
./usr/share/man/man9/vn_close.9 comp-sys-man .man
./usr/share/man/man9/vn_closefile.9 comp-sys-man .man
diff -r cd9f15c48beb -r 0b21402d3a5d share/man/man9/Makefile
--- a/share/man/man9/Makefile Tue Jun 16 00:47:21 2020 +0000
+++ b/share/man/man9/Makefile Tue Jun 16 01:29:00 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.450 2020/05/01 21:43:24 jdolecek Exp $
+# $NetBSD: Makefile,v 1.451 2020/06/16 01:29:00 thorpej Exp $
# Makefile for section 9 (kernel function and variable) manual pages.
@@ -1030,7 +1030,8 @@
vmem.9 vmem_destroy.9 \
vmem.9 vmem_free.9 \
vmem.9 vmem_xalloc.9 \
- vmem.9 vmem_xfree.9
+ vmem.9 vmem_xfree.9 \
+ vmem.9 vmem_xfreeall.9
MLINKS+=vnode.9 vref.9 \
vnode.9 vrele.9 \
vnode.9 vrele_async.9 \
diff -r cd9f15c48beb -r 0b21402d3a5d share/man/man9/vmem.9
--- a/share/man/man9/vmem.9 Tue Jun 16 00:47:21 2020 +0000
+++ b/share/man/man9/vmem.9 Tue Jun 16 01:29:00 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: vmem.9,v 1.19 2019/11/06 11:55:18 wiz Exp $
+.\" $NetBSD: vmem.9,v 1.20 2020/06/16 01:29:00 thorpej Exp $
.\"
.\" Copyright (c)2006 YAMAMOTO Takashi,
.\" All rights reserved.
@@ -25,7 +25,7 @@
.\" SUCH DAMAGE.
.\"
.\" ------------------------------------------------------------
-.Dd November 5, 2019
+.Dd June 15, 2020
.Dt VMEM 9
.Os
.\" ------------------------------------------------------------
@@ -63,6 +63,9 @@
.Ft void
.Fn vmem_xfree "vmem_t *vm" "vmem_addr_t addr" "vmem_size_t size"
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+.Ft void
+.Fn vmem_xfreeall "vmem_t *vm"
+.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Ft int
.Fn vmem_alloc "vmem_t *vm" "vmem_size_t size" "vm_flag_t flags" "vmem_addr_t *addrp"
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -407,6 +410,24 @@
.El
.Pp
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+.Fn vmem_xfreeall
+frees all resources that have been allocated by
+.Fn vmem_xalloc
+to the arena.
+.Bl -tag -offset indent -width addr
+.It Fa vm
+The arena which we free to.
+Note that this function is may not be used on arenas
+where resources have been allocated using
+.Fn vmem_alloc
+or arenas that have a quantum cache
+.Po
+i.e. were created with a non-zero
+.Fa qcache_max
+.Pc .
+.El
+.Pp
+.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Fn vmem_alloc
allocates a resource from the arena.
.Bl -tag -offset indent -width flags
diff -r cd9f15c48beb -r 0b21402d3a5d sys/kern/subr_vmem.c
--- a/sys/kern/subr_vmem.c Tue Jun 16 00:47:21 2020 +0000
+++ b/sys/kern/subr_vmem.c Tue Jun 16 01:29:00 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_vmem.c,v 1.103 2020/04/21 17:50:19 ad Exp $ */
+/* $NetBSD: subr_vmem.c,v 1.104 2020/06/16 01:29:00 thorpej Exp $ */
/*-
* Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi,
@@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.103 2020/04/21 17:50:19 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.104 2020/06/16 01:29:00 thorpej Exp $");
#if defined(_KERNEL) && defined(_KERNEL_OPT)
#include "opt_ddb.h"
@@ -194,6 +194,8 @@
static size_t vmem_btag_freelist_count = 0;
static struct pool vmem_btag_pool;
+static void vmem_xfree_bt(vmem_t *, bt_t *);
+
static void
vmem_kick_pdaemon(void)
{
@@ -1313,7 +1315,6 @@
vmem_xfree(vmem_t *vm, vmem_addr_t addr, vmem_size_t size)
{
bt_t *bt;
- bt_t *t;
KASSERT(size > 0);
@@ -1324,6 +1325,42 @@
KASSERT(bt->bt_start == addr);
KASSERT(bt->bt_size == vmem_roundup_size(vm, size) ||
bt->bt_size - vmem_roundup_size(vm, size) <= vm->vm_quantum_mask);
+
+ /* vmem_xfree_bt() drops the lock. */
+ vmem_xfree_bt(vm, bt);
+}
+
+void
+vmem_xfreeall(vmem_t *vm)
+{
+ bt_t *bt;
+
+ /* This can't be used if the arena has a quantum cache. */
+ KASSERT(vm->vm_qcache_max == 0);
+
+ for (;;) {
+ VMEM_LOCK(vm);
+ TAILQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
+ if (bt->bt_type == BT_TYPE_BUSY)
+ break;
+ }
+ if (bt != NULL) {
+ /* vmem_xfree_bt() drops the lock. */
+ vmem_xfree_bt(vm, bt);
+ } else {
+ VMEM_UNLOCK(vm);
+ return;
+ }
+ }
+}
+
+static void
+vmem_xfree_bt(vmem_t *vm, bt_t *bt)
+{
+ bt_t *t;
+
+ VMEM_ASSERT_LOCKED(vm);
+
KASSERT(bt->bt_type == BT_TYPE_BUSY);
bt_rembusy(vm, bt);
bt->bt_type = BT_TYPE_FREE;
diff -r cd9f15c48beb -r 0b21402d3a5d sys/sys/vmem.h
--- a/sys/sys/vmem.h Tue Jun 16 00:47:21 2020 +0000
+++ b/sys/sys/vmem.h Tue Jun 16 01:29:00 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmem.h,v 1.20 2013/01/29 21:26:24 para Exp $ */
+/* $NetBSD: vmem.h,v 1.21 2020/06/16 01:29:00 thorpej Exp $ */
/*-
* Copyright (c)2006 YAMAMOTO Takashi,
@@ -72,6 +72,7 @@
int vmem_xalloc(vmem_t *, vmem_size_t, vmem_size_t, vmem_size_t,
vmem_size_t, vmem_addr_t, vmem_addr_t, vm_flag_t, vmem_addr_t *);
void vmem_xfree(vmem_t *, vmem_addr_t, vmem_size_t);
+void vmem_xfreeall(vmem_t *);
int vmem_add(vmem_t *, vmem_addr_t, vmem_size_t, vm_flag_t);
vmem_size_t vmem_roundup_size(vmem_t *, vmem_size_t);
vmem_size_t vmem_size(vmem_t *, int typemask);
Home |
Main Index |
Thread Index |
Old Index