From 34e2fb3bb655b79fc2b93e1ad69187508a91c479 Mon Sep 17 00:00:00 2001 From: thorpej Date: Wed, 6 Nov 1996 03:02:59 +0000 Subject: [PATCH] Performance enhancement from Kirk McKusick : When freeing an indirect block, there is no need to write it (synchronously, no less!) before tossing it. --- sys/ufs/ffs/ffs_inode.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c index 520625957f2d..1593e55e1777 100644 --- a/sys/ufs/ffs/ffs_inode.c +++ b/sys/ufs/ffs/ffs_inode.c @@ -1,4 +1,4 @@ -/* $NetBSD: ffs_inode.c,v 1.11 1996/09/01 23:49:21 mycroft Exp $ */ +/* $NetBSD: ffs_inode.c,v 1.12 1996/11/06 03:02:59 thorpej Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -397,7 +397,7 @@ ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp) register struct fs *fs = ip->i_fs; register daddr_t *bap; struct vnode *vp; - daddr_t *copy, nb, nlbn, last; + daddr_t *copy = NULL, nb, nlbn, last; long blkcount, factor; int nblocks, blocksreleased = 0; int error = 0, allerror = 0; @@ -444,16 +444,16 @@ ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp) } bap = (daddr_t *)bp->b_data; - MALLOC(copy, daddr_t *, fs->fs_bsize, M_TEMP, M_WAITOK); - bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->fs_bsize); - bzero((caddr_t)&bap[last + 1], - (u_int)(NINDIR(fs) - (last + 1)) * sizeof (daddr_t)); - if (last == -1) - bp->b_flags |= B_INVAL; - error = bwrite(bp); - if (error) - allerror = error; - bap = copy; + if (lastbn != -1) { + MALLOC(copy, daddr_t *, fs->fs_bsize, M_TEMP, M_WAITOK); + bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->fs_bsize); + bzero((caddr_t)&bap[last + 1], + (u_int)(NINDIR(fs) - (last + 1)) * sizeof (daddr_t)); + error = bwrite(bp); + if (error) + allerror = error; + bap = copy; + } /* * Recursively free totally unused blocks. @@ -489,7 +489,14 @@ ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp) blocksreleased += blkcount; } } - FREE(copy, M_TEMP); + + if (copy != NULL) { + FREE(copy, M_TEMP); + } else { + bp->b_flags |= B_INVAL; + brelse(bp); + } + *countp = blocksreleased; return (allerror); }