From 127ab960d5e107837105af12ebf0da8e904002e6 Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Tue, 22 Oct 2002 01:14:25 +0000 Subject: [PATCH] This update is a performance improvement when allocating blocks on a full filesystem. Previously, if the allocation failed, we had to fsync the file before rolling back any partial allocation of indirect blocks. Most block allocation requests only need to allocate a single data block and if that allocation fails, there is nothing to unroll. So, before doing the fsync, we check to see if any rollback will really be necessary. If none is necessary, then we simply return. This update eliminates the flurry of disk activity that got triggered whenever a filesystem would run out of space. Sponsored by: DARPA & NAI Labs. --- sys/ufs/ffs/ffs_balloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/ufs/ffs/ffs_balloc.c b/sys/ufs/ffs/ffs_balloc.c index 4256f9777301..1f88bcf357ea 100644 --- a/sys/ufs/ffs/ffs_balloc.c +++ b/sys/ufs/ffs/ffs_balloc.c @@ -360,6 +360,12 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, *bpp = nbp; return (0); fail: + /* + * If we have failed to allocate any blocks, simply return the error. + * This is the usual case and avoids the need to fsync the file. + */ + if (allocblk == allociblk && allocib == NULL && unwindidx == -1) + return (error); /* * If we have failed part way through block allocation, we * have to deallocate any indirect blocks that we have allocated. @@ -821,6 +827,12 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, *bpp = nbp; return (0); fail: + /* + * If we have failed to allocate any blocks, simply return the error. + * This is the usual case and avoids the need to fsync the file. + */ + if (allocblk == allociblk && allocib == NULL && unwindidx == -1) + return (error); /* * If we have failed part way through block allocation, we * have to deallocate any indirect blocks that we have allocated.