version 1.99, 2005/01/01 21:09:56 |
version 1.99.8.1, 2005/06/18 11:13:12 |
Line 174 struct pool_item { |
|
Line 174 struct pool_item { |
|
/* The cache group pool. */ |
/* The cache group pool. */ |
static struct pool pcgpool; |
static struct pool pcgpool; |
|
|
static void pool_cache_reclaim(struct pool_cache *); |
static void pool_cache_reclaim(struct pool_cache *, struct pool_pagelist *); |
|
|
static int pool_catchup(struct pool *); |
static int pool_catchup(struct pool *); |
static void pool_prime_page(struct pool *, caddr_t, |
static void pool_prime_page(struct pool *, caddr_t, |
Line 384 pr_find_pagehead(struct pool *pp, caddr_ |
|
Line 384 pr_find_pagehead(struct pool *pp, caddr_ |
|
return ph; |
return ph; |
} |
} |
|
|
|
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) { |
|
s = splvm(); |
|
pool_put(pp->pr_phpool, ph); |
|
splx(s); |
|
} |
|
} |
|
} |
|
|
/* |
/* |
* Remove a page from the pool. |
* Remove a page from the pool. |
*/ |
*/ |
Line 391 static __inline void |
|
Line 408 static __inline void |
|
pr_rmpage(struct pool *pp, struct pool_item_header *ph, |
pr_rmpage(struct pool *pp, struct pool_item_header *ph, |
struct pool_pagelist *pq) |
struct pool_pagelist *pq) |
{ |
{ |
int s; |
|
|
|
LOCK_ASSERT(!simple_lock_held(&pp->pr_slock) || pq != NULL); |
LOCK_ASSERT(simple_lock_held(&pp->pr_slock)); |
|
|
/* |
/* |
* If the page was idle, decrement the idle page count. |
* If the page was idle, decrement the idle page count. |
Line 411 pr_rmpage(struct pool *pp, struct pool_i |
|
Line 427 pr_rmpage(struct pool *pp, struct pool_i |
|
pp->pr_nitems -= pp->pr_itemsperpage; |
pp->pr_nitems -= pp->pr_itemsperpage; |
|
|
/* |
/* |
* Unlink a page from the pool and release it (or queue it for release). |
* Unlink the page from the pool and queue it for release. |
*/ |
*/ |
LIST_REMOVE(ph, ph_pagelist); |
LIST_REMOVE(ph, ph_pagelist); |
if ((pp->pr_roflags & PR_PHINPAGE) == 0) |
if ((pp->pr_roflags & PR_PHINPAGE) == 0) |
SPLAY_REMOVE(phtree, &pp->pr_phtree, ph); |
SPLAY_REMOVE(phtree, &pp->pr_phtree, ph); |
if (pq) { |
LIST_INSERT_HEAD(pq, ph, ph_pagelist); |
LIST_INSERT_HEAD(pq, ph, ph_pagelist); |
|
} else { |
|
pool_allocator_free(pp, ph->ph_page); |
|
if ((pp->pr_roflags & PR_PHINPAGE) == 0) { |
|
s = splvm(); |
|
pool_put(pp->pr_phpool, ph); |
|
splx(s); |
|
} |
|
} |
|
pp->pr_npages--; |
pp->pr_npages--; |
pp->pr_npagefree++; |
pp->pr_npagefree++; |
|
|
Line 696 pool_init(struct pool *pp, size_t size, |
|
Line 704 pool_init(struct pool *pp, size_t size, |
|
void |
void |
pool_destroy(struct pool *pp) |
pool_destroy(struct pool *pp) |
{ |
{ |
|
struct pool_pagelist pq; |
struct pool_item_header *ph; |
struct pool_item_header *ph; |
struct pool_cache *pc; |
|
int s; |
int s; |
|
|
/* Locking order: pool_allocator -> pool */ |
/* Remove from global pool list */ |
|
simple_lock(&pool_head_slock); |
|
TAILQ_REMOVE(&pool_head, pp, pr_poollist); |
|
if (drainpp == pp) |
|
drainpp = NULL; |
|
simple_unlock(&pool_head_slock); |
|
|
|
/* Remove this pool from its allocator's list of pools. */ |
s = splvm(); |
s = splvm(); |
simple_lock(&pp->pr_alloc->pa_slock); |
simple_lock(&pp->pr_alloc->pa_slock); |
TAILQ_REMOVE(&pp->pr_alloc->pa_list, pp, pr_alloc_list); |
TAILQ_REMOVE(&pp->pr_alloc->pa_list, pp, pr_alloc_list); |
simple_unlock(&pp->pr_alloc->pa_slock); |
simple_unlock(&pp->pr_alloc->pa_slock); |
splx(s); |
splx(s); |
|
|
/* Destroy all caches for this pool. */ |
s = splvm(); |
while ((pc = TAILQ_FIRST(&pp->pr_cachelist)) != NULL) |
simple_lock(&pp->pr_slock); |
pool_cache_destroy(pc); |
|
|
KASSERT(TAILQ_EMPTY(&pp->pr_cachelist)); |
|
|
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
if (pp->pr_nout != 0) { |
if (pp->pr_nout != 0) { |
Line 719 pool_destroy(struct pool *pp) |
|
Line 735 pool_destroy(struct pool *pp) |
|
} |
} |
#endif |
#endif |
|
|
/* Remove all pages */ |
|
while ((ph = LIST_FIRST(&pp->pr_emptypages)) != NULL) |
|
pr_rmpage(pp, ph, NULL); |
|
KASSERT(LIST_EMPTY(&pp->pr_fullpages)); |
KASSERT(LIST_EMPTY(&pp->pr_fullpages)); |
KASSERT(LIST_EMPTY(&pp->pr_partpages)); |
KASSERT(LIST_EMPTY(&pp->pr_partpages)); |
|
|
/* Remove from global pool list */ |
/* Remove all pages */ |
simple_lock(&pool_head_slock); |
LIST_INIT(&pq); |
TAILQ_REMOVE(&pool_head, pp, pr_poollist); |
while ((ph = LIST_FIRST(&pp->pr_emptypages)) != NULL) |
if (drainpp == pp) { |
pr_rmpage(pp, ph, &pq); |
drainpp = NULL; |
|
} |
simple_unlock(&pp->pr_slock); |
simple_unlock(&pool_head_slock); |
splx(s); |
|
|
|
pr_pagelist_free(pp, &pq); |
|
|
#ifdef POOL_DIAGNOSTIC |
#ifdef POOL_DIAGNOSTIC |
if ((pp->pr_roflags & PR_LOGGING) != 0) |
if ((pp->pr_roflags & PR_LOGGING) != 0) |
Line 1037 pool_get(struct pool *pp, int flags) |
|
Line 1052 pool_get(struct pool *pp, int flags) |
|
* Internal version of pool_put(). Pool is already locked/entered. |
* Internal version of pool_put(). Pool is already locked/entered. |
*/ |
*/ |
static void |
static void |
pool_do_put(struct pool *pp, void *v) |
pool_do_put(struct pool *pp, void *v, struct pool_pagelist *pq) |
{ |
{ |
struct pool_item *pi = v; |
struct pool_item *pi = v; |
struct pool_item_header *ph; |
struct pool_item_header *ph; |
Line 1125 pool_do_put(struct pool *pp, void *v) |
|
Line 1140 pool_do_put(struct pool *pp, void *v) |
|
if (pp->pr_npages > pp->pr_minpages && |
if (pp->pr_npages > pp->pr_minpages && |
(pp->pr_npages > pp->pr_maxpages || |
(pp->pr_npages > pp->pr_maxpages || |
(pp->pr_alloc->pa_flags & PA_WANT) != 0)) { |
(pp->pr_alloc->pa_flags & PA_WANT) != 0)) { |
simple_unlock(&pp->pr_slock); |
pr_rmpage(pp, ph, pq); |
pr_rmpage(pp, ph, NULL); |
|
simple_lock(&pp->pr_slock); |
|
} else { |
} else { |
LIST_REMOVE(ph, ph_pagelist); |
LIST_REMOVE(ph, ph_pagelist); |
LIST_INSERT_HEAD(&pp->pr_emptypages, ph, ph_pagelist); |
LIST_INSERT_HEAD(&pp->pr_emptypages, ph, ph_pagelist); |
Line 1165 pool_do_put(struct pool *pp, void *v) |
|
Line 1178 pool_do_put(struct pool *pp, void *v) |
|
void |
void |
_pool_put(struct pool *pp, void *v, const char *file, long line) |
_pool_put(struct pool *pp, void *v, const char *file, long line) |
{ |
{ |
|
struct pool_pagelist pq; |
|
|
|
LIST_INIT(&pq); |
|
|
simple_lock(&pp->pr_slock); |
simple_lock(&pp->pr_slock); |
pr_enter(pp, file, line); |
pr_enter(pp, file, line); |
|
|
pr_log(pp, v, PRLOG_PUT, file, line); |
pr_log(pp, v, PRLOG_PUT, file, line); |
|
|
pool_do_put(pp, v); |
pool_do_put(pp, v, &pq); |
|
|
pr_leave(pp); |
pr_leave(pp); |
simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
|
|
|
if (! LIST_EMPTY(&pq)) |
|
pr_pagelist_free(pp, &pq); |
} |
} |
#undef pool_put |
#undef pool_put |
#endif /* POOL_DIAGNOSTIC */ |
#endif /* POOL_DIAGNOSTIC */ |
Line 1182 _pool_put(struct pool *pp, void *v, cons |
|
Line 1201 _pool_put(struct pool *pp, void *v, cons |
|
void |
void |
pool_put(struct pool *pp, void *v) |
pool_put(struct pool *pp, void *v) |
{ |
{ |
|
struct pool_pagelist pq; |
|
|
simple_lock(&pp->pr_slock); |
LIST_INIT(&pq); |
|
|
pool_do_put(pp, v); |
|
|
|
|
simple_lock(&pp->pr_slock); |
|
pool_do_put(pp, v, &pq); |
simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
|
|
|
if (! LIST_EMPTY(&pq)) |
|
pr_pagelist_free(pp, &pq); |
} |
} |
|
|
#ifdef POOL_DIAGNOSTIC |
#ifdef POOL_DIAGNOSTIC |
Line 1469 pool_reclaim(struct pool *pp) |
|
Line 1492 pool_reclaim(struct pool *pp) |
|
* Reclaim items from the pool's caches. |
* Reclaim items from the pool's caches. |
*/ |
*/ |
TAILQ_FOREACH(pc, &pp->pr_cachelist, pc_poollist) |
TAILQ_FOREACH(pc, &pp->pr_cachelist, pc_poollist) |
pool_cache_reclaim(pc); |
pool_cache_reclaim(pc, &pq); |
|
|
s = splclock(); |
s = splclock(); |
curtime = mono_time; |
curtime = mono_time; |
Line 1503 pool_reclaim(struct pool *pp) |
|
Line 1526 pool_reclaim(struct pool *pp) |
|
if (LIST_EMPTY(&pq)) |
if (LIST_EMPTY(&pq)) |
return (0); |
return (0); |
|
|
while ((ph = LIST_FIRST(&pq)) != NULL) { |
pr_pagelist_free(pp, &pq); |
LIST_REMOVE(ph, ph_pagelist); |
|
pool_allocator_free(pp, ph->ph_page); |
|
if (pp->pr_roflags & PR_PHINPAGE) { |
|
continue; |
|
} |
|
s = splvm(); |
|
pool_put(pp->pr_phpool, ph); |
|
splx(s); |
|
} |
|
|
|
return (1); |
return (1); |
} |
} |
|
|
Line 2024 pool_cache_destruct_object(struct pool_c |
|
Line 2037 pool_cache_destruct_object(struct pool_c |
|
} |
} |
|
|
/* |
/* |
* pool_cache_do_invalidate: |
* pool_cache_invalidate: |
* |
* |
* This internal function implements pool_cache_invalidate() and |
* Invalidate a pool cache (destruct and release all of the |
* pool_cache_reclaim(). |
* cached objects). |
*/ |
*/ |
static void |
void |
pool_cache_do_invalidate(struct pool_cache *pc, int free_groups, |
pool_cache_invalidate(struct pool_cache *pc) |
void (*putit)(struct pool *, void *)) |
|
{ |
{ |
|
struct pool_pagelist pq; |
struct pool_cache_group *pcg, *npcg; |
struct pool_cache_group *pcg, *npcg; |
void *object; |
void *object; |
int s; |
|
|
LIST_INIT(&pq); |
|
|
|
simple_lock(&pc->pc_slock); |
|
simple_lock(&pc->pc_pool->pr_slock); |
|
|
for (pcg = TAILQ_FIRST(&pc->pc_grouplist); pcg != NULL; |
for (pcg = TAILQ_FIRST(&pc->pc_grouplist); pcg != NULL; |
pcg = npcg) { |
pcg = npcg) { |
Line 2047 pool_cache_do_invalidate(struct pool_cac |
|
Line 2064 pool_cache_do_invalidate(struct pool_cac |
|
pc->pc_allocfrom = NULL; |
pc->pc_allocfrom = NULL; |
if (pc->pc_dtor != NULL) |
if (pc->pc_dtor != NULL) |
(*pc->pc_dtor)(pc->pc_arg, object); |
(*pc->pc_dtor)(pc->pc_arg, object); |
(*putit)(pc->pc_pool, object); |
pool_do_put(pc->pc_pool, object, &pq); |
} |
|
if (free_groups) { |
|
pc->pc_ngroups--; |
|
TAILQ_REMOVE(&pc->pc_grouplist, pcg, pcg_list); |
|
if (pc->pc_freeto == pcg) |
|
pc->pc_freeto = NULL; |
|
s = splvm(); |
|
pool_put(&pcgpool, pcg); |
|
splx(s); |
|
} |
} |
} |
} |
} |
|
|
|
/* |
|
* pool_cache_invalidate: |
|
* |
|
* Invalidate a pool cache (destruct and release all of the |
|
* cached objects). |
|
*/ |
|
void |
|
pool_cache_invalidate(struct pool_cache *pc) |
|
{ |
|
|
|
simple_lock(&pc->pc_slock); |
simple_unlock(&pc->pc_pool->pr_slock); |
pool_cache_do_invalidate(pc, 0, pool_put); |
|
simple_unlock(&pc->pc_slock); |
simple_unlock(&pc->pc_slock); |
|
|
|
if (! LIST_EMPTY(&pq)) |
|
pr_pagelist_free(pc->pc_pool, &pq); |
} |
} |
|
|
/* |
/* |
Line 2082 pool_cache_invalidate(struct pool_cache |
|
Line 2081 pool_cache_invalidate(struct pool_cache |
|
* Reclaim a pool cache for pool_reclaim(). |
* Reclaim a pool cache for pool_reclaim(). |
*/ |
*/ |
static void |
static void |
pool_cache_reclaim(struct pool_cache *pc) |
pool_cache_reclaim(struct pool_cache *pc, struct pool_pagelist *pq) |
{ |
{ |
|
struct pool_cache_group *pcg, *npcg; |
|
void *object; |
|
int s; |
|
|
|
/* |
|
* We're locking in the wrong order (normally pool_cache -> pool, |
|
* but the pool is already locked when we get here), so we have |
|
* to use trylock. If we can't lock the pool_cache, it's not really |
|
* a big deal here. |
|
*/ |
|
if (simple_lock_try(&pc->pc_slock) == 0) |
|
return; |
|
|
|
for (pcg = TAILQ_FIRST(&pc->pc_grouplist); pcg != NULL; |
|
pcg = npcg) { |
|
npcg = TAILQ_NEXT(pcg, pcg_list); |
|
while (pcg->pcg_avail != 0) { |
|
pc->pc_nitems--; |
|
object = pcg_get(pcg, NULL); |
|
if (pcg->pcg_avail == 0 && pc->pc_allocfrom == pcg) |
|
pc->pc_allocfrom = NULL; |
|
if (pc->pc_dtor != NULL) |
|
(*pc->pc_dtor)(pc->pc_arg, object); |
|
pool_do_put(pc->pc_pool, object, pq); |
|
} |
|
pc->pc_ngroups--; |
|
TAILQ_REMOVE(&pc->pc_grouplist, pcg, pcg_list); |
|
if (pc->pc_freeto == pcg) |
|
pc->pc_freeto = NULL; |
|
s = splvm(); |
|
pool_put(&pcgpool, pcg); |
|
splx(s); |
|
} |
|
|
simple_lock(&pc->pc_slock); |
|
pool_cache_do_invalidate(pc, 1, pool_do_put); |
|
simple_unlock(&pc->pc_slock); |
simple_unlock(&pc->pc_slock); |
} |
} |
|
|