Module Name:    src
Committed By:   thorpej
Date:           Thu Oct 15 20:50:13 UTC 2009

Modified Files:
        src/share/man/man9: pool_cache.9
        src/sys/kern: subr_pool.c
        src/sys/sys: pool.h

Log Message:
- pool_cache_invalidate(): broadcast a cross-call to drain the per-CPU
  caches before draining the global cache.
- pool_cache_invalidate_local(): remove.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/share/man/man9/pool_cache.9
cvs rdiff -u -r1.175 -r1.176 src/sys/kern/subr_pool.c
cvs rdiff -u -r1.66 -r1.67 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/share/man/man9/pool_cache.9
diff -u src/share/man/man9/pool_cache.9:1.12 src/share/man/man9/pool_cache.9:1.13
--- src/share/man/man9/pool_cache.9:1.12	Thu Oct  8 23:15:26 2009
+++ src/share/man/man9/pool_cache.9	Thu Oct 15 20:50:13 2009
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pool_cache.9,v 1.12 2009/10/08 23:15:26 wiz Exp $
+.\"	$NetBSD: pool_cache.9,v 1.13 2009/10/15 20:50:13 thorpej Exp $
 .\"
 .\" Copyright (c)2003 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -53,7 +53,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" ------------------------------------------------------------
-.Dd October 9, 2009
+.Dd October 15, 2009
 .Dt POOL_CACHE 9
 .Os
 .\" ------------------------------------------------------------
@@ -67,7 +67,6 @@
 .Nm pool_cache_put ,
 .Nm pool_cache_destruct_object ,
 .Nm pool_cache_invalidate ,
-.Nm pool_cache_invalidate_local ,
 .Nm pool_cache_sethiwat ,
 .Nm pool_cache_setlowat
 .Nd resource-pool cache manager
@@ -108,9 +107,6 @@
 .Ft void
 .Fn pool_cache_invalidate \
 "pool_cache_t pc"
-.Ft void
-.Fn pool_cache_invalidate_local \
-"pool_cache_t pc"
 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 .Ft void
 .Fn pool_cache_sethiwat \
@@ -279,22 +275,11 @@
 .Pp
 Invalidate a pool cache
 .Fa pc .
-Destruct and release all objects in the global cache.
-Per-CPU caches will not be invalidated by this call, meaning that it
-is still possible to allocate "stale" items from the cache.
-If relevant, the user must check for this condition when allocating
-items.
-.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-.It Fn pool_cache_invalidate_local "pc"
-.Pp
-Invalidate local, current CPU pool cache
-.Fa pc .
-Destruct and release all objects in the local, current CPU cache.
-Only the Per-CPU caches associated to the current CPU calling the routine
-will be invalidated, meaning that stale items can still be allocated from
-other CPUs or the global cache.
-It is the caller's responsibility to ensure that such conditions do
-not occur.
+All objects in the cache will be destructed and freed back to the pool
+backing the cache.
+For pool caches that vend constructed objects, consumers of this API
+must take care to provide proper synchronization between the input to
+the constructor and cache invalidation.
 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 .It Fn pool_cache_sethiwat "pc" "nitems"
 .Pp

Index: src/sys/kern/subr_pool.c
diff -u src/sys/kern/subr_pool.c:1.175 src/sys/kern/subr_pool.c:1.176
--- src/sys/kern/subr_pool.c:1.175	Thu Oct  8 21:54:45 2009
+++ src/sys/kern/subr_pool.c	Thu Oct 15 20:50:12 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_pool.c,v 1.175 2009/10/08 21:54:45 jym Exp $	*/
+/*	$NetBSD: subr_pool.c,v 1.176 2009/10/15 20:50:12 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.175 2009/10/08 21:54:45 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.176 2009/10/15 20:50:12 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pool.h"
@@ -2289,11 +2289,33 @@
  *
  *	Invalidate a pool cache (destruct and release all of the
  *	cached objects).  Does not reclaim objects from the pool.
+ *
+ *	Note: For pool caches that provide constructed objects, there
+ *	is an assumption that another level of synchronization is occurring
+ *	between the input to the constructor and the cache invalidation.
  */
 void
 pool_cache_invalidate(pool_cache_t pc)
 {
 	pcg_t *full, *empty, *part;
+	uint64_t where;
+
+	if (ncpu < 2) {
+		/*
+		 * We might be called early enough in the boot process
+		 * for the CPU data structures to not be fully initialized.
+		 * In this case, simply gather the local CPU's cache now
+		 * since it will be the only one running.
+		 */
+		pool_cache_xcall(pc);
+	} else {
+		/*
+		 * Gather all of the CPU-specific caches into the
+		 * global cache.
+		 */
+		where = xc_broadcast(0, (xcfunc_t)pool_cache_xcall, pc, NULL);
+		xc_wait(where);
+	}
 
 	mutex_enter(&pc->pc_lock);
 	full = pc->pc_fullgroups;
@@ -2313,20 +2335,6 @@
 }
 
 /*
- * pool_cache_invalidate_local:
- *
- *	Invalidate all local ('current CPU') cached objects in
- *	pool cache.
- *	It is caller's responsibility to ensure that no operation is
- *	taking place on this pool cache while doing the local invalidation.
- */
-void
-pool_cache_invalidate_local(pool_cache_t pc)
-{
-	pool_cache_invalidate_cpu(pc, curcpu()->ci_index);
-}
-
-/*
  * pool_cache_invalidate_cpu:
  *
  *	Invalidate all CPU-bound cached objects in pool cache, the CPU being

Index: src/sys/sys/pool.h
diff -u src/sys/sys/pool.h:1.66 src/sys/sys/pool.h:1.67
--- src/sys/sys/pool.h:1.66	Thu Oct  8 21:54:45 2009
+++ src/sys/sys/pool.h	Thu Oct 15 20:50:12 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pool.h,v 1.66 2009/10/08 21:54:45 jym Exp $	*/
+/*	$NetBSD: pool.h,v 1.67 2009/10/15 20:50:12 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2000, 2007 The NetBSD Foundation, Inc.
@@ -321,7 +321,6 @@
 void		pool_cache_put_paddr(pool_cache_t, void *, paddr_t);
 void		pool_cache_destruct_object(pool_cache_t, void *);
 void		pool_cache_invalidate(pool_cache_t);
-void		pool_cache_invalidate_local(pool_cache_t);
 bool		pool_cache_reclaim(pool_cache_t);
 void		pool_cache_set_drain_hook(pool_cache_t,
 		    void (*)(void *, int), void *);

Reply via email to