version 1.22, 2008/05/16 09:22:01 |
version 1.24, 2008/06/15 21:18:06 |
Line 37 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 37 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/systm.h> |
#include <sys/systm.h> |
#include <sys/kernel.h> |
#include <sys/kernel.h> |
#include <sys/malloc.h> |
#include <sys/kmem.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/hash.h> |
#include <sys/hash.h> |
#include <sys/proc.h> |
#include <sys/proc.h> |
Line 46 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 46 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/mount.h> |
#include <sys/mount.h> |
#include <sys/pool.h> |
#include <sys/pool.h> |
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
|
#include <sys/atomic.h> |
|
|
#include <ufs/ufs/inode.h> |
#include <ufs/ufs/inode.h> |
#include <ufs/ufs/dir.h> |
#include <ufs/ufs/dir.h> |
Line 59 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 60 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#define OFSFMT(ip) ((ip)->i_ump->um_maxsymlinklen <= 0) |
#define OFSFMT(ip) ((ip)->i_ump->um_maxsymlinklen <= 0) |
#define BLKFREE2IDX(n) ((n) > DH_NFSTATS ? DH_NFSTATS : (n)) |
#define BLKFREE2IDX(n) ((n) > DH_NFSTATS ? DH_NFSTATS : (n)) |
|
|
static MALLOC_JUSTDEFINE(M_DIRHASH, "UFS dirhash", "UFS directory hash tables"); |
static u_int ufs_dirhashminblks = 5; |
|
static u_int ufs_dirhashmaxmem = 2 * 1024 * 1024; |
static int ufs_dirhashminblks = 5; |
static u_int ufs_dirhashmem; |
static int ufs_dirhashmaxmem = 2 * 1024 * 1024; |
static u_int ufs_dirhashcheck = 0; |
static int ufs_dirhashmem; |
|
static int ufs_dirhashcheck = 0; |
|
|
|
static int ufsdirhash_hash(struct dirhash *dh, const char *name, int namelen); |
static int ufsdirhash_hash(struct dirhash *dh, const char *name, int namelen); |
static void ufsdirhash_adjfree(struct dirhash *dh, doff_t offset, int diff, |
static void ufsdirhash_adjfree(struct dirhash *dh, doff_t offset, int diff, |
Line 76 static doff_t ufsdirhash_getprev(struct |
|
Line 75 static doff_t ufsdirhash_getprev(struct |
|
int dirblksiz); |
int dirblksiz); |
static int ufsdirhash_recycle(int wanted); |
static int ufsdirhash_recycle(int wanted); |
|
|
|
static pool_cache_t ufsdirhashblk_cache; |
static pool_cache_t ufsdirhash_cache; |
static pool_cache_t ufsdirhash_cache; |
|
|
#define DIRHASHLIST_LOCK() mutex_enter(&ufsdirhash_lock) |
#define DIRHASHLIST_LOCK() mutex_enter(&ufsdirhash_lock) |
#define DIRHASHLIST_UNLOCK() mutex_exit(&ufsdirhash_lock) |
#define DIRHASHLIST_UNLOCK() mutex_exit(&ufsdirhash_lock) |
#define DIRHASH_LOCK(dh) mutex_enter(&(dh)->dh_lock) |
#define DIRHASH_LOCK(dh) mutex_enter(&(dh)->dh_lock) |
#define DIRHASH_UNLOCK(dh) mutex_exit(&(dh)->dh_lock) |
#define DIRHASH_UNLOCK(dh) mutex_exit(&(dh)->dh_lock) |
#define DIRHASH_BLKALLOC_WAITOK() \ |
#define DIRHASH_BLKALLOC() \ |
pool_cache_get(ufsdirhash_cache, PR_WAITOK) |
pool_cache_get(ufsdirhashblk_cache, PR_NOWAIT) |
#define DIRHASH_BLKFREE(ptr) \ |
#define DIRHASH_BLKFREE(ptr) \ |
pool_cache_put(ufsdirhash_cache, ptr) |
pool_cache_put(ufsdirhashblk_cache, ptr) |
|
|
/* Dirhash list; recently-used entries are near the tail. */ |
/* Dirhash list; recently-used entries are near the tail. */ |
static TAILQ_HEAD(, dirhash) ufsdirhash_list; |
static TAILQ_HEAD(, dirhash) ufsdirhash_list; |
Line 154 ufsdirhash_build(struct inode *ip) |
|
Line 154 ufsdirhash_build(struct inode *ip) |
|
memreqd = sizeof(*dh) + narrays * sizeof(*dh->dh_hash) + |
memreqd = sizeof(*dh) + narrays * sizeof(*dh->dh_hash) + |
narrays * DH_NBLKOFF * sizeof(**dh->dh_hash) + |
narrays * DH_NBLKOFF * sizeof(**dh->dh_hash) + |
nblocks * sizeof(*dh->dh_blkfree); |
nblocks * sizeof(*dh->dh_blkfree); |
DIRHASHLIST_LOCK(); |
|
if (memreqd + ufs_dirhashmem > ufs_dirhashmaxmem) { |
while (atomic_add_int_nv(&ufs_dirhashmem, memreqd) > |
DIRHASHLIST_UNLOCK(); |
ufs_dirhashmaxmem) { |
|
atomic_add_int(&ufs_dirhashmem, -memreqd); |
if (memreqd > ufs_dirhashmaxmem / 2) |
if (memreqd > ufs_dirhashmaxmem / 2) |
return (-1); |
return (-1); |
|
|
/* Try to free some space. */ |
/* Try to free some space. */ |
if (ufsdirhash_recycle(memreqd) != 0) |
if (ufsdirhash_recycle(memreqd) != 0) |
return (-1); |
return (-1); |
/* Enough was freed, and list has been locked. */ |
else |
|
DIRHASHLIST_UNLOCK(); |
} |
} |
ufs_dirhashmem += memreqd; |
|
DIRHASHLIST_UNLOCK(); |
|
|
|
/* |
/* |
* Use non-blocking mallocs so that we will revert to a linear |
* Use non-blocking mallocs so that we will revert to a linear |
* lookup on failure rather than potentially blocking forever. |
* lookup on failure rather than potentially blocking forever. |
*/ |
*/ |
MALLOC(dh, struct dirhash *, sizeof *dh, M_DIRHASH, M_NOWAIT | M_ZERO); |
dh = pool_cache_get(ufsdirhash_cache, PR_NOWAIT); |
if (dh == NULL) { |
if (dh == NULL) { |
DIRHASHLIST_LOCK(); |
atomic_add_int(&ufs_dirhashmem, -memreqd); |
ufs_dirhashmem -= memreqd; |
|
DIRHASHLIST_UNLOCK(); |
|
return (-1); |
return (-1); |
} |
} |
|
memset(dh, 0, sizeof(*dh)); |
mutex_init(&dh->dh_lock, MUTEX_DEFAULT, IPL_NONE); |
mutex_init(&dh->dh_lock, MUTEX_DEFAULT, IPL_NONE); |
dh->dh_hash = (doff_t **)malloc(narrays * sizeof(dh->dh_hash[0]), |
dh->dh_hashsz = narrays * sizeof(dh->dh_hash[0]); |
M_DIRHASH, M_NOWAIT | M_ZERO); |
dh->dh_hash = kmem_zalloc(dh->dh_hashsz, KM_NOSLEEP); |
dh->dh_blkfree = (u_int8_t *)malloc(nblocks * sizeof(dh->dh_blkfree[0]), |
dh->dh_blkfreesz = nblocks * sizeof(dh->dh_blkfree[0]); |
M_DIRHASH, M_NOWAIT); |
dh->dh_blkfree = kmem_zalloc(dh->dh_blkfreesz, KM_NOSLEEP); |
if (dh->dh_hash == NULL || dh->dh_blkfree == NULL) |
if (dh->dh_hash == NULL || dh->dh_blkfree == NULL) |
goto fail; |
goto fail; |
for (i = 0; i < narrays; i++) { |
for (i = 0; i < narrays; i++) { |
if ((dh->dh_hash[i] = DIRHASH_BLKALLOC_WAITOK()) == NULL) |
if ((dh->dh_hash[i] = DIRHASH_BLKALLOC()) == NULL) |
goto fail; |
goto fail; |
for (j = 0; j < DH_NBLKOFF; j++) |
for (j = 0; j < DH_NBLKOFF; j++) |
dh->dh_hash[i][j] = DIRHASH_EMPTY; |
dh->dh_hash[i][j] = DIRHASH_EMPTY; |
|
|
for (i = 0; i < narrays; i++) |
for (i = 0; i < narrays; i++) |
if (dh->dh_hash[i] != NULL) |
if (dh->dh_hash[i] != NULL) |
DIRHASH_BLKFREE(dh->dh_hash[i]); |
DIRHASH_BLKFREE(dh->dh_hash[i]); |
FREE(dh->dh_hash, M_DIRHASH); |
kmem_free(dh->dh_hash, dh->dh_hashsz); |
} |
} |
if (dh->dh_blkfree != NULL) |
if (dh->dh_blkfree != NULL) |
FREE(dh->dh_blkfree, M_DIRHASH); |
kmem_free(dh->dh_blkfree, dh->dh_blkfreesz); |
mutex_destroy(&dh->dh_lock); |
mutex_destroy(&dh->dh_lock); |
FREE(dh, M_DIRHASH); |
pool_cache_put(ufsdirhash_cache, dh); |
ip->i_dirhash = NULL; |
ip->i_dirhash = NULL; |
DIRHASHLIST_LOCK(); |
atomic_add_int(&ufs_dirhashmem, -memreqd); |
ufs_dirhashmem -= memreqd; |
|
DIRHASHLIST_UNLOCK(); |
|
return (-1); |
return (-1); |
} |
} |
|
|
Line 281 ufsdirhash_free(struct inode *ip) |
|
Line 277 ufsdirhash_free(struct inode *ip) |
|
|
|
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return; |
return; |
DIRHASHLIST_LOCK(); |
|
DIRHASH_LOCK(dh); |
|
if (dh->dh_onlist) |
|
TAILQ_REMOVE(&ufsdirhash_list, dh, dh_list); |
|
DIRHASH_UNLOCK(dh); |
|
DIRHASHLIST_UNLOCK(); |
|
|
|
/* The dirhash pointed to by 'dh' is exclusively ours now. */ |
if (dh->dh_onlist) { |
|
DIRHASHLIST_LOCK(); |
|
if (dh->dh_onlist) |
|
TAILQ_REMOVE(&ufsdirhash_list, dh, dh_list); |
|
DIRHASHLIST_UNLOCK(); |
|
} |
|
|
|
/* The dirhash pointed to by 'dh' is exclusively ours now. */ |
mem = sizeof(*dh); |
mem = sizeof(*dh); |
if (dh->dh_hash != NULL) { |
if (dh->dh_hash != NULL) { |
for (i = 0; i < dh->dh_narrays; i++) |
for (i = 0; i < dh->dh_narrays; i++) |
DIRHASH_BLKFREE(dh->dh_hash[i]); |
DIRHASH_BLKFREE(dh->dh_hash[i]); |
FREE(dh->dh_hash, M_DIRHASH); |
kmem_free(dh->dh_hash, dh->dh_hashsz); |
FREE(dh->dh_blkfree, M_DIRHASH); |
kmem_free(dh->dh_blkfree, dh->dh_blkfreesz); |
mem += dh->dh_narrays * sizeof(*dh->dh_hash) + |
mem += dh->dh_hashsz; |
dh->dh_narrays * DH_NBLKOFF * sizeof(**dh->dh_hash) + |
mem += dh->dh_narrays * DH_NBLKOFF * sizeof(**dh->dh_hash); |
dh->dh_nblk * sizeof(*dh->dh_blkfree); |
mem += dh->dh_nblk * sizeof(*dh->dh_blkfree); |
} |
} |
mutex_destroy(&dh->dh_lock); |
mutex_destroy(&dh->dh_lock); |
FREE(dh, M_DIRHASH); |
pool_cache_put(ufsdirhash_cache, dh); |
ip->i_dirhash = NULL; |
ip->i_dirhash = NULL; |
|
|
DIRHASHLIST_LOCK(); |
atomic_add_int(&ufs_dirhashmem, -mem); |
ufs_dirhashmem -= mem; |
|
DIRHASHLIST_UNLOCK(); |
|
} |
} |
|
|
/* |
/* |
Line 335 ufsdirhash_lookup(struct inode *ip, cons |
|
Line 329 ufsdirhash_lookup(struct inode *ip, cons |
|
|
|
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return (EJUSTRETURN); |
return (EJUSTRETURN); |
|
|
/* |
/* |
* Move this dirhash towards the end of the list if it has a |
* Move this dirhash towards the end of the list if it has a |
* score higher than the next entry, and acquire the dh_lock. |
* score higher than the next entry, and acquire the dh_lock. |
|
|
slot = WRAPINCR(slot, dh->dh_hlen)) { |
slot = WRAPINCR(slot, dh->dh_hlen)) { |
if (offset == DIRHASH_DEL) |
if (offset == DIRHASH_DEL) |
continue; |
continue; |
DIRHASH_UNLOCK(dh); |
|
|
|
if (offset < 0 || offset >= ip->i_size) |
if (offset < 0 || offset >= ip->i_size) |
panic("ufsdirhash_lookup: bad offset in hash array"); |
panic("ufsdirhash_lookup: bad offset in hash array"); |
|
|
brelse(bp, 0); |
brelse(bp, 0); |
blkoff = offset & ~bmask; |
blkoff = offset & ~bmask; |
if (ufs_blkatoff(vp, (off_t)blkoff, |
if (ufs_blkatoff(vp, (off_t)blkoff, |
NULL, &bp, true) != 0) |
NULL, &bp, true) != 0) { |
|
DIRHASH_UNLOCK(dh); |
return (EJUSTRETURN); |
return (EJUSTRETURN); |
|
} |
} |
} |
dp = (struct direct *)((char *)bp->b_data + (offset & bmask)); |
dp = (struct direct *)((char *)bp->b_data + (offset & bmask)); |
if (dp->d_reclen == 0 || dp->d_reclen > |
if (dp->d_reclen == 0 || dp->d_reclen > |
dirblksiz - (offset & (dirblksiz - 1))) { |
dirblksiz - (offset & (dirblksiz - 1))) { |
/* Corrupted directory. */ |
/* Corrupted directory. */ |
|
DIRHASH_UNLOCK(dh); |
brelse(bp, 0); |
brelse(bp, 0); |
return (EJUSTRETURN); |
return (EJUSTRETURN); |
} |
} |
|
|
if (dh->dh_seqopt == 0 && dh->dh_seqoff == offset) |
if (dh->dh_seqopt == 0 && dh->dh_seqoff == offset) |
dh->dh_seqopt = 1; |
dh->dh_seqopt = 1; |
dh->dh_seqoff = offset + DIRSIZ(0, dp, needswap); |
dh->dh_seqoff = offset + DIRSIZ(0, dp, needswap); |
|
DIRHASH_UNLOCK(dh); |
|
|
*bpp = bp; |
*bpp = bp; |
*offp = offset; |
*offp = offset; |
return (0); |
return (0); |
} |
} |
|
|
DIRHASH_LOCK(dh); |
|
if (dh->dh_hash == NULL) { |
if (dh->dh_hash == NULL) { |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
if (bp != NULL) |
if (bp != NULL) |
Line 505 ufsdirhash_findfree(struct inode *ip, in |
|
Line 502 ufsdirhash_findfree(struct inode *ip, in |
|
|
|
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return (-1); |
return (-1); |
|
|
DIRHASH_LOCK(dh); |
DIRHASH_LOCK(dh); |
if (dh->dh_hash == NULL) { |
if (dh->dh_hash == NULL) { |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
Line 524 ufsdirhash_findfree(struct inode *ip, in |
|
Line 522 ufsdirhash_findfree(struct inode *ip, in |
|
|
|
KASSERT(dirblock < dh->dh_nblk && |
KASSERT(dirblock < dh->dh_nblk && |
dh->dh_blkfree[dirblock] >= howmany(slotneeded, DIRALIGN)); |
dh->dh_blkfree[dirblock] >= howmany(slotneeded, DIRALIGN)); |
DIRHASH_UNLOCK(dh); |
|
pos = dirblock * dirblksiz; |
pos = dirblock * dirblksiz; |
error = ufs_blkatoff(ip->i_vnode, (off_t)pos, (void *)&dp, &bp, false); |
error = ufs_blkatoff(ip->i_vnode, (off_t)pos, (void *)&dp, &bp, false); |
if (error) |
if (error) { |
|
DIRHASH_UNLOCK(dh); |
return (-1); |
return (-1); |
|
} |
/* Find the first entry with free space. */ |
/* Find the first entry with free space. */ |
for (i = 0; i < dirblksiz; ) { |
for (i = 0; i < dirblksiz; ) { |
if (dp->d_reclen == 0) { |
if (dp->d_reclen == 0) { |
|
DIRHASH_UNLOCK(dh); |
brelse(bp, 0); |
brelse(bp, 0); |
return (-1); |
return (-1); |
} |
} |
Line 541 ufsdirhash_findfree(struct inode *ip, in |
|
Line 541 ufsdirhash_findfree(struct inode *ip, in |
|
dp = (struct direct *)((char *)dp + dp->d_reclen); |
dp = (struct direct *)((char *)dp + dp->d_reclen); |
} |
} |
if (i > dirblksiz) { |
if (i > dirblksiz) { |
|
DIRHASH_UNLOCK(dh); |
brelse(bp, 0); |
brelse(bp, 0); |
return (-1); |
return (-1); |
} |
} |
Line 553 ufsdirhash_findfree(struct inode *ip, in |
|
Line 554 ufsdirhash_findfree(struct inode *ip, in |
|
if (dp->d_ino != 0) |
if (dp->d_ino != 0) |
freebytes -= DIRSIZ(0, dp, needswap); |
freebytes -= DIRSIZ(0, dp, needswap); |
if (dp->d_reclen == 0) { |
if (dp->d_reclen == 0) { |
|
DIRHASH_UNLOCK(dh); |
brelse(bp, 0); |
brelse(bp, 0); |
return (-1); |
return (-1); |
} |
} |
Line 560 ufsdirhash_findfree(struct inode *ip, in |
|
Line 562 ufsdirhash_findfree(struct inode *ip, in |
|
dp = (struct direct *)((char *)dp + dp->d_reclen); |
dp = (struct direct *)((char *)dp + dp->d_reclen); |
} |
} |
if (i > dirblksiz) { |
if (i > dirblksiz) { |
|
DIRHASH_UNLOCK(dh); |
brelse(bp, 0); |
brelse(bp, 0); |
return (-1); |
return (-1); |
} |
} |
if (freebytes < slotneeded) |
if (freebytes < slotneeded) |
panic("ufsdirhash_findfree: free mismatch"); |
panic("ufsdirhash_findfree: free mismatch"); |
|
DIRHASH_UNLOCK(dh); |
brelse(bp, 0); |
brelse(bp, 0); |
*slotsize = pos + i - slotstart; |
*slotsize = pos + i - slotstart; |
return (slotstart); |
return (slotstart); |
Line 583 ufsdirhash_enduseful(struct inode *ip) |
|
Line 587 ufsdirhash_enduseful(struct inode *ip) |
|
|
|
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return (-1); |
return (-1); |
|
|
DIRHASH_LOCK(dh); |
DIRHASH_LOCK(dh); |
if (dh->dh_hash == NULL) { |
if (dh->dh_hash == NULL) { |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
Line 617 ufsdirhash_add(struct inode *ip, struct |
|
Line 622 ufsdirhash_add(struct inode *ip, struct |
|
|
|
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return; |
return; |
|
|
DIRHASH_LOCK(dh); |
DIRHASH_LOCK(dh); |
if (dh->dh_hash == NULL) { |
if (dh->dh_hash == NULL) { |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
Line 663 ufsdirhash_remove(struct inode *ip, stru |
|
Line 669 ufsdirhash_remove(struct inode *ip, stru |
|
|
|
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return; |
return; |
|
|
DIRHASH_LOCK(dh); |
DIRHASH_LOCK(dh); |
if (dh->dh_hash == NULL) { |
if (dh->dh_hash == NULL) { |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
Line 759 ufsdirhash_dirtrunc(struct inode *ip, do |
|
Line 766 ufsdirhash_dirtrunc(struct inode *ip, do |
|
|
|
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return; |
return; |
|
|
DIRHASH_LOCK(dh); |
DIRHASH_LOCK(dh); |
if (dh->dh_hash == NULL) { |
if (dh->dh_hash == NULL) { |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
Line 819 ufsdirhash_checkblock(struct inode *ip, |
|
Line 827 ufsdirhash_checkblock(struct inode *ip, |
|
return; |
return; |
if ((dh = ip->i_dirhash) == NULL) |
if ((dh = ip->i_dirhash) == NULL) |
return; |
return; |
|
|
DIRHASH_LOCK(dh); |
DIRHASH_LOCK(dh); |
if (dh->dh_hash == NULL) { |
if (dh->dh_hash == NULL) { |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
Line 903 ufsdirhash_adjfree(struct dirhash *dh, d |
|
Line 912 ufsdirhash_adjfree(struct dirhash *dh, d |
|
{ |
{ |
int block, i, nfidx, ofidx; |
int block, i, nfidx, ofidx; |
|
|
|
KASSERT(mutex_owned(&dh->dh_lock)); |
|
|
/* Update the per-block summary info. */ |
/* Update the per-block summary info. */ |
block = offset / dirblksiz; |
block = offset / dirblksiz; |
KASSERT(block < dh->dh_nblk && block < dh->dh_dirblks); |
KASSERT(block < dh->dh_nblk && block < dh->dh_dirblks); |
Line 1026 ufsdirhash_recycle(int wanted) |
|
Line 1037 ufsdirhash_recycle(int wanted) |
|
doff_t **hash; |
doff_t **hash; |
u_int8_t *blkfree; |
u_int8_t *blkfree; |
int i, mem, narrays; |
int i, mem, narrays; |
|
size_t hashsz, blkfreesz; |
|
|
DIRHASHLIST_LOCK(); |
DIRHASHLIST_LOCK(); |
while (wanted + ufs_dirhashmem > ufs_dirhashmaxmem) { |
while (wanted + ufs_dirhashmem > ufs_dirhashmaxmem) { |
Line 1048 ufsdirhash_recycle(int wanted) |
|
Line 1060 ufsdirhash_recycle(int wanted) |
|
TAILQ_REMOVE(&ufsdirhash_list, dh, dh_list); |
TAILQ_REMOVE(&ufsdirhash_list, dh, dh_list); |
dh->dh_onlist = 0; |
dh->dh_onlist = 0; |
hash = dh->dh_hash; |
hash = dh->dh_hash; |
|
hashsz = dh->dh_hashsz; |
dh->dh_hash = NULL; |
dh->dh_hash = NULL; |
blkfree = dh->dh_blkfree; |
blkfree = dh->dh_blkfree; |
|
blkfreesz = dh->dh_blkfreesz; |
dh->dh_blkfree = NULL; |
dh->dh_blkfree = NULL; |
narrays = dh->dh_narrays; |
narrays = dh->dh_narrays; |
mem = narrays * sizeof(*dh->dh_hash) + |
mem = narrays * sizeof(*dh->dh_hash) + |
Line 1059 ufsdirhash_recycle(int wanted) |
|
Line 1073 ufsdirhash_recycle(int wanted) |
|
/* Unlock everything, free the detached memory. */ |
/* Unlock everything, free the detached memory. */ |
DIRHASH_UNLOCK(dh); |
DIRHASH_UNLOCK(dh); |
DIRHASHLIST_UNLOCK(); |
DIRHASHLIST_UNLOCK(); |
|
|
for (i = 0; i < narrays; i++) |
for (i = 0; i < narrays; i++) |
DIRHASH_BLKFREE(hash[i]); |
DIRHASH_BLKFREE(hash[i]); |
FREE(hash, M_DIRHASH); |
kmem_free(hash, hashsz); |
FREE(blkfree, M_DIRHASH); |
kmem_free(blkfree, blkfreesz); |
|
|
/* Account for the returned memory, and repeat if necessary. */ |
/* Account for the returned memory, and repeat if necessary. */ |
DIRHASHLIST_LOCK(); |
DIRHASHLIST_LOCK(); |
ufs_dirhashmem -= mem; |
ufs_dirhashmem -= mem; |
} |
} |
/* Success; return with list locked. */ |
/* Success. */ |
return (0); |
return (0); |
} |
} |
|
|
Line 1077 ufsdirhash_init() |
|
Line 1092 ufsdirhash_init() |
|
{ |
{ |
|
|
mutex_init(&ufsdirhash_lock, MUTEX_DEFAULT, IPL_NONE); |
mutex_init(&ufsdirhash_lock, MUTEX_DEFAULT, IPL_NONE); |
malloc_type_attach(M_DIRHASH); |
ufsdirhashblk_cache = pool_cache_init(DH_NBLKOFF * sizeof(daddr_t), 0, |
ufsdirhash_cache = pool_cache_init(DH_NBLKOFF * sizeof(daddr_t), 0, |
0, 0, "dirhashblk", NULL, IPL_NONE, NULL, NULL, NULL); |
0, 0, "ufsdirhash", NULL, IPL_NONE, NULL, NULL, NULL); |
ufsdirhash_cache = pool_cache_init(sizeof(struct dirhash), 0, |
|
0, 0, "dirhash", NULL, IPL_NONE, NULL, NULL, NULL); |
TAILQ_INIT(&ufsdirhash_list); |
TAILQ_INIT(&ufsdirhash_list); |
} |
} |
|
|
Line 1088 ufsdirhash_done(void) |
|
Line 1104 ufsdirhash_done(void) |
|
{ |
{ |
|
|
KASSERT(TAILQ_EMPTY(&ufsdirhash_list)); |
KASSERT(TAILQ_EMPTY(&ufsdirhash_list)); |
|
pool_cache_destroy(ufsdirhashblk_cache); |
pool_cache_destroy(ufsdirhash_cache); |
pool_cache_destroy(ufsdirhash_cache); |
malloc_type_detach(M_DIRHASH); |
|
mutex_destroy(&ufsdirhash_lock); |
mutex_destroy(&ufsdirhash_lock); |
} |
} |
|
|