version 1.32.6.4, 2007/12/09 19:38:24 |
version 1.33, 2007/10/23 11:29:06 |
Line 107 LIST_HEAD(vmem_hashlist, vmem_btag); |
|
Line 107 LIST_HEAD(vmem_hashlist, vmem_btag); |
|
#define QC_NAME_MAX 16 |
#define QC_NAME_MAX 16 |
|
|
struct qcache { |
struct qcache { |
pool_cache_t qc_cache; |
struct pool qc_pool; |
|
struct pool_cache qc_cache; |
vmem_t *qc_vmem; |
vmem_t *qc_vmem; |
char qc_name[QC_NAME_MAX]; |
char qc_name[QC_NAME_MAX]; |
}; |
}; |
typedef struct qcache qcache_t; |
typedef struct qcache qcache_t; |
#define QC_POOL_TO_QCACHE(pool) ((qcache_t *)(pool->pr_qcache)) |
#define QC_POOL_TO_QCACHE(pool) ((qcache_t *)(pool)) |
#endif /* defined(QCACHE) */ |
#endif /* defined(QCACHE) */ |
|
|
/* vmem arena */ |
/* vmem arena */ |
|
|
#define VMEM_LOCK(vm) mutex_enter(&vm->vm_lock) |
#define VMEM_LOCK(vm) mutex_enter(&vm->vm_lock) |
#define VMEM_TRYLOCK(vm) mutex_tryenter(&vm->vm_lock) |
#define VMEM_TRYLOCK(vm) mutex_tryenter(&vm->vm_lock) |
#define VMEM_UNLOCK(vm) mutex_exit(&vm->vm_lock) |
#define VMEM_UNLOCK(vm) mutex_exit(&vm->vm_lock) |
#define VMEM_LOCK_INIT(vm, ipl) mutex_init(&vm->vm_lock, MUTEX_DEFAULT, ipl) |
#ifdef notyet /* XXX needs vmlocking branch changes */ |
|
#define VMEM_LOCK_INIT(vm, ipl) mutex_init(&vm->vm_lock, MUTEX_DRIVER, ipl) |
|
#else |
|
#define VMEM_LOCK_INIT(vm, ipl) mutex_init(&vm->vm_lock, MUTEX_DRIVER, IPL_VM) |
|
#endif |
#define VMEM_LOCK_DESTROY(vm) mutex_destroy(&vm->vm_lock) |
#define VMEM_LOCK_DESTROY(vm) mutex_destroy(&vm->vm_lock) |
#define VMEM_ASSERT_LOCKED(vm) KASSERT(mutex_owned(&vm->vm_lock)) |
#define VMEM_ASSERT_LOCKED(vm) KASSERT(mutex_owned(&vm->vm_lock)) |
|
|
|
|
/* ---- boundary tag */ |
/* ---- boundary tag */ |
|
|
#if defined(_KERNEL) |
#if defined(_KERNEL) |
static struct pool_cache bt_cache; |
static struct pool_cache bt_poolcache; |
|
static POOL_INIT(bt_pool, sizeof(bt_t), 0, 0, 0, "vmembtpl", NULL, IPL_VM); |
#endif /* defined(_KERNEL) */ |
#endif /* defined(_KERNEL) */ |
|
|
static bt_t * |
static bt_t * |
Line 240 bt_alloc(vmem_t *vm, vm_flag_t flags) |
|
Line 246 bt_alloc(vmem_t *vm, vm_flag_t flags) |
|
bt_t *bt; |
bt_t *bt; |
|
|
#if defined(_KERNEL) |
#if defined(_KERNEL) |
bt = pool_cache_get(&bt_cache, |
int s; |
|
|
|
/* XXX bootstrap */ |
|
s = splvm(); |
|
bt = pool_cache_get(&bt_poolcache, |
(flags & VM_SLEEP) != 0 ? PR_WAITOK : PR_NOWAIT); |
(flags & VM_SLEEP) != 0 ? PR_WAITOK : PR_NOWAIT); |
|
splx(s); |
#else /* defined(_KERNEL) */ |
#else /* defined(_KERNEL) */ |
bt = malloc(sizeof *bt); |
bt = malloc(sizeof *bt); |
#endif /* defined(_KERNEL) */ |
#endif /* defined(_KERNEL) */ |
Line 254 bt_free(vmem_t *vm, bt_t *bt) |
|
Line 265 bt_free(vmem_t *vm, bt_t *bt) |
|
{ |
{ |
|
|
#if defined(_KERNEL) |
#if defined(_KERNEL) |
pool_cache_put(&bt_cache, bt); |
int s; |
|
|
|
/* XXX bootstrap */ |
|
s = splvm(); |
|
pool_cache_put(&bt_poolcache, bt); |
|
splx(s); |
#else /* defined(_KERNEL) */ |
#else /* defined(_KERNEL) */ |
free(bt); |
free(bt); |
#endif /* defined(_KERNEL) */ |
#endif /* defined(_KERNEL) */ |
Line 491 qc_init(vmem_t *vm, size_t qcache_max, i |
|
Line 507 qc_init(vmem_t *vm, size_t qcache_max, i |
|
qc->qc_vmem = vm; |
qc->qc_vmem = vm; |
snprintf(qc->qc_name, sizeof(qc->qc_name), "%s-%zu", |
snprintf(qc->qc_name, sizeof(qc->qc_name), "%s-%zu", |
vm->vm_name, size); |
vm->vm_name, size); |
qc->qc_cache = pool_cache_init(size, |
pool_init(&qc->qc_pool, size, ORDER2SIZE(vm->vm_quantum_shift), |
ORDER2SIZE(vm->vm_quantum_shift), 0, |
0, PR_NOALIGN | PR_NOTOUCH /* XXX */, qc->qc_name, pa, |
PR_NOALIGN | PR_NOTOUCH /* XXX */, |
ipl); |
qc->qc_name, pa, ipl, NULL, NULL, NULL); |
|
KASSERT(qc->qc_cache != NULL); /* XXX */ |
|
if (prevqc != NULL && |
if (prevqc != NULL && |
qc->qc_cache->pc_pool.pr_itemsperpage == |
qc->qc_pool.pr_itemsperpage == |
prevqc->qc_cache->pc_pool.pr_itemsperpage) { |
prevqc->qc_pool.pr_itemsperpage) { |
pool_cache_destroy(qc->qc_cache); |
pool_destroy(&qc->qc_pool); |
vm->vm_qcache[i - 1] = prevqc; |
vm->vm_qcache[i - 1] = prevqc; |
continue; |
continue; |
} |
} |
qc->qc_cache->pc_pool.pr_qcache = qc; |
pool_cache_init(&qc->qc_cache, &qc->qc_pool, NULL, NULL, NULL); |
vm->vm_qcache[i - 1] = qc; |
vm->vm_qcache[i - 1] = qc; |
prevqc = qc; |
prevqc = qc; |
} |
} |
Line 524 qc_destroy(vmem_t *vm) |
|
Line 538 qc_destroy(vmem_t *vm) |
|
if (prevqc == qc) { |
if (prevqc == qc) { |
continue; |
continue; |
} |
} |
pool_cache_destroy(qc->qc_cache); |
pool_cache_destroy(&qc->qc_cache); |
|
pool_destroy(&qc->qc_pool); |
prevqc = qc; |
prevqc = qc; |
} |
} |
} |
} |
Line 545 qc_reap(vmem_t *vm) |
|
Line 560 qc_reap(vmem_t *vm) |
|
if (prevqc == qc) { |
if (prevqc == qc) { |
continue; |
continue; |
} |
} |
if (pool_cache_reclaim(qc->qc_cache) != 0) { |
if (pool_reclaim(&qc->qc_pool) != 0) { |
didsomething = true; |
didsomething = true; |
} |
} |
prevqc = qc; |
prevqc = qc; |
|
|
{ |
{ |
|
|
mutex_init(&vmem_list_lock, MUTEX_DEFAULT, IPL_NONE); |
mutex_init(&vmem_list_lock, MUTEX_DEFAULT, IPL_NONE); |
pool_cache_bootstrap(&bt_cache, sizeof(bt_t), 0, 0, 0, "vmembt", |
pool_cache_init(&bt_poolcache, &bt_pool, NULL, NULL, NULL); |
NULL, IPL_VM, NULL, NULL, NULL); |
|
return 0; |
return 0; |
} |
} |
#endif /* defined(_KERNEL) */ |
#endif /* defined(_KERNEL) */ |
Line 867 vmem_alloc(vmem_t *vm, vmem_size_t size0 |
|
Line 881 vmem_alloc(vmem_t *vm, vmem_size_t size0 |
|
int qidx = size >> vm->vm_quantum_shift; |
int qidx = size >> vm->vm_quantum_shift; |
qcache_t *qc = vm->vm_qcache[qidx - 1]; |
qcache_t *qc = vm->vm_qcache[qidx - 1]; |
|
|
return (vmem_addr_t)pool_cache_get(qc->qc_cache, |
return (vmem_addr_t)pool_cache_get(&qc->qc_cache, |
vmf_to_prf(flags)); |
vmf_to_prf(flags)); |
} |
} |
#endif /* defined(QCACHE) */ |
#endif /* defined(QCACHE) */ |
Line 1036 vmem_free(vmem_t *vm, vmem_addr_t addr, |
|
Line 1050 vmem_free(vmem_t *vm, vmem_addr_t addr, |
|
int qidx = (size + vm->vm_quantum_mask) >> vm->vm_quantum_shift; |
int qidx = (size + vm->vm_quantum_mask) >> vm->vm_quantum_shift; |
qcache_t *qc = vm->vm_qcache[qidx - 1]; |
qcache_t *qc = vm->vm_qcache[qidx - 1]; |
|
|
return pool_cache_put(qc->qc_cache, (void *)addr); |
return pool_cache_put(&qc->qc_cache, (void *)addr); |
} |
} |
#endif /* defined(QCACHE) */ |
#endif /* defined(QCACHE) */ |
|
|
Line 1189 vmem_rehash_start(void) |
|
Line 1203 vmem_rehash_start(void) |
|
int error; |
int error; |
|
|
error = workqueue_create(&vmem_rehash_wq, "vmem_rehash", |
error = workqueue_create(&vmem_rehash_wq, "vmem_rehash", |
vmem_rehash_all, NULL, PRI_VM, IPL_SOFTCLOCK, 0); |
vmem_rehash_all, NULL, PVM, IPL_SOFTCLOCK, 0); |
if (error) { |
if (error) { |
panic("%s: workqueue_create %d\n", __func__, error); |
panic("%s: workqueue_create %d\n", __func__, error); |
} |
} |