version 1.30.2.5, 2001/01/18 09:23:45 |
version 1.52, 2001/05/09 23:46:03 |
Line 145 struct pool_cache_group { |
|
Line 145 struct pool_cache_group { |
|
static void pool_cache_reclaim(struct pool_cache *); |
static void pool_cache_reclaim(struct pool_cache *); |
|
|
static int pool_catchup(struct pool *); |
static int pool_catchup(struct pool *); |
static void pool_prime_page(struct pool *, caddr_t); |
static int pool_prime_page(struct pool *, caddr_t, int); |
static void *pool_page_alloc(unsigned long, int, int); |
static void *pool_page_alloc(unsigned long, int, int); |
static void pool_page_free(void *, unsigned long, int); |
static void pool_page_free(void *, unsigned long, int); |
|
|
Line 153 static void pool_print1(struct pool *, c |
|
Line 153 static void pool_print1(struct pool *, c |
|
void (*)(const char *, ...)); |
void (*)(const char *, ...)); |
|
|
/* |
/* |
* Pool log entry. An array of these is allocated in pool_create(). |
* Pool log entry. An array of these is allocated in pool_init(). |
*/ |
*/ |
struct pool_log { |
struct pool_log { |
const char *pl_file; |
const char *pl_file; |
Line 344 pr_rmpage(struct pool *pp, struct pool_i |
|
Line 344 pr_rmpage(struct pool *pp, struct pool_i |
|
} |
} |
|
|
/* |
/* |
* Allocate and initialize a pool. |
|
*/ |
|
struct pool * |
|
pool_create(size_t size, u_int align, u_int ioff, int nitems, |
|
const char *wchan, size_t pagesz, |
|
void *(*alloc)(unsigned long, int, int), |
|
void (*release)(void *, unsigned long, int), |
|
int mtype) |
|
{ |
|
struct pool *pp; |
|
int flags; |
|
|
|
pp = (struct pool *)malloc(sizeof(*pp), M_POOL, M_NOWAIT); |
|
if (pp == NULL) |
|
return (NULL); |
|
|
|
flags = PR_FREEHEADER; |
|
pool_init(pp, size, align, ioff, flags, wchan, pagesz, |
|
alloc, release, mtype); |
|
|
|
if (nitems != 0) { |
|
if (pool_prime(pp, nitems, NULL) != 0) { |
|
pool_destroy(pp); |
|
return (NULL); |
|
} |
|
} |
|
|
|
return (pp); |
|
} |
|
|
|
/* |
|
* Initialize the given pool resource structure. |
* Initialize the given pool resource structure. |
* |
* |
* We export this routine to allow other kernel parts to declare |
* We export this routine to allow other kernel parts to declare |
Line 714 _pool_get(struct pool *pp, int flags, co |
|
Line 683 _pool_get(struct pool *pp, int flags, co |
|
} |
} |
|
|
/* We have more memory; add it to the pool */ |
/* We have more memory; add it to the pool */ |
|
if (pool_prime_page(pp, v, flags & PR_WAITOK) != 0) { |
|
/* |
|
* Probably, we don't allowed to wait and |
|
* couldn't allocate a page header. |
|
*/ |
|
(*pp->pr_free)(v, pp->pr_pagesz, pp->pr_mtype); |
|
pp->pr_nfail++; |
|
pr_leave(pp); |
|
simple_unlock(&pp->pr_slock); |
|
return (NULL); |
|
} |
pp->pr_npagealloc++; |
pp->pr_npagealloc++; |
pool_prime_page(pp, v); |
|
|
|
/* Start the allocation process over. */ |
/* Start the allocation process over. */ |
goto startover; |
goto startover; |
Line 956 _pool_put(struct pool *pp, void *v, cons |
|
Line 935 _pool_put(struct pool *pp, void *v, cons |
|
} |
} |
|
|
/* |
/* |
* Add N items to the pool. |
|
*/ |
|
int |
|
pool_prime(struct pool *pp, int n, caddr_t storage) |
|
{ |
|
caddr_t cp; |
|
int newnitems, newpages; |
|
|
|
#ifdef DIAGNOSTIC |
|
if (__predict_false(storage && !(pp->pr_roflags & PR_STATIC))) |
|
panic("pool_prime: static"); |
|
/* !storage && static caught below */ |
|
#endif |
|
|
|
simple_lock(&pp->pr_slock); |
|
|
|
newnitems = pp->pr_minitems + n; |
|
newpages = |
|
roundup(newnitems, pp->pr_itemsperpage) / pp->pr_itemsperpage |
|
- pp->pr_minpages; |
|
|
|
while (newpages-- > 0) { |
|
if (pp->pr_roflags & PR_STATIC) { |
|
cp = storage; |
|
storage += pp->pr_pagesz; |
|
} else { |
|
simple_unlock(&pp->pr_slock); |
|
cp = (*pp->pr_alloc)(pp->pr_pagesz, 0, pp->pr_mtype); |
|
simple_lock(&pp->pr_slock); |
|
} |
|
|
|
if (cp == NULL) { |
|
simple_unlock(&pp->pr_slock); |
|
return (ENOMEM); |
|
} |
|
|
|
pp->pr_npagealloc++; |
|
pool_prime_page(pp, cp); |
|
pp->pr_minpages++; |
|
} |
|
|
|
pp->pr_minitems = newnitems; |
|
|
|
if (pp->pr_minpages >= pp->pr_maxpages) |
|
pp->pr_maxpages = pp->pr_minpages + 1; /* XXX */ |
|
|
|
simple_unlock(&pp->pr_slock); |
|
return (0); |
|
} |
|
|
|
/* |
|
* Add a page worth of items to the pool. |
* Add a page worth of items to the pool. |
* |
* |
* Note, we must be called with the pool descriptor LOCKED. |
* Note, we must be called with the pool descriptor LOCKED. |
*/ |
*/ |
static void |
static int |
pool_prime_page(struct pool *pp, caddr_t storage) |
pool_prime_page(struct pool *pp, caddr_t storage, int flags) |
{ |
{ |
struct pool_item *pi; |
struct pool_item *pi; |
struct pool_item_header *ph; |
struct pool_item_header *ph; |
Line 1028 pool_prime_page(struct pool *pp, caddr_t |
|
Line 956 pool_prime_page(struct pool *pp, caddr_t |
|
ph = (struct pool_item_header *)(cp + pp->pr_phoffset); |
ph = (struct pool_item_header *)(cp + pp->pr_phoffset); |
} else { |
} else { |
s = splhigh(); |
s = splhigh(); |
ph = pool_get(&phpool, PR_URGENT); |
ph = pool_get(&phpool, flags); |
splx(s); |
splx(s); |
|
if (ph == NULL) |
|
return (ENOMEM); |
LIST_INSERT_HEAD(&pp->pr_hashtab[PR_HASH_INDEX(pp, cp)], |
LIST_INSERT_HEAD(&pp->pr_hashtab[PR_HASH_INDEX(pp, cp)], |
ph, ph_hashlist); |
ph, ph_hashlist); |
} |
} |
Line 1083 pool_prime_page(struct pool *pp, caddr_t |
|
Line 1013 pool_prime_page(struct pool *pp, caddr_t |
|
|
|
if (++pp->pr_npages > pp->pr_hiwat) |
if (++pp->pr_npages > pp->pr_hiwat) |
pp->pr_hiwat = pp->pr_npages; |
pp->pr_hiwat = pp->pr_npages; |
|
|
|
return (0); |
} |
} |
|
|
/* |
/* |
* Like pool_prime(), except this is used by pool_get() when nitems |
* Used by pool_get() when nitems drops below the low water mark. This |
* drops below the low water mark. This is used to catch up nitmes |
* is used to catch up nitmes with the low water mark. |
* with the low water mark. |
|
* |
* |
* Note 1, we never wait for memory here, we let the caller decide what to do. |
* Note 1, we never wait for memory here, we let the caller decide what to do. |
* |
* |
Line 1129 pool_catchup(struct pool *pp) |
|
Line 1060 pool_catchup(struct pool *pp) |
|
error = ENOMEM; |
error = ENOMEM; |
break; |
break; |
} |
} |
|
if ((error = pool_prime_page(pp, cp, PR_NOWAIT)) != 0) { |
|
(*pp->pr_free)(cp, pp->pr_pagesz, pp->pr_mtype); |
|
break; |
|
} |
pp->pr_npagealloc++; |
pp->pr_npagealloc++; |
pool_prime_page(pp, cp); |
|
} |
} |
|
|
return (error); |
return (error); |
Line 1713 pool_cache_put(struct pool_cache *pc, vo |
|
Line 1647 pool_cache_put(struct pool_cache *pc, vo |
|
* 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. |
*/ |
*/ |
if (pc->pc_dtor != NULL) |
pool_cache_destruct_object(pc, object); |
(*pc->pc_dtor)(pc->pc_arg, object); |
|
pool_put(pc->pc_pool, object); |
|
return; |
return; |
} |
} |
|
|
Line 1730 pool_cache_put(struct pool_cache *pc, vo |
|
Line 1662 pool_cache_put(struct pool_cache *pc, vo |
|
} |
} |
|
|
/* |
/* |
|
* pool_cache_destruct_object: |
|
* |
|
* Force destruction of an object and its release back into |
|
* the pool. |
|
*/ |
|
void |
|
pool_cache_destruct_object(struct pool_cache *pc, void *object) |
|
{ |
|
|
|
if (pc->pc_dtor != NULL) |
|
(*pc->pc_dtor)(pc->pc_arg, object); |
|
pool_put(pc->pc_pool, object); |
|
} |
|
|
|
/* |
* pool_cache_do_invalidate: |
* pool_cache_do_invalidate: |
* |
* |
* This internal function implements pool_cache_invalidate() and |
* This internal function implements pool_cache_invalidate() and |