From 58d250bc297a7b203b5c88431b342a311e3169f0 Mon Sep 17 00:00:00 2001 From: bde Date: Sat, 13 Mar 2004 02:56:27 +0000 Subject: Align the offset in vn_rdwr_inchunks() so that at most the first and the last chunk are misaligned relative to a MAXBSIZE byte boundary. vn_rdwr_inchunks() is used mainly for elf core dumps, and elf sections are usually perfectly misaligned relative to MAXBSIZE, and chunking prevents the file system from doing much realigning. This gives a surprisingly large speedup for core dumps -- from 50 to 13 seconds for a 512MB core dump here. The pessimization was mostly from an interaction of the misalignment with IO_DIRECT. It increased the number of i/o's for each chunk by a factor of 5 (3 writes and 2 read-before-writes instead of 1 write). --- sys/kern/vfs_vnops.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index aa49d6f..e67e22e 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -476,8 +476,18 @@ vn_rdwr_inchunks(rw, vp, base, len, offset, segflg, ioflg, active_cred, int error = 0; do { - int chunk = (len > MAXBSIZE) ? MAXBSIZE : len; + int chunk; + /* + * Force `offset' to a multiple of MAXBSIZE except possibly + * for the first chunk, so that filesystems only need to + * write full blocks except possibly for the first and last + * chunks. + */ + chunk = MAXBSIZE - (uoff_t)offset % MAXBSIZE; + + if (chunk > len) + chunk = len; if (rw != UIO_READ && vp->v_type == VREG) bwillwrite(); error = vn_rdwr(rw, vp, base, chunk, offset, segflg, -- cgit v1.1