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.128.2.6 retrieving revision 1.129.12.1 diff -u -p -r1.128.2.6 -r1.129.12.1 --- src/sys/kern/subr_pool.c 2007/08/20 21:27:37 1.128.2.6 +++ src/sys/kern/subr_pool.c 2007/09/03 16:48:49 1.129.12.1 @@ -1,7 +1,7 @@ -/* $NetBSD: subr_pool.c,v 1.128.2.6 2007/08/20 21:27:37 ad Exp $ */ +/* $NetBSD: subr_pool.c,v 1.129.12.1 2007/09/03 16:48:49 jmcneill Exp $ */ /*- - * Copyright (c) 1997, 1999, 2000, 2002, 2007 The NetBSD Foundation, Inc. + * Copyright (c) 1997, 1999, 2000, 2002 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.128.2.6 2007/08/20 21:27:37 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.129.12.1 2007/09/03 16:48:49 jmcneill Exp $"); #include "opt_pool.h" #include "opt_poollog.h" @@ -54,7 +54,6 @@ __KERNEL_RCSID(0, "$NetBSD: subr_pool.c, #include #include #include -#include #include @@ -102,8 +101,8 @@ int pool_inactive_time = 10; /* Next candidate for drainage (see pool_drain()) */ static struct pool *drainpp; -/* This lock protects both pool_head and drainpp. */ -static kmutex_t pool_head_lock; +/* This spin lock protects both pool_head and drainpp. */ +struct simplelock pool_head_slock = SIMPLELOCK_INITIALIZER; typedef uint8_t pool_item_freelist_t; @@ -423,12 +422,16 @@ static void pr_pagelist_free(struct pool *pp, struct pool_pagelist *pq) { struct pool_item_header *ph; + int s; while ((ph = LIST_FIRST(pq)) != NULL) { LIST_REMOVE(ph, ph_pagelist); pool_allocator_free(pp, ph->ph_page); - if ((pp->pr_roflags & PR_PHINPAGE) == 0) + if ((pp->pr_roflags & PR_PHINPAGE) == 0) { + s = splvm(); pool_put(pp->pr_phpool, ph); + splx(s); + } } } @@ -440,7 +443,7 @@ pr_rmpage(struct pool *pp, struct pool_i struct pool_pagelist *pq) { - KASSERT(mutex_owned(&pp->pr_lock)); + LOCK_ASSERT(simple_lock_held(&pp->pr_slock)); /* * If the page was idle, decrement the idle page count. @@ -554,8 +557,6 @@ pool_subsystem_init(void) __link_set_decl(pools, struct link_pool_init); struct link_pool_init * const *pi; - mutex_init(&pool_head_lock, MUTEX_DEFAULT, IPL_NONE); - __link_set_foreach(pi, pools) pool_init((*pi)->pp, (*pi)->size, (*pi)->align, (*pi)->align_offset, (*pi)->flags, (*pi)->wchan, @@ -583,7 +584,7 @@ pool_init(struct pool *pp, size_t size, struct pool *pp1; #endif size_t trysize, phsize; - int off, slack; + int off, slack, s; KASSERT((1UL << (CHAR_BIT * sizeof(pool_item_freelist_t))) - 2 >= PHPOOL_FREELIST_NELEM(PHPOOL_MAX - 1)); @@ -624,7 +625,7 @@ pool_init(struct pool *pp, size_t size, TAILQ_INIT(&palloc->pa_list); - mutex_init(&palloc->pa_lock, MUTEX_DRIVER, IPL_VM); + simple_lock_init(&palloc->pa_slock); palloc->pa_pagemask = ~(palloc->pa_pagesz - 1); palloc->pa_pageshift = ffs(palloc->pa_pagesz) - 1; @@ -768,9 +769,7 @@ pool_init(struct pool *pp, size_t size, pp->pr_entered_file = NULL; pp->pr_entered_line = 0; - mutex_init(&pp->pr_lock, MUTEX_DRIVER, ipl); - cv_init(&pp->pr_cv, wchan); - pp->pr_ipl = ipl; + simple_lock_init(&pp->pr_slock); /* * Initialize private page header pool and cache magazine pool if we @@ -803,21 +802,17 @@ pool_init(struct pool *pp, size_t size, 0, "pcgpool", &pool_allocator_meta, IPL_VM); } - if (__predict_true(!cold)) { - /* Insert into the list of all pools. */ - mutex_enter(&pool_head_lock); - LIST_INSERT_HEAD(&pool_head, pp, pr_poollist); - mutex_exit(&pool_head_lock); - - /* Insert this into the list of pools using this allocator. */ - mutex_enter(&palloc->pa_lock); - TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list); - mutex_exit(&palloc->pa_lock); - } else { - LIST_INSERT_HEAD(&pool_head, pp, pr_poollist); - TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list); - } - + /* Insert into the list of all pools. */ + simple_lock(&pool_head_slock); + LIST_INSERT_HEAD(&pool_head, pp, pr_poollist); + simple_unlock(&pool_head_slock); + + /* Insert this into the list of pools using this allocator. */ + s = splvm(); + simple_lock(&palloc->pa_slock); + TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list); + simple_unlock(&palloc->pa_slock); + splx(s); pool_reclaim_register(pp); } @@ -829,21 +824,25 @@ pool_destroy(struct pool *pp) { struct pool_pagelist pq; struct pool_item_header *ph; + int s; /* Remove from global pool list */ - mutex_enter(&pool_head_lock); + simple_lock(&pool_head_slock); LIST_REMOVE(pp, pr_poollist); if (drainpp == pp) drainpp = NULL; - mutex_exit(&pool_head_lock); + simple_unlock(&pool_head_slock); /* Remove this pool from its allocator's list of pools. */ pool_reclaim_unregister(pp); - mutex_enter(&pp->pr_alloc->pa_lock); + s = splvm(); + simple_lock(&pp->pr_alloc->pa_slock); TAILQ_REMOVE(&pp->pr_alloc->pa_list, pp, pr_alloc_list); - mutex_exit(&pp->pr_alloc->pa_lock); + simple_unlock(&pp->pr_alloc->pa_slock); + splx(s); - mutex_enter(&pp->pr_lock); + s = splvm(); + simple_lock(&pp->pr_slock); KASSERT(LIST_EMPTY(&pp->pr_cachelist)); @@ -863,7 +862,8 @@ pool_destroy(struct pool *pp) while ((ph = LIST_FIRST(&pp->pr_emptypages)) != NULL) pr_rmpage(pp, ph, &pq); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); + splx(s); pr_pagelist_free(pp, &pq); @@ -871,9 +871,6 @@ pool_destroy(struct pool *pp) if ((pp->pr_roflags & PR_LOGGING) != 0) free(pp->pr_log, M_TEMP); #endif - - cv_destroy(&pp->pr_cv); - mutex_destroy(&pp->pr_lock); } void @@ -893,11 +890,17 @@ static struct pool_item_header * pool_alloc_item_header(struct pool *pp, void *storage, int flags) { struct pool_item_header *ph; + int s; + + LOCK_ASSERT(simple_lock_held(&pp->pr_slock) == 0); if ((pp->pr_roflags & PR_PHINPAGE) != 0) ph = (struct pool_item_header *) ((char *)storage + pp->pr_phoffset); - else + else { + s = splvm(); ph = pool_get(pp->pr_phpool, flags); + splx(s); + } return (ph); } @@ -930,7 +933,7 @@ pool_get(struct pool *pp, int flags) ASSERT_SLEEPABLE(NULL, "pool_get(PR_WAITOK)"); #endif - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pr_enter(pp, file, line); startover: @@ -942,7 +945,7 @@ pool_get(struct pool *pp, int flags) #ifdef DIAGNOSTIC if (__predict_false(pp->pr_nout > pp->pr_hardlimit)) { pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); panic("pool_get: %s: crossed hard limit", pp->pr_wchan); } #endif @@ -954,9 +957,9 @@ pool_get(struct pool *pp, int flags) * and check the hardlimit condition again. */ pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); (*pp->pr_drain_hook)(pp->pr_drain_hook_arg, flags); - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pr_enter(pp, file, line); if (pp->pr_nout < pp->pr_hardlimit) goto startover; @@ -969,7 +972,7 @@ pool_get(struct pool *pp, int flags) */ pp->pr_flags |= PR_WANTED; pr_leave(pp); - cv_wait(&pp->pr_cv, &pp->pr_lock); + ltsleep(pp, PSWP, pp->pr_wchan, 0, &pp->pr_slock); pr_enter(pp, file, line); goto startover; } @@ -985,7 +988,7 @@ pool_get(struct pool *pp, int flags) pp->pr_nfail++; pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); return (NULL); } @@ -1000,7 +1003,7 @@ pool_get(struct pool *pp, int flags) #ifdef DIAGNOSTIC if (pp->pr_nitems != 0) { - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); printf("pool_get: %s: curpage NULL, nitems %u\n", pp->pr_wchan, pp->pr_nitems); panic("pool_get: nitems inconsistent"); @@ -1027,7 +1030,7 @@ pool_get(struct pool *pp, int flags) pp->pr_nfail++; pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); return (NULL); } @@ -1038,7 +1041,7 @@ pool_get(struct pool *pp, int flags) #ifdef DIAGNOSTIC if (__predict_false(ph->ph_nmissing == pp->pr_itemsperpage)) { pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); panic("pool_get: %s: page empty", pp->pr_wchan); } #endif @@ -1050,13 +1053,13 @@ pool_get(struct pool *pp, int flags) v = pi = LIST_FIRST(&ph->ph_itemlist); if (__predict_false(v == NULL)) { pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); panic("pool_get: %s: page empty", pp->pr_wchan); } #ifdef DIAGNOSTIC if (__predict_false(pp->pr_nitems == 0)) { pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); printf("pool_get: %s: items on itemlist, nitems %u\n", pp->pr_wchan, pp->pr_nitems); panic("pool_get: nitems inconsistent"); @@ -1103,7 +1106,7 @@ pool_get(struct pool *pp, int flags) if (__predict_false((pp->pr_roflags & PR_NOTOUCH) == 0 && !LIST_EMPTY(&ph->ph_itemlist))) { pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); panic("pool_get: %s: nmissing inconsistent", pp->pr_wchan); } @@ -1132,7 +1135,7 @@ pool_get(struct pool *pp, int flags) */ } - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); KASSERT((((vaddr_t)v + pp->pr_itemoffset) & (pp->pr_align - 1)) == 0); FREECHECK_OUT(&pp->pr_freecheck, v); return (v); @@ -1147,9 +1150,8 @@ pool_do_put(struct pool *pp, void *v, st struct pool_item *pi = v; struct pool_item_header *ph; - KASSERT(mutex_owned(&pp->pr_lock)); + LOCK_ASSERT(simple_lock_held(&pp->pr_slock)); FREECHECK_IN(&pp->pr_freecheck, v); - LOCKDEBUG_MEM_CHECK(v, pp->pr_size); #ifdef DIAGNOSTIC if (__predict_false(pp->pr_nout == 0)) { @@ -1164,6 +1166,13 @@ pool_do_put(struct pool *pp, void *v, st panic("pool_put: %s: page header missing", pp->pr_wchan); } +#ifdef LOCKDEBUG + /* + * Check if we're freeing a locked simple lock. + */ + simple_lock_freecheck(pi, (char *)pi + pp->pr_size); +#endif + /* * Return to item list. */ @@ -1199,7 +1208,7 @@ pool_do_put(struct pool *pp, void *v, st pp->pr_flags &= ~PR_WANTED; if (ph->ph_nmissing == 0) pp->pr_nidle++; - cv_broadcast(&pp->pr_cv); + wakeup((void *)pp); return; } @@ -1261,7 +1270,7 @@ _pool_put(struct pool *pp, void *v, cons LIST_INIT(&pq); - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pr_enter(pp, file, line); pr_log(pp, v, PRLOG_PUT, file, line); @@ -1269,7 +1278,7 @@ _pool_put(struct pool *pp, void *v, cons pool_do_put(pp, v, &pq); pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); pr_pagelist_free(pp, &pq); } @@ -1283,9 +1292,9 @@ pool_put(struct pool *pp, void *v) LIST_INIT(&pq); - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pool_do_put(pp, v, &pq); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); pr_pagelist_free(pp, &pq); } @@ -1308,7 +1317,7 @@ pool_grow(struct pool *pp, int flags) struct pool_item_header *ph = NULL; char *cp; - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); cp = pool_allocator_alloc(pp, flags); if (__predict_true(cp != NULL)) { ph = pool_alloc_item_header(pp, cp, flags); @@ -1317,11 +1326,11 @@ pool_grow(struct pool *pp, int flags) if (cp != NULL) { pool_allocator_free(pp, cp); } - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); return ENOMEM; } - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pool_prime_page(pp, cp, ph); pp->pr_npagealloc++; return 0; @@ -1336,7 +1345,7 @@ pool_prime(struct pool *pp, int n) int newpages; int error = 0; - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); newpages = roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage; @@ -1351,7 +1360,7 @@ pool_prime(struct pool *pp, int n) if (pp->pr_minpages >= pp->pr_maxpages) pp->pr_maxpages = pp->pr_minpages + 1; /* XXX */ - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); return error; } @@ -1369,7 +1378,7 @@ pool_prime_page(struct pool *pp, void *s const unsigned int ioff = pp->pr_itemoffset; int n; - KASSERT(mutex_owned(&pp->pr_lock)); + LOCK_ASSERT(simple_lock_held(&pp->pr_slock)); #ifdef DIAGNOSTIC if ((pp->pr_roflags & PR_NOALIGN) == 0 && @@ -1484,7 +1493,7 @@ void pool_setlowat(struct pool *pp, int n) { - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pp->pr_minitems = n; pp->pr_minpages = (n == 0) @@ -1500,27 +1509,27 @@ pool_setlowat(struct pool *pp, int n) */ } - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); } void pool_sethiwat(struct pool *pp, int n) { - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pp->pr_maxpages = (n == 0) ? 0 : roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage; - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); } void pool_sethardlimit(struct pool *pp, int n, const char *warnmess, int ratecap) { - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); pp->pr_hardlimit = n; pp->pr_hardlimit_warning = warnmess; @@ -1536,7 +1545,7 @@ pool_sethardlimit(struct pool *pp, int n ? 0 : roundup(n, pp->pr_itemsperpage) / pp->pr_itemsperpage; - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); } /* @@ -1562,7 +1571,7 @@ pool_reclaim(struct pool *pp) (*pp->pr_drain_hook)(pp->pr_drain_hook_arg, PR_NOWAIT); } - if (mutex_tryenter(&pp->pr_lock) == 0) + if (simple_lock_try(&pp->pr_slock) == 0) return (0); pr_enter(pp, file, line); @@ -1602,7 +1611,7 @@ pool_reclaim(struct pool *pp) } pr_leave(pp); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); if (LIST_EMPTY(&pq) && LIST_EMPTY(&pcgl)) return 0; @@ -1625,8 +1634,8 @@ pool_drain(void *arg) int s; pp = NULL; - s = splvm(); /* XXX why? */ - mutex_enter(&pool_head_lock); + s = splvm(); + simple_lock(&pool_head_slock); if (drainpp == NULL) { drainpp = LIST_FIRST(&pool_head); } @@ -1634,7 +1643,7 @@ pool_drain(void *arg) pp = drainpp; drainpp = LIST_NEXT(pp, pr_poollist); } - mutex_exit(&pool_head_lock); + simple_unlock(&pool_head_slock); if (pp) pool_reclaim(pp); splx(s); @@ -1646,14 +1655,18 @@ pool_drain(void *arg) void pool_print(struct pool *pp, const char *modif) { + int s; - if (mutex_tryenter(&pp->pr_lock) == 0) { + s = splvm(); + if (simple_lock_try(&pp->pr_slock) == 0) { printf("pool %s is locked; try again later\n", pp->pr_wchan); + splx(s); return; } pool_print1(pp, modif, printf); - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); + splx(s); } void @@ -1661,10 +1674,10 @@ pool_printall(const char *modif, void (* { struct pool *pp; - if (mutex_tryenter(&pool_head_lock) == 0) { + if (simple_lock_try(&pool_head_slock) == 0) { (*pr)("WARNING: pool_head_slock is locked\n"); } else { - mutex_exit(&pool_head_lock); + simple_unlock(&pool_head_slock); } LIST_FOREACH(pp, &pool_head, pr_poollist) { @@ -1686,14 +1699,14 @@ pool_printit(struct pool *pp, const char * other processors should be paused. We can skip locking * the pool in this case. * - * We do a mutex_tryenter() just to print the lock + * We do a simple_lock_try() just to print the lock * status, however. */ - if (mutex_tryenter(&pp->pr_lock) == 0) + if (simple_lock_try(&pp->pr_slock) == 0) (*pr)("WARNING: pool %s is locked\n", pp->pr_wchan); else - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); pool_print1(pp, modif, pr); } @@ -1892,7 +1905,7 @@ pool_chk(struct pool *pp, const char *la struct pool_item_header *ph; int r = 0; - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); LIST_FOREACH(ph, &pp->pr_emptypages, ph_pagelist) { r = pool_chk_page(pp, label, ph); if (r) { @@ -1913,7 +1926,7 @@ pool_chk(struct pool *pp, const char *la } out: - mutex_exit(&pp->pr_lock); + simple_unlock(&pp->pr_slock); return (r); } @@ -1935,7 +1948,7 @@ pool_cache_init(struct pool_cache *pc, s LIST_INIT(&pc->pc_emptygroups); LIST_INIT(&pc->pc_fullgroups); LIST_INIT(&pc->pc_partgroups); - mutex_init(&pc->pc_lock, MUTEX_DRIVER, pp->pr_ipl); + simple_lock_init(&pc->pc_slock); pc->pc_pool = pp; @@ -1950,12 +1963,9 @@ pool_cache_init(struct pool_cache *pc, s pc->pc_nitems = 0; - if (__predict_true(!cold)) { - mutex_enter(&pp->pr_lock); - LIST_INSERT_HEAD(&pp->pr_cachelist, pc, pc_poollist); - mutex_exit(&pp->pr_lock); - } else - LIST_INSERT_HEAD(&pp->pr_cachelist, pc, pc_poollist); + simple_lock(&pp->pr_slock); + LIST_INSERT_HEAD(&pp->pr_cachelist, pc, pc_poollist); + simple_unlock(&pp->pr_slock); } /* @@ -1972,11 +1982,9 @@ pool_cache_destroy(struct pool_cache *pc pool_cache_invalidate(pc); /* ...and remove it from the pool's cache list. */ - mutex_enter(&pp->pr_lock); + simple_lock(&pp->pr_slock); LIST_REMOVE(pc, pc_poollist); - mutex_exit(&pp->pr_lock); - - mutex_destroy(&pc->pc_lock); + simple_unlock(&pp->pr_slock); } static inline void * @@ -2015,11 +2023,14 @@ static void pcg_grouplist_free(struct pool_cache_grouplist *pcgl) { struct pool_cache_group *pcg; + int s; + s = splvm(); while ((pcg = LIST_FIRST(pcgl)) != NULL) { LIST_REMOVE(pcg, pcg_list); pool_put(&pcgpool, pcg); } + splx(s); } /* @@ -2039,7 +2050,7 @@ pool_cache_get_paddr(struct pool_cache * ASSERT_SLEEPABLE(NULL, "pool_cache_get(PR_WAITOK)"); #endif - mutex_enter(&pc->pc_lock); + simple_lock(&pc->pc_slock); pcg = LIST_FIRST(&pc->pc_partgroups); if (pcg == NULL) { @@ -2058,7 +2069,7 @@ pool_cache_get_paddr(struct pool_cache * * when the object is freed back to the cache. */ pc->pc_misses++; - mutex_exit(&pc->pc_lock); + simple_unlock(&pc->pc_slock); object = pool_get(pc->pc_pool, flags); if (object != NULL && pc->pc_ctor != NULL) { if ((*pc->pc_ctor)(pc->pc_arg, object, flags) != 0) { @@ -2088,7 +2099,7 @@ pool_cache_get_paddr(struct pool_cache * LIST_REMOVE(pcg, pcg_list); LIST_INSERT_HEAD(&pc->pc_emptygroups, pcg, pcg_list); } - mutex_exit(&pc->pc_lock); + simple_unlock(&pc->pc_slock); KASSERT((((vaddr_t)object + pc->pc_pool->pr_itemoffset) & (pc->pc_pool->pr_align - 1)) == 0); @@ -2106,6 +2117,7 @@ void pool_cache_put_paddr(struct pool_cache *pc, void *object, paddr_t pa) { struct pool_cache_group *pcg; + int s; FREECHECK_IN(&pc->pc_freecheck, object); @@ -2113,7 +2125,7 @@ pool_cache_put_paddr(struct pool_cache * goto destruct; } - mutex_enter(&pc->pc_lock); + simple_lock(&pc->pc_slock); pcg = LIST_FIRST(&pc->pc_partgroups); if (pcg == NULL) { @@ -2129,8 +2141,10 @@ pool_cache_put_paddr(struct pool_cache * * No empty groups to free the object to. Attempt to * allocate one. */ - mutex_exit(&pc->pc_lock); + simple_unlock(&pc->pc_slock); + s = splvm(); pcg = pool_get(&pcgpool, PR_NOWAIT); + splx(s); if (pcg == NULL) { destruct: @@ -2142,7 +2156,7 @@ destruct: return; } memset(pcg, 0, sizeof(*pcg)); - mutex_enter(&pc->pc_lock); + simple_lock(&pc->pc_slock); pc->pc_ngroups++; LIST_INSERT_HEAD(&pc->pc_partgroups, pcg, pcg_list); } @@ -2154,7 +2168,7 @@ destruct: LIST_REMOVE(pcg, pcg_list); LIST_INSERT_HEAD(&pc->pc_fullgroups, pcg, pcg_list); } - mutex_exit(&pc->pc_lock); + simple_unlock(&pc->pc_slock); } /* @@ -2187,28 +2201,28 @@ pool_do_cache_invalidate_grouplist(struc struct pool_cache_group *pcg; void *object; - KASSERT(mutex_owned(&pc->pc_lock)); - KASSERT(mutex_owned(&pc->pc_pool->pr_lock)); + LOCK_ASSERT(simple_lock_held(&pc->pc_slock)); + LOCK_ASSERT(simple_lock_held(&pc->pc_pool->pr_slock)); while ((pcg = LIST_FIRST(pcgsl)) != NULL) { pc->pc_ngroups--; LIST_REMOVE(pcg, pcg_list); LIST_INSERT_HEAD(pcgdl, pcg, pcg_list); pc->pc_nitems -= pcg->pcg_avail; - mutex_exit(&pc->pc_pool->pr_lock); - mutex_exit(&pc->pc_lock); + simple_unlock(&pc->pc_pool->pr_slock); + simple_unlock(&pc->pc_slock); while (pcg->pcg_avail != 0) { object = pcg_get(pcg, NULL); if (pc->pc_dtor != NULL) (*pc->pc_dtor)(pc->pc_arg, object); - mutex_enter(&pc->pc_pool->pr_lock); + simple_lock(&pc->pc_pool->pr_slock); pool_do_put(pc->pc_pool, object, pq); - mutex_exit(&pc->pc_pool->pr_lock); + simple_unlock(&pc->pc_pool->pr_slock); } - mutex_enter(&pc->pc_lock); - mutex_enter(&pc->pc_pool->pr_lock); + simple_lock(&pc->pc_slock); + simple_lock(&pc->pc_pool->pr_slock); } } @@ -2217,8 +2231,8 @@ pool_do_cache_invalidate(struct pool_cac struct pool_cache_grouplist *pcgl) { - KASSERT(mutex_owned(&pc->pc_lock)); - KASSERT(mutex_owned(&pc->pc_pool->pr_lock)); + LOCK_ASSERT(simple_lock_held(&pc->pc_slock)); + LOCK_ASSERT(simple_lock_held(&pc->pc_pool->pr_slock)); pool_do_cache_invalidate_grouplist(&pc->pc_fullgroups, pc, pq, pcgl); pool_do_cache_invalidate_grouplist(&pc->pc_partgroups, pc, pq, pcgl); @@ -2243,13 +2257,13 @@ pool_cache_invalidate(struct pool_cache LIST_INIT(&pq); LIST_INIT(&pcgl); - mutex_enter(&pc->pc_lock); - mutex_enter(&pc->pc_pool->pr_lock); + simple_lock(&pc->pc_slock); + simple_lock(&pc->pc_pool->pr_slock); pool_do_cache_invalidate(pc, &pq, &pcgl); - mutex_exit(&pc->pc_pool->pr_lock); - mutex_exit(&pc->pc_lock); + simple_unlock(&pc->pc_pool->pr_slock); + simple_unlock(&pc->pc_slock); pr_pagelist_free(pc->pc_pool, &pq); pcg_grouplist_free(&pcgl); @@ -2271,12 +2285,12 @@ pool_cache_reclaim(struct pool_cache *pc * to use trylock. If we can't lock the pool_cache, it's not really * a big deal here. */ - if (mutex_tryenter(&pc->pc_lock) == 0) + if (simple_lock_try(&pc->pc_slock) == 0) return; pool_do_cache_invalidate(pc, pq, pcgl); - mutex_exit(&pc->pc_lock); + simple_unlock(&pc->pc_slock); } /* @@ -2346,6 +2360,8 @@ pool_allocator_alloc(struct pool *pp, in struct pool_allocator *pa = pp->pr_alloc; void *res; + LOCK_ASSERT(!simple_lock_held(&pp->pr_slock)); + res = (*pa->pa_alloc)(pp, flags); if (res == NULL && (flags & PR_WAITOK) == 0) { /* @@ -2366,6 +2382,8 @@ pool_allocator_free(struct pool *pp, voi { struct pool_allocator *pa = pp->pr_alloc; + LOCK_ASSERT(!simple_lock_held(&pp->pr_slock)); + (*pa->pa_free)(pp, v); } @@ -2404,13 +2422,21 @@ pool_page_free_meta(struct pool *pp, voi void * pool_subpage_alloc(struct pool *pp, int flags) { - return pool_get(&psppool, flags); + void *v; + int s; + s = splvm(); + v = pool_get(&psppool, flags); + splx(s); + return v; } void pool_subpage_free(struct pool *pp, void *v) { + int s; + s = splvm(); pool_put(&psppool, v); + splx(s); } /* We don't provide a real nointr allocator. Maybe later. */