Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/kern/subr_pool.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/kern/subr_pool.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.182 retrieving revision 1.189 diff -u -p -r1.182 -r1.189 --- src/sys/kern/subr_pool.c 2010/01/20 23:40:42 1.182 +++ src/sys/kern/subr_pool.c 2011/03/22 15:16:23 1.189 @@ -1,7 +1,8 @@ -/* $NetBSD: subr_pool.c,v 1.182 2010/01/20 23:40:42 rmind Exp $ */ +/* $NetBSD: subr_pool.c,v 1.189 2011/03/22 15:16:23 pooka Exp $ */ /*- - * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008 The NetBSD Foundation, Inc. + * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010 + * The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -31,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.182 2010/01/20 23:40:42 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.189 2011/03/22 15:16:23 pooka Exp $"); #include "opt_ddb.h" #include "opt_pool.h" @@ -53,7 +54,10 @@ __KERNEL_RCSID(0, "$NetBSD: subr_pool.c, #include #include -#include +#include +#ifdef DIAGNOSTIC +#include /* uvm_km_va_drain */ +#endif /* * Pool resource management utility. @@ -178,6 +182,8 @@ static struct pool pcg_large_pool; static struct pool cache_pool; static struct pool cache_cpu_pool; +pool_cache_t pnbuf_cache; /* pathname buffer cache */ + /* List of all caches. */ TAILQ_HEAD(,pool_cache) pool_cache_head = TAILQ_HEAD_INITIALIZER(pool_cache_head); @@ -561,6 +567,11 @@ pool_reclaim_register(struct pool *pp) callback_register(&vm_map_to_kernel(map)->vmk_reclaim_callback, &pp->pr_reclaimerentry, pp, pool_reclaim_callback); splx(s); + +#ifdef DIAGNOSTIC + /* Diagnostic drain attempt. */ + uvm_km_va_drain(map, 0); +#endif } static void @@ -983,19 +994,17 @@ pool_get(struct pool *pp, int flags) void *v; #ifdef DIAGNOSTIC - if (__predict_false(pp->pr_itemsperpage == 0)) - panic("pool_get: pool %p: pr_itemsperpage is zero, " - "pool not initialized?", pp); - if (__predict_false(curlwp == NULL && doing_shutdown == 0 && - (flags & PR_WAITOK) != 0)) - panic("pool_get: %s: must have NOWAIT", pp->pr_wchan); - -#endif /* DIAGNOSTIC */ -#ifdef LOCKDEBUG + if (pp->pr_itemsperpage == 0) + panic("pool_get: pool '%s': pr_itemsperpage is zero, " + "pool not initialized?", pp->pr_wchan); + if ((cpu_intr_p() || cpu_softintr_p()) && pp->pr_ipl == IPL_NONE && + !cold && panicstr == NULL) + panic("pool '%s' is IPL_NONE, but called from " + "interrupt context\n", pp->pr_wchan); +#endif if (flags & PR_WAITOK) { ASSERT_SLEEPABLE(); } -#endif mutex_enter(&pp->pr_lock); pr_enter(pp, file, line); @@ -1603,6 +1612,8 @@ pool_sethardlimit(struct pool *pp, int n /* * Release all complete pages that have not been used recently. + * + * Might be called from interrupt context. */ int #ifdef POOL_DIAGNOSTIC @@ -1617,6 +1628,10 @@ pool_reclaim(struct pool *pp) bool klock; int rv; + if (cpu_intr_p() || cpu_softintr_p()) { + KASSERT(pp->pr_ipl != IPL_NONE); + } + if (pp->pr_drain_hook != NULL) { /* * The drain hook must be called with the pool unlocked. @@ -1735,12 +1750,13 @@ pool_drain_start(struct pool **ppp, uint } } -void +bool pool_drain_end(struct pool *pp, uint64_t where) { + bool reclaimed; if (pp == NULL) - return; + return false; KASSERT(pp->pr_refcnt > 0); @@ -1749,13 +1765,15 @@ pool_drain_end(struct pool *pp, uint64_t xc_wait(where); /* Drain the cache (if any) and pool.. */ - pool_reclaim(pp); + reclaimed = pool_reclaim(pp); /* Finally, unlock the pool. */ mutex_enter(&pool_head_lock); pp->pr_refcnt--; cv_broadcast(&pool_busy); mutex_exit(&pool_head_lock); + + return reclaimed; } /* @@ -1904,7 +1922,7 @@ pool_print1(struct pool *pp, const char if (pc != NULL) { cpuhit = 0; cpumiss = 0; - for (i = 0; i < MAXCPUS; i++) { + for (i = 0; i < __arraycount(pc->pc_cpus); i++) { if ((cc = pc->pc_cpus[i]) == NULL) continue; cpuhit += cc->cc_hits; @@ -2158,7 +2176,7 @@ pool_cache_destroy(pool_cache_t pc) mutex_exit(&pp->pr_lock); /* Destroy per-CPU data */ - for (i = 0; i < MAXCPUS; i++) + for (i = 0; i < __arraycount(pc->pc_cpus); i++) pool_cache_invalidate_cpu(pc, i); /* Finally, destroy it. */ @@ -2180,7 +2198,7 @@ pool_cache_cpu_init1(struct cpu_info *ci index = ci->ci_index; - KASSERT(index < MAXCPUS); + KASSERT(index < __arraycount(pc->pc_cpus)); if ((cc = pc->pc_cpus[index]) != NULL) { KASSERT(cc->cc_cpuindex == index); @@ -2519,11 +2537,14 @@ pool_cache_get_paddr(pool_cache_t pc, in void *object; int s; -#ifdef LOCKDEBUG + KASSERTMSG((!cpu_intr_p() && !cpu_softintr_p()) || + (pc->pc_pool.pr_ipl != IPL_NONE || cold || panicstr != NULL), + ("pool '%s' is IPL_NONE, but called from interrupt context\n", + pc->pc_pool.pr_wchan)); + if (flags & PR_WAITOK) { ASSERT_SLEEPABLE(); } -#endif /* Lock out interrupts and disable preemption. */ s = splvm(); @@ -3039,7 +3060,7 @@ found: goto print; } } - for (i = 0; i < MAXCPUS; i++) { + for (i = 0; i < __arraycount(pc->pc_cpus); i++) { pool_cache_cpu_t *cc; if ((cc = pc->pc_cpus[i]) == NULL) {