Re: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations
Hi, > -Original Message- > From: Jaegeuk Kim [mailto:jaegeuk@samsung.com] > Sent: Wednesday, December 04, 2013 4:11 PM > To: Chao Yu > Cc: linux-ker...@vger.kernel.org; linux-f2fs-devel@lists.sourceforge.net; > linux-fsde...@vger.kernel.org; 谭姝 > Subject: RE: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations > > Hi, > > > > + if (btype == META) > > > + rw |= REQ_META; > > > + > > > + if (is_read_io(rw)) { > > > + if (sync) > > > + rw |= READ_SYNC; > > > + submit_bio(rw, io->bio); > > > + trace_f2fs_submit_read_bio(sbi->sb, rw, type, io->bio); > > > + io->bio = NULL; > > > + return; > > > + } > > > + > > > + if (sync) > > > + rw |= WRITE_SYNC; > > > > rw = WRITE_SYNC; ? > > No, since it removes the REQ_META. > See above. Ah, you're right, Thanks. > > > > > > + if (type >= META_FLUSH) > > > + rw |= WRITE_FLUSH_FUA; > > > > rw = WRITE_FLUSH_FUA; ? > > > > > + > > > + /* > > > + * META_FLUSH is only from the checkpoint procedure, and we should wait > > > + * this metadata bio for FS consistency. > > > + */ > > > + if (type == META_FLUSH) { > > > + DECLARE_COMPLETION_ONSTACK(wait); > > > + io->bio->bi_private = &wait; > > > + submit_bio(rw, io->bio); > > > + wait_for_completion(&wait); > > > + } else { > > > + submit_bio(rw, io->bio); > > > + } > > > + trace_f2fs_submit_write_bio(sbi->sb, rw, btype, io->bio); > > > + io->bio = NULL; > > > +} > > > > [snip] > > > > Thanks, > > Yu > > > > -- > Jaegeuk Kim > Samsung -- Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations
Hi, > > + if (btype == META) > > + rw |= REQ_META; > > + > > + if (is_read_io(rw)) { > > + if (sync) > > + rw |= READ_SYNC; > > + submit_bio(rw, io->bio); > > + trace_f2fs_submit_read_bio(sbi->sb, rw, type, io->bio); > > + io->bio = NULL; > > + return; > > + } > > + > > + if (sync) > > + rw |= WRITE_SYNC; > > rw = WRITE_SYNC; ? No, since it removes the REQ_META. See above. > > > + if (type >= META_FLUSH) > > + rw |= WRITE_FLUSH_FUA; > > rw = WRITE_FLUSH_FUA; ? > > > + > > + /* > > +* META_FLUSH is only from the checkpoint procedure, and we should wait > > +* this metadata bio for FS consistency. > > +*/ > > + if (type == META_FLUSH) { > > + DECLARE_COMPLETION_ONSTACK(wait); > > + io->bio->bi_private = &wait; > > + submit_bio(rw, io->bio); > > + wait_for_completion(&wait); > > + } else { > > + submit_bio(rw, io->bio); > > + } > > + trace_f2fs_submit_write_bio(sbi->sb, rw, btype, io->bio); > > + io->bio = NULL; > > +} > > [snip] > > Thanks, > Yu > -- Jaegeuk Kim Samsung -- Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations
Hi, Comment as following. > -Original Message- > From: Jaegeuk Kim [mailto:jaegeuk@samsung.com] > Sent: Monday, December 02, 2013 4:27 PM > To: linux-fsde...@vger.kernel.org > Cc: linux-ker...@vger.kernel.org; linux-f2fs-devel@lists.sourceforge.net > Subject: Re: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations > > Change log from v1: > o remove redundant codes > > >From a480dfc915490f4bca7275f6fbb44fa34aa00eaa Mon Sep 17 00:00:00 2001 > From: Jaegeuk Kim > Date: Sat, 30 Nov 2013 12:51:14 +0900 > Subject: [PATCH] f2fs: refactor bio-related operations > Cc: linux-fsde...@vger.kernel.org, linux-ker...@vger.kernel.org, > linux-f2fs-devel@lists.sourceforge.net > > This patch integrates redundant bio operations on read and write IOs. > > 1. Move bio-related codes to the top of data.c. > 2. Replace f2fs_submit_bio with f2fs_submit_merged_bio, which handles read >bios additionally. > 3. Introduce __submit_merged_bio to submit the merged bio. > 4. Change f2fs_readpage to f2fs_submit_page_bio. > 5. Introduce f2fs_submit_page_mbio to integrate previous submit_read_page and >submit_write_page. [snip] > +static void __submit_merged_bio(struct f2fs_sb_info *sbi, > + struct f2fs_bio_info *io, > + enum page_type type, bool sync, int rw) > +{ > + enum page_type btype = PAGE_TYPE_OF_BIO(type); > + > + if (!io->bio) > + return; > + > + if (btype == META) > + rw |= REQ_META; > + > + if (is_read_io(rw)) { > + if (sync) > + rw |= READ_SYNC; > + submit_bio(rw, io->bio); > + trace_f2fs_submit_read_bio(sbi->sb, rw, type, io->bio); > + io->bio = NULL; > + return; > + } > + > + if (sync) > + rw |= WRITE_SYNC; rw = WRITE_SYNC; ? > + if (type >= META_FLUSH) > + rw |= WRITE_FLUSH_FUA; rw = WRITE_FLUSH_FUA; ? > + > + /* > + * META_FLUSH is only from the checkpoint procedure, and we should wait > + * this metadata bio for FS consistency. > + */ > + if (type == META_FLUSH) { > + DECLARE_COMPLETION_ONSTACK(wait); > + io->bio->bi_private = &wait; > + submit_bio(rw, io->bio); > + wait_for_completion(&wait); > + } else { > + submit_bio(rw, io->bio); > + } > + trace_f2fs_submit_write_bio(sbi->sb, rw, btype, io->bio); > + io->bio = NULL; > +} [snip] Thanks, Yu -- Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations
> -Original Message- > From: Jaegeuk Kim [mailto:jaegeuk@samsung.com] > Sent: Monday, December 02, 2013 4:27 PM > To: linux-fsde...@vger.kernel.org > Cc: linux-ker...@vger.kernel.org; linux-f2fs-devel@lists.sourceforge.net > Subject: Re: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations > > Change log from v1: > o remove redundant codes > > >From a480dfc915490f4bca7275f6fbb44fa34aa00eaa Mon Sep 17 00:00:00 2001 > From: Jaegeuk Kim > Date: Sat, 30 Nov 2013 12:51:14 +0900 > Subject: [PATCH] f2fs: refactor bio-related operations > Cc: linux-fsde...@vger.kernel.org, linux-ker...@vger.kernel.org, > linux-f2fs-devel@lists.sourceforge.net > > This patch integrates redundant bio operations on read and write IOs. > > 1. Move bio-related codes to the top of data.c. > 2. Replace f2fs_submit_bio with f2fs_submit_merged_bio, which handles read >bios additionally. > 3. Introduce __submit_merged_bio to submit the merged bio. > 4. Change f2fs_readpage to f2fs_submit_page_bio. > 5. Introduce f2fs_submit_page_mbio to integrate previous submit_read_page and >submit_write_page. Good job! > > Reviewed-by: Gu Zheng > Signed-off-by: Jaegeuk Kim Reviewed-by: Chao Yu > --- > fs/f2fs/checkpoint.c| 14 +- > fs/f2fs/data.c | 316 > +--- > fs/f2fs/f2fs.h | 12 +- > fs/f2fs/gc.c| 2 +- > fs/f2fs/node.c | 14 +- > fs/f2fs/recovery.c | 4 +- > fs/f2fs/segment.c | 164 +++ > include/trace/events/f2fs.h | 30 ++--- > 8 files changed, 257 insertions(+), 299 deletions(-) > > diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c > index 40eea42..38f4a224 100644 > --- a/fs/f2fs/checkpoint.c > +++ b/fs/f2fs/checkpoint.c > @@ -61,7 +61,8 @@ repeat: > if (PageUptodate(page)) > goto out; > > - if (f2fs_readpage(sbi, page, index, READ_SYNC | REQ_META | REQ_PRIO)) > + if (f2fs_submit_page_bio(sbi, page, index, > + READ_SYNC | REQ_META | REQ_PRIO)) > goto repeat; > > lock_page(page); > @@ -157,7 +158,8 @@ long sync_meta_pages(struct f2fs_sb_info *sbi, enum > page_type type, > } > > if (nwritten) > - f2fs_submit_bio(sbi, type, nr_to_write == LONG_MAX); > + f2fs_submit_merged_bio(sbi, type, nr_to_write == LONG_MAX, > + WRITE); > > return nwritten; > } > @@ -590,7 +592,7 @@ retry: >* We should submit bio, since it exists several >* wribacking dentry pages in the freeing inode. >*/ > - f2fs_submit_bio(sbi, DATA, true); > + f2fs_submit_merged_bio(sbi, DATA, true, WRITE); > } > goto retry; > } > @@ -796,9 +798,9 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool > is_umount) > > trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish block_ops"); > > - f2fs_submit_bio(sbi, DATA, true); > - f2fs_submit_bio(sbi, NODE, true); > - f2fs_submit_bio(sbi, META, true); > + f2fs_submit_merged_bio(sbi, DATA, true, WRITE); > + f2fs_submit_merged_bio(sbi, NODE, true, WRITE); > + f2fs_submit_merged_bio(sbi, META, true, WRITE); > > /* >* update checkpoint pack index > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index c9a76f8..4e2fc09 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -25,6 +25,204 @@ > #include > > /* > + * Low-level block read/write IO operations. > + */ > +static struct bio *__bio_alloc(struct block_device *bdev, int npages) > +{ > + struct bio *bio; > + > + /* No failure on bio allocation */ > + bio = bio_alloc(GFP_NOIO, npages); > + bio->bi_bdev = bdev; > + bio->bi_private = NULL; > + return bio; > +} > + > +static void f2fs_read_end_io(struct bio *bio, int err) > +{ > + const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); > + struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; > + > + do { > + struct page *page = bvec->bv_page; > + > + if (--bvec >= bio->bi_io_vec) > + prefetchw(&bvec->bv_page->flags); > + > + if (uptodate) { > + SetPageUptodate(page); > + } else { > + ClearPageUptodate(page); > + SetPageError(page); > + } > + unlock_page(page); > + } while (bvec >= bio
Re: [f2fs-dev] [PATCH v2] f2fs: refactor bio-related operations
Change log from v1: o remove redundant codes >From a480dfc915490f4bca7275f6fbb44fa34aa00eaa Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Sat, 30 Nov 2013 12:51:14 +0900 Subject: [PATCH] f2fs: refactor bio-related operations Cc: linux-fsde...@vger.kernel.org, linux-ker...@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net This patch integrates redundant bio operations on read and write IOs. 1. Move bio-related codes to the top of data.c. 2. Replace f2fs_submit_bio with f2fs_submit_merged_bio, which handles read bios additionally. 3. Introduce __submit_merged_bio to submit the merged bio. 4. Change f2fs_readpage to f2fs_submit_page_bio. 5. Introduce f2fs_submit_page_mbio to integrate previous submit_read_page and submit_write_page. Reviewed-by: Gu Zheng Signed-off-by: Jaegeuk Kim --- fs/f2fs/checkpoint.c| 14 +- fs/f2fs/data.c | 316 +--- fs/f2fs/f2fs.h | 12 +- fs/f2fs/gc.c| 2 +- fs/f2fs/node.c | 14 +- fs/f2fs/recovery.c | 4 +- fs/f2fs/segment.c | 164 +++ include/trace/events/f2fs.h | 30 ++--- 8 files changed, 257 insertions(+), 299 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 40eea42..38f4a224 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -61,7 +61,8 @@ repeat: if (PageUptodate(page)) goto out; - if (f2fs_readpage(sbi, page, index, READ_SYNC | REQ_META | REQ_PRIO)) + if (f2fs_submit_page_bio(sbi, page, index, + READ_SYNC | REQ_META | REQ_PRIO)) goto repeat; lock_page(page); @@ -157,7 +158,8 @@ long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, } if (nwritten) - f2fs_submit_bio(sbi, type, nr_to_write == LONG_MAX); + f2fs_submit_merged_bio(sbi, type, nr_to_write == LONG_MAX, + WRITE); return nwritten; } @@ -590,7 +592,7 @@ retry: * We should submit bio, since it exists several * wribacking dentry pages in the freeing inode. */ - f2fs_submit_bio(sbi, DATA, true); + f2fs_submit_merged_bio(sbi, DATA, true, WRITE); } goto retry; } @@ -796,9 +798,9 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish block_ops"); - f2fs_submit_bio(sbi, DATA, true); - f2fs_submit_bio(sbi, NODE, true); - f2fs_submit_bio(sbi, META, true); + f2fs_submit_merged_bio(sbi, DATA, true, WRITE); + f2fs_submit_merged_bio(sbi, NODE, true, WRITE); + f2fs_submit_merged_bio(sbi, META, true, WRITE); /* * update checkpoint pack index diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c9a76f8..4e2fc09 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -25,6 +25,204 @@ #include /* + * Low-level block read/write IO operations. + */ +static struct bio *__bio_alloc(struct block_device *bdev, int npages) +{ + struct bio *bio; + + /* No failure on bio allocation */ + bio = bio_alloc(GFP_NOIO, npages); + bio->bi_bdev = bdev; + bio->bi_private = NULL; + return bio; +} + +static void f2fs_read_end_io(struct bio *bio, int err) +{ + const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); + struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; + + do { + struct page *page = bvec->bv_page; + + if (--bvec >= bio->bi_io_vec) + prefetchw(&bvec->bv_page->flags); + + if (uptodate) { + SetPageUptodate(page); + } else { + ClearPageUptodate(page); + SetPageError(page); + } + unlock_page(page); + } while (bvec >= bio->bi_io_vec); + + bio_put(bio); +} + +static void f2fs_write_end_io(struct bio *bio, int err) +{ + const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); + struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; + struct f2fs_sb_info *sbi = F2FS_SB(bvec->bv_page->mapping->host->i_sb); + + do { + struct page *page = bvec->bv_page; + + if (--bvec >= bio->bi_io_vec) + prefetchw(&bvec->bv_page->flags); + + if (!uptodate) { + SetPageError(page); + set_bit(AS_EIO, &page->mapping->flags); + set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); + sbi->sb->s_flags |= MS_RDONLY; + } + end_page_writeback(page); + dec_page_count(sbi, F2FS_WRITEBACK); + } while (bvec >= bio->bi_io_vec); + + if (bio->bi_private) +