version 1.30.2.3, 2000/12/08 09:13:56 |
version 1.30.2.4, 2000/12/13 15:50:21 |
|
|
pool_print1(struct pool *pp, const char *modif, void (*pr)(const char *, ...)) |
pool_print1(struct pool *pp, const char *modif, void (*pr)(const char *, ...)) |
{ |
{ |
struct pool_item_header *ph; |
struct pool_item_header *ph; |
|
struct pool_cache *pc; |
|
struct pool_cache_group *pcg; |
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
struct pool_item *pi; |
struct pool_item *pi; |
#endif |
#endif |
int print_log = 0, print_pagelist = 0; |
int i, print_log = 0, print_pagelist = 0, print_cache = 0; |
char c; |
char c; |
|
|
while ((c = *modif++) != '\0') { |
while ((c = *modif++) != '\0') { |
Line 1388 pool_print1(struct pool *pp, const char |
|
Line 1390 pool_print1(struct pool *pp, const char |
|
print_log = 1; |
print_log = 1; |
if (c == 'p') |
if (c == 'p') |
print_pagelist = 1; |
print_pagelist = 1; |
|
if (c == 'c') |
|
print_cache = 1; |
modif++; |
modif++; |
} |
} |
|
|
Line 1444 pool_print1(struct pool *pp, const char |
|
Line 1448 pool_print1(struct pool *pp, const char |
|
|
|
skip_log: |
skip_log: |
|
|
|
if (print_cache == 0) |
|
goto skip_cache; |
|
|
|
for (pc = TAILQ_FIRST(&pp->pr_cachelist); pc != NULL; |
|
pc = TAILQ_NEXT(pc, pc_poollist)) { |
|
(*pr)("\tcache %p: allocfrom %p freeto %p\n", pc, |
|
pc->pc_allocfrom, pc->pc_freeto); |
|
(*pr)("\t hits %lu misses %lu ngroups %lu nitems %lu\n", |
|
pc->pc_hits, pc->pc_misses, pc->pc_ngroups, pc->pc_nitems); |
|
for (pcg = TAILQ_FIRST(&pc->pc_grouplist); pcg != NULL; |
|
pcg = TAILQ_NEXT(pcg, pcg_list)) { |
|
(*pr)("\t\tgroup %p: avail %d\n", pcg, pcg->pcg_avail); |
|
for (i = 0; i < PCG_NOBJECTS; i++) |
|
(*pr)("\t\t\t%p\n", pcg->pcg_objects[i]); |
|
} |
|
} |
|
|
|
skip_cache: |
|
|
pr_enter_check(pp, pr); |
pr_enter_check(pp, pr); |
} |
} |
|
|
Line 1536 pool_cache_init(struct pool_cache *pc, s |
|
Line 1559 pool_cache_init(struct pool_cache *pc, s |
|
pc->pc_dtor = dtor; |
pc->pc_dtor = dtor; |
pc->pc_arg = arg; |
pc->pc_arg = arg; |
|
|
|
pc->pc_hits = 0; |
|
pc->pc_misses = 0; |
|
|
|
pc->pc_ngroups = 0; |
|
|
|
pc->pc_nitems = 0; |
|
|
simple_lock(&pp->pr_slock); |
simple_lock(&pp->pr_slock); |
TAILQ_INSERT_TAIL(&pp->pr_cachelist, pc, pc_poollist); |
TAILQ_INSERT_TAIL(&pp->pr_cachelist, pc, pc_poollist); |
simple_unlock(&pp->pr_slock); |
simple_unlock(&pp->pr_slock); |
Line 1567 pcg_get(struct pool_cache_group *pcg) |
|
Line 1597 pcg_get(struct pool_cache_group *pcg) |
|
u_int idx; |
u_int idx; |
|
|
KASSERT(pcg->pcg_avail <= PCG_NOBJECTS); |
KASSERT(pcg->pcg_avail <= PCG_NOBJECTS); |
|
KASSERT(pcg->pcg_avail != 0); |
idx = --pcg->pcg_avail; |
idx = --pcg->pcg_avail; |
|
|
KASSERT(pcg->pcg_objects[idx] != NULL); |
KASSERT(pcg->pcg_objects[idx] != NULL); |
Line 1616 pool_cache_get(struct pool_cache *pc, in |
|
Line 1647 pool_cache_get(struct pool_cache *pc, in |
|
* the caller. We will allocate a group, if necessary, |
* the caller. We will allocate a group, if necessary, |
* when the object is freed back to the cache. |
* when the object is freed back to the cache. |
*/ |
*/ |
|
pc->pc_misses++; |
simple_unlock(&pc->pc_slock); |
simple_unlock(&pc->pc_slock); |
object = pool_get(pc->pc_pool, flags); |
object = pool_get(pc->pc_pool, flags); |
if (object != NULL && pc->pc_ctor != NULL) { |
if (object != NULL && pc->pc_ctor != NULL) { |
Line 1628 pool_cache_get(struct pool_cache *pc, in |
|
Line 1660 pool_cache_get(struct pool_cache *pc, in |
|
} |
} |
|
|
have_group: |
have_group: |
|
pc->pc_hits++; |
|
pc->pc_nitems--; |
object = pcg_get(pcg); |
object = pcg_get(pcg); |
|
|
if (pcg->pcg_avail == 0) |
if (pcg->pcg_avail == 0) |
pc->pc_allocfrom = NULL; |
pc->pc_allocfrom = NULL; |
|
|
simple_unlock(&pc->pc_slock); |
simple_unlock(&pc->pc_slock); |
|
|
return (object); |
return (object); |
Line 1661 pool_cache_put(struct pool_cache *pc, vo |
|
Line 1695 pool_cache_put(struct pool_cache *pc, vo |
|
|
|
/* |
/* |
* No empty groups to free the object to. Attempt to |
* No empty groups to free the object to. Attempt to |
* allocate one. We don't unlock the cache here, since |
* allocate one. |
* we never block. |
|
*/ |
*/ |
|
simple_unlock(&pc->pc_slock); |
pcg = pool_get(&pcgpool, PR_NOWAIT); |
pcg = pool_get(&pcgpool, PR_NOWAIT); |
if (pcg != NULL) { |
if (pcg != NULL) { |
memset(pcg, 0, sizeof(*pcg)); |
memset(pcg, 0, sizeof(*pcg)); |
|
simple_lock(&pc->pc_slock); |
|
pc->pc_ngroups++; |
TAILQ_INSERT_TAIL(&pc->pc_grouplist, pcg, pcg_list); |
TAILQ_INSERT_TAIL(&pc->pc_grouplist, pcg, pcg_list); |
pc->pc_freeto = pcg; |
if (pc->pc_freeto == NULL) |
|
pc->pc_freeto = pcg; |
goto have_group; |
goto have_group; |
} |
} |
|
|
simple_unlock(&pc->pc_slock); |
|
|
|
/* |
/* |
* Unable to allocate a cache group; destruct the object |
* Unable to allocate a cache group; destruct the object |
* and free it back to the pool. |
* and free it back to the pool. |
Line 1685 pool_cache_put(struct pool_cache *pc, vo |
|
Line 1720 pool_cache_put(struct pool_cache *pc, vo |
|
} |
} |
|
|
have_group: |
have_group: |
|
pc->pc_nitems++; |
pcg_put(pcg, object); |
pcg_put(pcg, object); |
|
|
if (pcg->pcg_avail == PCG_NOBJECTS) |
if (pcg->pcg_avail == PCG_NOBJECTS) |
Line 1710 pool_cache_do_invalidate(struct pool_cac |
|
Line 1746 pool_cache_do_invalidate(struct pool_cac |
|
pcg = npcg) { |
pcg = npcg) { |
npcg = TAILQ_NEXT(pcg, pcg_list); |
npcg = TAILQ_NEXT(pcg, pcg_list); |
while (pcg->pcg_avail != 0) { |
while (pcg->pcg_avail != 0) { |
|
pc->pc_nitems--; |
object = pcg_get(pcg); |
object = pcg_get(pcg); |
|
if (pcg->pcg_avail == 0 && pc->pc_allocfrom == pcg) |
|
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, __FILE__, __LINE__); |
(*putit)(pc->pc_pool, object, __FILE__, __LINE__); |
} |
} |
if (free_groups) { |
if (free_groups) { |
|
pc->pc_ngroups--; |
TAILQ_REMOVE(&pc->pc_grouplist, pcg, pcg_list); |
TAILQ_REMOVE(&pc->pc_grouplist, pcg, pcg_list); |
|
if (pc->pc_freeto == pcg) |
|
pc->pc_freeto = NULL; |
pool_put(&pcgpool, pcg); |
pool_put(&pcgpool, pcg); |
} |
} |
} |
} |
|
|
pool_cache_reclaim(struct pool_cache *pc) |
pool_cache_reclaim(struct pool_cache *pc) |
{ |
{ |
|
|
/* |
simple_lock(&pc->pc_slock); |
* We're locking in the opposite order (pool already |
|
* locked in pool_reclaim()), so use a try-lock instead. |
|
*/ |
|
|
|
if (simple_lock_try(&pc->pc_slock) == 0) |
|
return; |
|
pool_cache_do_invalidate(pc, 1, pool_do_put); |
pool_cache_do_invalidate(pc, 1, pool_do_put); |
simple_unlock(&pc->pc_slock); |
simple_unlock(&pc->pc_slock); |
} |
} |