| version 1.137, 2007/11/18 16:27:43 |
version 1.137.2.4, 2007/12/26 17:55:57 |
| Line 58 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| Line 58 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| #include <sys/lockdebug.h> |
#include <sys/lockdebug.h> |
| #include <sys/xcall.h> |
#include <sys/xcall.h> |
| #include <sys/cpu.h> |
#include <sys/cpu.h> |
| |
#include <sys/atomic.h> |
| |
|
| #include <uvm/uvm.h> |
#include <uvm/uvm.h> |
| |
|
| Line 75 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| Line 76 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| */ |
*/ |
| |
|
| /* List of all pools */ |
/* List of all pools */ |
| LIST_HEAD(,pool) pool_head = LIST_HEAD_INITIALIZER(pool_head); |
TAILQ_HEAD(,pool) pool_head = TAILQ_HEAD_INITIALIZER(pool_head); |
| |
|
| /* List of all caches. */ |
|
| LIST_HEAD(,pool_cache) pool_cache_head = |
|
| LIST_HEAD_INITIALIZER(pool_cache_head); |
|
| |
|
| /* Private pool for page header structures */ |
/* Private pool for page header structures */ |
| #define PHPOOL_MAX 8 |
#define PHPOOL_MAX 8 |
| Line 185 static struct pool pcgpool; |
|
| Line 182 static struct pool pcgpool; |
|
| static struct pool cache_pool; |
static struct pool cache_pool; |
| static struct pool cache_cpu_pool; |
static struct pool cache_cpu_pool; |
| |
|
| |
/* List of all caches. */ |
| |
TAILQ_HEAD(,pool_cache) pool_cache_head = |
| |
TAILQ_HEAD_INITIALIZER(pool_cache_head); |
| |
|
| |
int pool_cache_disable; |
| |
|
| |
|
| static pool_cache_cpu_t *pool_cache_put_slow(pool_cache_cpu_t *, int *, |
static pool_cache_cpu_t *pool_cache_put_slow(pool_cache_cpu_t *, int *, |
| void *, paddr_t); |
void *, paddr_t); |
| static pool_cache_cpu_t *pool_cache_get_slow(pool_cache_cpu_t *, int *, |
static pool_cache_cpu_t *pool_cache_get_slow(pool_cache_cpu_t *, int *, |
|
|
| pool_init(struct pool *pp, size_t size, u_int align, u_int ioff, int flags, |
pool_init(struct pool *pp, size_t size, u_int align, u_int ioff, int flags, |
| const char *wchan, struct pool_allocator *palloc, int ipl) |
const char *wchan, struct pool_allocator *palloc, int ipl) |
| { |
{ |
| #ifdef DEBUG |
|
| struct pool *pp1; |
struct pool *pp1; |
| #endif |
|
| size_t trysize, phsize; |
size_t trysize, phsize; |
| int off, slack; |
int off, slack; |
| |
|
| Line 626 pool_init(struct pool *pp, size_t size, |
|
| Line 628 pool_init(struct pool *pp, size_t size, |
|
| * Check that the pool hasn't already been initialised and |
* Check that the pool hasn't already been initialised and |
| * added to the list of all pools. |
* added to the list of all pools. |
| */ |
*/ |
| LIST_FOREACH(pp1, &pool_head, pr_poollist) { |
TAILQ_FOREACH(pp1, &pool_head, pr_poollist) { |
| if (pp == pp1) |
if (pp == pp1) |
| panic("pool_init: pool %s already initialised", |
panic("pool_init: pool %s already initialised", |
| wchan); |
wchan); |
| Line 802 pool_init(struct pool *pp, size_t size, |
|
| Line 804 pool_init(struct pool *pp, size_t size, |
|
| pp->pr_entered_file = NULL; |
pp->pr_entered_file = NULL; |
| pp->pr_entered_line = 0; |
pp->pr_entered_line = 0; |
| |
|
| mutex_init(&pp->pr_lock, MUTEX_DEFAULT, ipl); |
/* |
| |
* XXXAD hack to prevent IP input processing from blocking. |
| |
*/ |
| |
if (ipl == IPL_SOFTNET) { |
| |
mutex_init(&pp->pr_lock, MUTEX_DEFAULT, IPL_VM); |
| |
} else { |
| |
mutex_init(&pp->pr_lock, MUTEX_DEFAULT, ipl); |
| |
} |
| cv_init(&pp->pr_cv, wchan); |
cv_init(&pp->pr_cv, wchan); |
| pp->pr_ipl = ipl; |
pp->pr_ipl = ipl; |
| |
|
| Line 837 pool_init(struct pool *pp, size_t size, |
|
| Line 846 pool_init(struct pool *pp, size_t size, |
|
| "cachegrp", &pool_allocator_meta, IPL_VM); |
"cachegrp", &pool_allocator_meta, IPL_VM); |
| } |
} |
| |
|
| if (__predict_true(!cold)) { |
/* Insert into the list of all pools. */ |
| /* Insert into the list of all pools. */ |
if (__predict_true(!cold)) |
| mutex_enter(&pool_head_lock); |
mutex_enter(&pool_head_lock); |
| LIST_INSERT_HEAD(&pool_head, pp, pr_poollist); |
TAILQ_FOREACH(pp1, &pool_head, pr_poollist) { |
| |
if (strcmp(pp1->pr_wchan, pp->pr_wchan) > 0) |
| |
break; |
| |
} |
| |
if (pp1 == NULL) |
| |
TAILQ_INSERT_TAIL(&pool_head, pp, pr_poollist); |
| |
else |
| |
TAILQ_INSERT_BEFORE(pp1, pp, pr_poollist); |
| |
if (__predict_true(!cold)) |
| mutex_exit(&pool_head_lock); |
mutex_exit(&pool_head_lock); |
| |
|
| /* Insert this into the list of pools using this allocator. */ |
/* Insert this into the list of pools using this allocator. */ |
| |
if (__predict_true(!cold)) |
| mutex_enter(&palloc->pa_lock); |
mutex_enter(&palloc->pa_lock); |
| TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list); |
TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list); |
| |
if (__predict_true(!cold)) |
| mutex_exit(&palloc->pa_lock); |
mutex_exit(&palloc->pa_lock); |
| } else { |
|
| LIST_INSERT_HEAD(&pool_head, pp, pr_poollist); |
|
| TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list); |
|
| } |
|
| |
|
| pool_reclaim_register(pp); |
pool_reclaim_register(pp); |
| } |
} |
| Line 868 pool_destroy(struct pool *pp) |
|
| Line 883 pool_destroy(struct pool *pp) |
|
| mutex_enter(&pool_head_lock); |
mutex_enter(&pool_head_lock); |
| while (pp->pr_refcnt != 0) |
while (pp->pr_refcnt != 0) |
| cv_wait(&pool_busy, &pool_head_lock); |
cv_wait(&pool_busy, &pool_head_lock); |
| LIST_REMOVE(pp, pr_poollist); |
TAILQ_REMOVE(&pool_head, pp, pr_poollist); |
| if (drainpp == pp) |
if (drainpp == pp) |
| drainpp = NULL; |
drainpp = NULL; |
| mutex_exit(&pool_head_lock); |
mutex_exit(&pool_head_lock); |
| Line 1674 pool_drain_start(struct pool **ppp, uint |
|
| Line 1689 pool_drain_start(struct pool **ppp, uint |
|
| { |
{ |
| struct pool *pp; |
struct pool *pp; |
| |
|
| KASSERT(!LIST_EMPTY(&pool_head)); |
KASSERT(!TAILQ_EMPTY(&pool_head)); |
| |
|
| pp = NULL; |
pp = NULL; |
| |
|
| Line 1682 pool_drain_start(struct pool **ppp, uint |
|
| Line 1697 pool_drain_start(struct pool **ppp, uint |
|
| mutex_enter(&pool_head_lock); |
mutex_enter(&pool_head_lock); |
| do { |
do { |
| if (drainpp == NULL) { |
if (drainpp == NULL) { |
| drainpp = LIST_FIRST(&pool_head); |
drainpp = TAILQ_FIRST(&pool_head); |
| } |
} |
| if (drainpp != NULL) { |
if (drainpp != NULL) { |
| pp = drainpp; |
pp = drainpp; |
| drainpp = LIST_NEXT(pp, pr_poollist); |
drainpp = TAILQ_NEXT(pp, pr_poollist); |
| } |
} |
| /* |
/* |
| * Skip completely idle pools. We depend on at least |
* Skip completely idle pools. We depend on at least |
| Line 1742 pool_printall(const char *modif, void (* |
|
| Line 1757 pool_printall(const char *modif, void (* |
|
| { |
{ |
| struct pool *pp; |
struct pool *pp; |
| |
|
| LIST_FOREACH(pp, &pool_head, pr_poollist) { |
TAILQ_FOREACH(pp, &pool_head, pr_poollist) { |
| pool_printit(pp, modif, pr); |
pool_printit(pp, modif, pr); |
| } |
} |
| } |
} |
| Line 2032 pool_cache_bootstrap(pool_cache_t pc, si |
|
| Line 2047 pool_cache_bootstrap(pool_cache_t pc, si |
|
| void *arg) |
void *arg) |
| { |
{ |
| CPU_INFO_ITERATOR cii; |
CPU_INFO_ITERATOR cii; |
| |
pool_cache_t pc1; |
| struct cpu_info *ci; |
struct cpu_info *ci; |
| struct pool *pp; |
struct pool *pp; |
| |
|
| Line 2040 pool_cache_bootstrap(pool_cache_t pc, si |
|
| Line 2056 pool_cache_bootstrap(pool_cache_t pc, si |
|
| palloc = &pool_allocator_nointr; |
palloc = &pool_allocator_nointr; |
| pool_init(pp, size, align, align_offset, flags, wchan, palloc, ipl); |
pool_init(pp, size, align, align_offset, flags, wchan, palloc, ipl); |
| |
|
| mutex_init(&pc->pc_lock, MUTEX_DEFAULT, pp->pr_ipl); |
/* |
| |
* XXXAD hack to prevent IP input processing from blocking. |
| |
*/ |
| |
if (ipl == IPL_SOFTNET) { |
| |
mutex_init(&pc->pc_lock, MUTEX_DEFAULT, IPL_VM); |
| |
} else { |
| |
mutex_init(&pc->pc_lock, MUTEX_DEFAULT, ipl); |
| |
} |
| |
|
| if (ctor == NULL) { |
if (ctor == NULL) { |
| ctor = (int (*)(void *, void *, int))nullop; |
ctor = (int (*)(void *, void *, int))nullop; |
| Line 2075 pool_cache_bootstrap(pool_cache_t pc, si |
|
| Line 2098 pool_cache_bootstrap(pool_cache_t pc, si |
|
| pool_cache_cpu_init1(ci, pc); |
pool_cache_cpu_init1(ci, pc); |
| } |
} |
| } |
} |
| |
|
| if (__predict_true(!cold)) { |
/* Add to list of all pools. */ |
| mutex_enter(&pp->pr_lock); |
if (__predict_true(!cold)) |
| pp->pr_cache = pc; |
|
| mutex_exit(&pp->pr_lock); |
|
| mutex_enter(&pool_head_lock); |
mutex_enter(&pool_head_lock); |
| LIST_INSERT_HEAD(&pool_cache_head, pc, pc_cachelist); |
TAILQ_FOREACH(pc1, &pool_cache_head, pc_cachelist) { |
| mutex_exit(&pool_head_lock); |
if (strcmp(pc1->pc_pool.pr_wchan, pc->pc_pool.pr_wchan) > 0) |
| } else { |
break; |
| pp->pr_cache = pc; |
|
| LIST_INSERT_HEAD(&pool_cache_head, pc, pc_cachelist); |
|
| } |
} |
| |
if (pc1 == NULL) |
| |
TAILQ_INSERT_TAIL(&pool_cache_head, pc, pc_cachelist); |
| |
else |
| |
TAILQ_INSERT_BEFORE(pc1, pc, pc_cachelist); |
| |
if (__predict_true(!cold)) |
| |
mutex_exit(&pool_head_lock); |
| |
|
| |
membar_sync(); |
| |
pp->pr_cache = pc; |
| } |
} |
| |
|
| /* |
/* |
| Line 2106 pool_cache_destroy(pool_cache_t pc) |
|
| Line 2134 pool_cache_destroy(pool_cache_t pc) |
|
| mutex_enter(&pool_head_lock); |
mutex_enter(&pool_head_lock); |
| while (pc->pc_refcnt != 0) |
while (pc->pc_refcnt != 0) |
| cv_wait(&pool_busy, &pool_head_lock); |
cv_wait(&pool_busy, &pool_head_lock); |
| LIST_REMOVE(pc, pc_cachelist); |
TAILQ_REMOVE(&pool_cache_head, pc, pc_cachelist); |
| mutex_exit(&pool_head_lock); |
mutex_exit(&pool_head_lock); |
| |
|
| /* First, invalidate the entire cache. */ |
/* First, invalidate the entire cache. */ |
| Line 2197 pool_cache_cpu_init(struct cpu_info *ci) |
|
| Line 2225 pool_cache_cpu_init(struct cpu_info *ci) |
|
| pool_cache_t pc; |
pool_cache_t pc; |
| |
|
| mutex_enter(&pool_head_lock); |
mutex_enter(&pool_head_lock); |
| LIST_FOREACH(pc, &pool_cache_head, pc_cachelist) { |
TAILQ_FOREACH(pc, &pool_cache_head, pc_cachelist) { |
| pc->pc_refcnt++; |
pc->pc_refcnt++; |
| mutex_exit(&pool_head_lock); |
mutex_exit(&pool_head_lock); |
| |
|
| Line 2576 pool_cache_put_slow(pool_cache_cpu_t *cc |
|
| Line 2604 pool_cache_put_slow(pool_cache_cpu_t *cc |
|
| * If we can't allocate a new group, just throw the |
* If we can't allocate a new group, just throw the |
| * object away. |
* object away. |
| */ |
*/ |
| pcg = pool_get(&pcgpool, PR_NOWAIT); |
if (pool_cache_disable) { |
| |
pcg = NULL; |
| |
} else { |
| |
pcg = pool_get(&pcgpool, PR_NOWAIT); |
| |
} |
| if (pcg == NULL) { |
if (pcg == NULL) { |
| pool_cache_destruct_object(pc, object); |
pool_cache_destruct_object(pc, object); |
| return NULL; |
return NULL; |