Module Name: src Committed By: thorpej Date: Tue Dec 21 18:59:23 UTC 2021
Modified Files: src/distrib/sets/lists/comp: mi src/share/man/man9: Makefile pool_cache.9 src/sys/kern: subr_pool.c src/sys/sys: param.h pool.h Log Message: Add pool_cache_setpredestruct(), which allows a pool cache to specify a function to be called before the destructor for a batch of one or more objects is called. This can be used as a synchronization point by subsystems that rely on the type-stable nature of pool cache objects or subsystems that use other forms of passive serialization. To generate a diff of this commit: cvs rdiff -u -r1.2399 -r1.2400 src/distrib/sets/lists/comp/mi cvs rdiff -u -r1.458 -r1.459 src/share/man/man9/Makefile cvs rdiff -u -r1.22 -r1.23 src/share/man/man9/pool_cache.9 cvs rdiff -u -r1.277 -r1.278 src/sys/kern/subr_pool.c cvs rdiff -u -r1.705 -r1.706 src/sys/sys/param.h cvs rdiff -u -r1.94 -r1.95 src/sys/sys/pool.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/comp/mi diff -u src/distrib/sets/lists/comp/mi:1.2399 src/distrib/sets/lists/comp/mi:1.2400 --- src/distrib/sets/lists/comp/mi:1.2399 Tue Dec 7 17:39:53 2021 +++ src/distrib/sets/lists/comp/mi Tue Dec 21 18:59:22 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.2399 2021/12/07 17:39:53 brad Exp $ +# $NetBSD: mi,v 1.2400 2021/12/21 18:59:22 thorpej Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. ./etc/mtree/set.comp comp-sys-root @@ -12282,6 +12282,7 @@ ./usr/share/man/cat9/pool_cache_sethardlimit.0 comp-sys-catman .cat ./usr/share/man/cat9/pool_cache_sethiwat.0 comp-sys-catman .cat ./usr/share/man/cat9/pool_cache_setlowat.0 comp-sys-catman .cat +./usr/share/man/cat9/pool_cache_setpredestruct.0 comp-sys-catman .cat ./usr/share/man/cat9/pool_create.0 comp-sys-catman .cat ./usr/share/man/cat9/pool_destroy.0 comp-sys-catman .cat ./usr/share/man/cat9/pool_get.0 comp-sys-catman .cat @@ -20474,6 +20475,7 @@ ./usr/share/man/html9/pool_cache_sethardlimit.html comp-sys-htmlman html ./usr/share/man/html9/pool_cache_sethiwat.html comp-sys-htmlman html ./usr/share/man/html9/pool_cache_setlowat.html comp-sys-htmlman html +./usr/share/man/html9/pool_cache_setpredestruct.html comp-sys-htmlman html ./usr/share/man/html9/pool_create.html comp-sys-htmlman html ./usr/share/man/html9/pool_destroy.html comp-sys-htmlman html ./usr/share/man/html9/pool_get.html comp-sys-htmlman html @@ -28827,6 +28829,7 @@ ./usr/share/man/man9/pool_cache_sethardlimit.9 comp-sys-man .man ./usr/share/man/man9/pool_cache_sethiwat.9 comp-sys-man .man ./usr/share/man/man9/pool_cache_setlowat.9 comp-sys-man .man +./usr/share/man/man9/pool_cache_setpredestruct.9 comp-sys-man .man ./usr/share/man/man9/pool_create.9 comp-sys-man .man ./usr/share/man/man9/pool_destroy.9 comp-sys-man .man ./usr/share/man/man9/pool_get.9 comp-sys-man .man Index: src/share/man/man9/Makefile diff -u src/share/man/man9/Makefile:1.458 src/share/man/man9/Makefile:1.459 --- src/share/man/man9/Makefile:1.458 Wed Apr 28 00:49:22 2021 +++ src/share/man/man9/Makefile Tue Dec 21 18:59:22 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.458 2021/04/28 00:49:22 thorpej Exp $ +# $NetBSD: Makefile,v 1.459 2021/12/21 18:59:22 thorpej Exp $ # Makefile for section 9 (kernel function and variable) manual pages. @@ -758,7 +758,8 @@ MLINKS+=pool_cache.9 pool_cache_init.9 \ pool_cache.9 pool_cache_invalidate.9 \ pool_cache.9 pool_cache_sethiwat.9 \ pool_cache.9 pool_cache_setlowat.9 \ - pool_cache.9 pool_cache_sethardlimit.9 + pool_cache.9 pool_cache_sethardlimit.9 \ + pool_cache.9 pool_cache_setpredestruct.9 MLINKS+=powerhook_establish.9 powerhook_disestablish.9 MLINKS+=preempt.9 yield.9 MLINKS+=pserialize.9 pserialize_create.9 \ Index: src/share/man/man9/pool_cache.9 diff -u src/share/man/man9/pool_cache.9:1.22 src/share/man/man9/pool_cache.9:1.23 --- src/share/man/man9/pool_cache.9:1.22 Mon Apr 13 08:59:14 2020 +++ src/share/man/man9/pool_cache.9 Tue Dec 21 18:59:22 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: pool_cache.9,v 1.22 2020/04/13 08:59:14 wiz Exp $ +.\" $NetBSD: pool_cache.9,v 1.23 2021/12/21 18:59:22 thorpej Exp $ .\" .\" Copyright (c)2003 YAMAMOTO Takashi, .\" All rights reserved. @@ -53,7 +53,7 @@ .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" ------------------------------------------------------------ -.Dd April 12, 2020 +.Dd December 21, 2021 .Dt POOL_CACHE 9 .Os .\" ------------------------------------------------------------ @@ -69,7 +69,8 @@ .Nm pool_cache_invalidate , .Nm pool_cache_sethiwat , .Nm pool_cache_setlowat , -.Nm pool_cache_sethardlimit +.Nm pool_cache_sethardlimit , +.Nm pool_cache_setpredestruct .Nd resource-pool cache manager .\" ------------------------------------------------------------ .Sh SYNOPSIS @@ -119,6 +120,10 @@ .Fn pool_cache_sethardlimit \ "pool_cache_t pc" "int n" "const char *warnmess" "int ratecap" .\" ------------------------------------------------------------ +.Ft void +.Fn pool_cache_setpredestruct \ +"pool_cache_t pc" "void (*fn)(void *)" +.\" ------------------------------------------------------------ .Sh DESCRIPTION These utility routines provide management of pools of fixed-sized areas of memory. @@ -347,6 +352,15 @@ will be logged. represents the minimal interval (in seconds) after which another warning message is issued when the pool hits its hard limit again. .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +.It Fn pool_cache_setpredestruct "fn" +Sets a pre-destructor hook for the pool cache. +This hook will be invoked +.Pq with the same argument passed to the destructor +before a batch of one or more objects is destructed. +Pool cache users who rely on type-stability or use other +forms of passive serialization may use this hook as a +synchronization point. +.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .It Fn pool_cache_prime "pc" "n" Set the minimum number of total items (both free and allocated) for the backing .Xr pool 9 Index: src/sys/kern/subr_pool.c diff -u src/sys/kern/subr_pool.c:1.277 src/sys/kern/subr_pool.c:1.278 --- src/sys/kern/subr_pool.c:1.277 Sun Jul 25 06:00:31 2021 +++ src/sys/kern/subr_pool.c Tue Dec 21 18:59:22 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_pool.c,v 1.277 2021/07/25 06:00:31 simonb Exp $ */ +/* $NetBSD: subr_pool.c,v 1.278 2021/12/21 18:59:22 thorpej Exp $ */ /* * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015, 2018, @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.277 2021/07/25 06:00:31 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.278 2021/12/21 18:59:22 thorpej Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -2119,6 +2119,7 @@ pool_cache_bootstrap(pool_cache_t pc, si pc->pc_partgroups = NULL; pc->pc_ctor = ctor; pc->pc_dtor = dtor; + pc->pc_pre_dtor = NULL; pc->pc_arg = arg; pc->pc_refcnt = 0; pc->pc_freecheck = NULL; @@ -2164,6 +2165,19 @@ pool_cache_bootstrap(pool_cache_t pc, si } /* + * pool_cache_setpredestruct: + * + * Set a pre-destructor hook for the specified pool cache. + */ +void +pool_cache_setpredestruct(pool_cache_t pc, void (*fn)(void *)) +{ + KASSERT(pc->pc_pre_dtor == NULL); + pc->pc_pre_dtor = fn; + membar_sync(); +} + +/* * pool_cache_destroy: * * Destroy a pool cache. @@ -2290,6 +2304,20 @@ pool_cache_reclaim(pool_cache_t pc) return pool_reclaim(&pc->pc_pool); } +static inline void +pool_cache_pre_destruct(pool_cache_t pc) +{ + /* + * Call the pre-destruct hook before destructing a batch + * of objects. Users of this hook can perform passive + * serialization other other activities that need to be + * performed once-per-batch (rather than once-per-object). + */ + if (__predict_false(pc->pc_pre_dtor != NULL)) { + (*pc->pc_pre_dtor)(pc->pc_arg); + } +} + static void pool_cache_destruct_object1(pool_cache_t pc, void *object) { @@ -2309,6 +2337,7 @@ pool_cache_destruct_object(pool_cache_t FREECHECK_IN(&pc->pc_freecheck, object); + pool_cache_pre_destruct(pc); pool_cache_destruct_object1(pc, object); } @@ -2325,6 +2354,12 @@ pool_cache_invalidate_groups(pool_cache_ pcg_t *next; int i, n; + if (pcg == NULL) { + return 0; + } + + pool_cache_pre_destruct(pc); + for (n = 0; pcg != NULL; pcg = next, n++) { next = pcg->pcg_next; Index: src/sys/sys/param.h diff -u src/sys/sys/param.h:1.705 src/sys/sys/param.h:1.706 --- src/sys/sys/param.h:1.705 Wed Oct 20 03:09:45 2021 +++ src/sys/sys/param.h Tue Dec 21 18:59:22 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.705 2021/10/20 03:09:45 thorpej Exp $ */ +/* $NetBSD: param.h,v 1.706 2021/12/21 18:59:22 thorpej Exp $ */ /*- * Copyright (c) 1982, 1986, 1989, 1993 @@ -67,7 +67,7 @@ * 2.99.9 (299000900) */ -#define __NetBSD_Version__ 999009200 /* NetBSD 9.99.92 */ +#define __NetBSD_Version__ 999009300 /* NetBSD 9.99.93 */ #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \ (m) * 1000000) + (p) * 100) <= __NetBSD_Version__) Index: src/sys/sys/pool.h diff -u src/sys/sys/pool.h:1.94 src/sys/sys/pool.h:1.95 --- src/sys/sys/pool.h:1.94 Sun Jul 25 06:00:31 2021 +++ src/sys/sys/pool.h Tue Dec 21 18:59:22 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pool.h,v 1.94 2021/07/25 06:00:31 simonb Exp $ */ +/* $NetBSD: pool.h,v 1.95 2021/12/21 18:59:22 thorpej Exp $ */ /*- * Copyright (c) 1997, 1998, 1999, 2000, 2007, 2020 @@ -265,7 +265,8 @@ struct pool_cache { int pc_ncpu; /* number cpus set up */ int (*pc_ctor)(void *, void *, int); void (*pc_dtor)(void *, void *); - void *pc_arg; /* for ctor/ctor */ + void (*pc_pre_dtor)(void *); + void *pc_arg; /* for ctor/dtor/pre_dtor */ unsigned int pc_refcnt; /* ref count for pagedaemon, etc */ void *pc_cpus[MAXCPUS]; @@ -341,6 +342,7 @@ void pool_cache_bootstrap(pool_cache_t, const char *, struct pool_allocator *, int, int (*)(void *, void *, int), void (*)(void *, void *), void *); +void pool_cache_setpredestruct(pool_cache_t, void (*)(void *)); void pool_cache_destroy(pool_cache_t); void pool_cache_bootstrap_destroy(pool_cache_t); void *pool_cache_get_paddr(pool_cache_t, int, paddr_t *);