aboutsummaryrefslogtreecommitdiffstats
path: root/fs/buffer.c
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2014-10-09 18:26:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:25:53 -0400
commit59d43914ed7b96255271ad6b7b735344beffa3c0 (patch)
tree83497d5e1b25c77fc222d5845b584c258857fde5 /fs/buffer.c
parent21bb9bd19430a43e6462ce75030fd7fac4b766ef (diff)
vfs: make guard_bh_eod() more generic
This patchset implements readpages() operation for block device by using mpage_readpages() which can create multipage BIOs instead of BIOs for each page and reduce system CPU time consumption. This patch (of 3): guard_bh_eod() is used in submit_bh() to allow us to do IO even on the odd last sectors of a device, even if the block size is some multiple of the physical sector size. This makes guard_bh_eod() more generic and renames it guard_bio_eod() so that we can use it without struct buffer_head argument. The reason for this change is that using mpage_readpages() for block device requires to add this guard check in mpage code. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/buffer.c')
-rw-r--r--fs/buffer.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/fs/buffer.c b/fs/buffer.c
index 3588a80854b2..e442a26e80f7 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2956,7 +2956,7 @@ static void end_bio_bh_io_sync(struct bio *bio, int err)
2956 2956
2957/* 2957/*
2958 * This allows us to do IO even on the odd last sectors 2958 * This allows us to do IO even on the odd last sectors
2959 * of a device, even if the bh block size is some multiple 2959 * of a device, even if the block size is some multiple
2960 * of the physical sector size. 2960 * of the physical sector size.
2961 * 2961 *
2962 * We'll just truncate the bio to the size of the device, 2962 * We'll just truncate the bio to the size of the device,
@@ -2966,10 +2966,11 @@ static void end_bio_bh_io_sync(struct bio *bio, int err)
2966 * errors, this only handles the "we need to be able to 2966 * errors, this only handles the "we need to be able to
2967 * do IO at the final sector" case. 2967 * do IO at the final sector" case.
2968 */ 2968 */
2969static void guard_bh_eod(int rw, struct bio *bio, struct buffer_head *bh) 2969static void guard_bio_eod(int rw, struct bio *bio)
2970{ 2970{
2971 sector_t maxsector; 2971 sector_t maxsector;
2972 unsigned bytes; 2972 struct bio_vec *bvec = &bio->bi_io_vec[bio->bi_vcnt - 1];
2973 unsigned truncated_bytes;
2973 2974
2974 maxsector = i_size_read(bio->bi_bdev->bd_inode) >> 9; 2975 maxsector = i_size_read(bio->bi_bdev->bd_inode) >> 9;
2975 if (!maxsector) 2976 if (!maxsector)
@@ -2984,23 +2985,20 @@ static void guard_bh_eod(int rw, struct bio *bio, struct buffer_head *bh)
2984 return; 2985 return;
2985 2986
2986 maxsector -= bio->bi_iter.bi_sector; 2987 maxsector -= bio->bi_iter.bi_sector;
2987 bytes = bio->bi_iter.bi_size; 2988 if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
2988 if (likely((bytes >> 9) <= maxsector))
2989 return; 2989 return;
2990 2990
2991 /* Uhhuh. We've got a bh that straddles the device size! */ 2991 /* Uhhuh. We've got a bio that straddles the device size! */
2992 bytes = maxsector << 9; 2992 truncated_bytes = bio->bi_iter.bi_size - (maxsector << 9);
2993 2993
2994 /* Truncate the bio.. */ 2994 /* Truncate the bio.. */
2995 bio->bi_iter.bi_size = bytes; 2995 bio->bi_iter.bi_size -= truncated_bytes;
2996 bio->bi_io_vec[0].bv_len = bytes; 2996 bvec->bv_len -= truncated_bytes;
2997 2997
2998 /* ..and clear the end of the buffer for reads */ 2998 /* ..and clear the end of the buffer for reads */
2999 if ((rw & RW_MASK) == READ) { 2999 if ((rw & RW_MASK) == READ) {
3000 void *kaddr = kmap_atomic(bh->b_page); 3000 zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len,
3001 memset(kaddr + bh_offset(bh) + bytes, 0, bh->b_size - bytes); 3001 truncated_bytes);
3002 kunmap_atomic(kaddr);
3003 flush_dcache_page(bh->b_page);
3004 } 3002 }
3005} 3003}
3006 3004
@@ -3041,7 +3039,7 @@ int _submit_bh(int rw, struct buffer_head *bh, unsigned long bio_flags)
3041 bio->bi_flags |= bio_flags; 3039 bio->bi_flags |= bio_flags;
3042 3040
3043 /* Take care of bh's that straddle the end of the device */ 3041 /* Take care of bh's that straddle the end of the device */
3044 guard_bh_eod(rw, bio, bh); 3042 guard_bio_eod(rw, bio);
3045 3043
3046 if (buffer_meta(bh)) 3044 if (buffer_meta(bh))
3047 rw |= REQ_META; 3045 rw |= REQ_META;