Re: [Cluster-devel] [PATCH V10 13/19] iomap & xfs: only account for new added page
On Fri, Nov 16, 2018 at 02:49:36PM +0100, Christoph Hellwig wrote: > I'd much rather have __bio_try_merge_page only do merges in > the same page, and have a new __bio_try_merge_segment that does > multi-page merges. This will keep the accounting a lot simpler. Looks this way is clever, will do it in next version. Thanks, Ming
Re: [Cluster-devel] [PATCH V10 13/19] iomap & xfs: only account for new added page
On Thu, Nov 15, 2018 at 05:46:58PM -0800, Omar Sandoval wrote: > On Thu, Nov 15, 2018 at 04:53:00PM +0800, Ming Lei wrote: > > After multi-page is enabled, one new page may be merged to a segment > > even though it is a new added page. > > > > This patch deals with this issue by post-check in case of merge, and > > only a freshly new added page need to be dealt with for iomap & xfs. > > > > Cc: Dave Chinner > > Cc: Kent Overstreet > > Cc: Mike Snitzer > > Cc: dm-de...@redhat.com > > Cc: Alexander Viro > > Cc: linux-fsde...@vger.kernel.org > > Cc: Shaohua Li > > Cc: linux-r...@vger.kernel.org > > Cc: linux-er...@lists.ozlabs.org > > Cc: David Sterba > > Cc: linux-bt...@vger.kernel.org > > Cc: Darrick J. Wong > > Cc: linux-...@vger.kernel.org > > Cc: Gao Xiang > > Cc: Christoph Hellwig > > Cc: Theodore Ts'o > > Cc: linux-e...@vger.kernel.org > > Cc: Coly Li > > Cc: linux-bca...@vger.kernel.org > > Cc: Boaz Harrosh > > Cc: Bob Peterson > > Cc: cluster-devel@redhat.com > > Signed-off-by: Ming Lei > > --- > > fs/iomap.c | 22 ++ > > fs/xfs/xfs_aops.c | 10 -- > > include/linux/bio.h | 11 +++ > > 3 files changed, 33 insertions(+), 10 deletions(-) > > > > diff --git a/fs/iomap.c b/fs/iomap.c > > index df0212560b36..a1b97a5c726a 100644 > > --- a/fs/iomap.c > > +++ b/fs/iomap.c > > @@ -288,6 +288,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, > > loff_t length, void *data, > > loff_t orig_pos = pos; > > unsigned poff, plen; > > sector_t sector; > > + bool need_account = false; > > > > if (iomap->type == IOMAP_INLINE) { > > WARN_ON_ONCE(pos); > > @@ -313,18 +314,15 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, > > loff_t length, void *data, > > */ > > sector = iomap_sector(iomap, pos); > > if (ctx->bio && bio_end_sector(ctx->bio) == sector) { > > - if (__bio_try_merge_page(ctx->bio, page, plen, poff)) > > + if (__bio_try_merge_page(ctx->bio, page, plen, poff)) { > > + need_account = iop && bio_is_last_segment(ctx->bio, > > + page, plen, poff); > > It's redundant to make this iop && ... since you already check > iop && need_account below. Maybe rename it to added_page? Also, this > indentation is wack. We may avoid to call bio_is_last_segment() in case of !iop, and will fix the indentation. Looks added_page is one better name. > > > goto done; > > + } > > is_contig = true; > > } > > > > - /* > > -* If we start a new segment we need to increase the read count, and we > > -* need to do so before submitting any previous full bio to make sure > > -* that we don't prematurely unlock the page. > > -*/ > > - if (iop) > > - atomic_inc(&iop->read_count); > > + need_account = true; > > > > if (!ctx->bio || !is_contig || bio_full(ctx->bio)) { > > gfp_t gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL); > > @@ -347,6 +345,14 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, > > loff_t length, void *data, > > __bio_add_page(ctx->bio, page, plen, poff); > > done: > > /* > > +* If we add a new page we need to increase the read count, and we > > +* need to do so before submitting any previous full bio to make sure > > +* that we don't prematurely unlock the page. > > +*/ > > + if (iop && need_account) > > + atomic_inc(&iop->read_count); > > + > > + /* > > * Move the caller beyond our range so that it keeps making progress. > > * For that we have to include any leading non-uptodate ranges, but > > * we can skip trailing ones as they will be handled in the next > > diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c > > index 1f1829e506e8..d8e9cc9f751a 100644 > > --- a/fs/xfs/xfs_aops.c > > +++ b/fs/xfs/xfs_aops.c > > @@ -603,6 +603,7 @@ xfs_add_to_ioend( > > unsignedlen = i_blocksize(inode); > > unsignedpoff = offset & (PAGE_SIZE - 1); > > sector_tsector; > > + boolneed_account; > > > > sector = xfs_fsb_to_db(ip, wpc->imap.br_startblock) + > > ((offset - XFS_FSB_TO_B(mp, wpc->imap.br_startoff)) >> 9); > > @@ -617,13 +618,18 @@ xfs_add_to_ioend( > > } > > > > if (!__bio_try_merge_page(wpc->ioend->io_bio, page, len, poff)) { > > - if (iop) > > - atomic_inc(&iop->write_count); > > + need_account = true; > > if (bio_full(wpc->ioend->io_bio)) > > xfs_chain_bio(wpc->ioend, wbc, bdev, sector); > > __bio_add_page(wpc->ioend->io_bio, page, len, poff); > > + } else { > > + need_account = iop && bio_is_last_segment(wpc->ioend->io_bio, > > + page, len, poff); > > Same here, no need for iop &&, rename it added_page, indentation is off. > > > }
Re: [Cluster-devel] [PATCH V10 13/19] iomap & xfs: only account for new added page
I'd much rather have __bio_try_merge_page only do merges in the same page, and have a new __bio_try_merge_segment that does multi-page merges. This will keep the accounting a lot simpler.
Re: [Cluster-devel] [PATCH V10 13/19] iomap & xfs: only account for new added page
On Thu, Nov 15, 2018 at 04:53:00PM +0800, Ming Lei wrote: > After multi-page is enabled, one new page may be merged to a segment > even though it is a new added page. > > This patch deals with this issue by post-check in case of merge, and > only a freshly new added page need to be dealt with for iomap & xfs. > > Cc: Dave Chinner > Cc: Kent Overstreet > Cc: Mike Snitzer > Cc: dm-de...@redhat.com > Cc: Alexander Viro > Cc: linux-fsde...@vger.kernel.org > Cc: Shaohua Li > Cc: linux-r...@vger.kernel.org > Cc: linux-er...@lists.ozlabs.org > Cc: David Sterba > Cc: linux-bt...@vger.kernel.org > Cc: Darrick J. Wong > Cc: linux-...@vger.kernel.org > Cc: Gao Xiang > Cc: Christoph Hellwig > Cc: Theodore Ts'o > Cc: linux-e...@vger.kernel.org > Cc: Coly Li > Cc: linux-bca...@vger.kernel.org > Cc: Boaz Harrosh > Cc: Bob Peterson > Cc: cluster-devel@redhat.com > Signed-off-by: Ming Lei > --- > fs/iomap.c | 22 ++ > fs/xfs/xfs_aops.c | 10 -- > include/linux/bio.h | 11 +++ > 3 files changed, 33 insertions(+), 10 deletions(-) > > diff --git a/fs/iomap.c b/fs/iomap.c > index df0212560b36..a1b97a5c726a 100644 > --- a/fs/iomap.c > +++ b/fs/iomap.c > @@ -288,6 +288,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, > loff_t length, void *data, > loff_t orig_pos = pos; > unsigned poff, plen; > sector_t sector; > + bool need_account = false; > > if (iomap->type == IOMAP_INLINE) { > WARN_ON_ONCE(pos); > @@ -313,18 +314,15 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, > loff_t length, void *data, >*/ > sector = iomap_sector(iomap, pos); > if (ctx->bio && bio_end_sector(ctx->bio) == sector) { > - if (__bio_try_merge_page(ctx->bio, page, plen, poff)) > + if (__bio_try_merge_page(ctx->bio, page, plen, poff)) { > + need_account = iop && bio_is_last_segment(ctx->bio, > + page, plen, poff); It's redundant to make this iop && ... since you already check iop && need_account below. Maybe rename it to added_page? Also, this indentation is wack. > goto done; > + } > is_contig = true; > } > > - /* > - * If we start a new segment we need to increase the read count, and we > - * need to do so before submitting any previous full bio to make sure > - * that we don't prematurely unlock the page. > - */ > - if (iop) > - atomic_inc(&iop->read_count); > + need_account = true; > > if (!ctx->bio || !is_contig || bio_full(ctx->bio)) { > gfp_t gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL); > @@ -347,6 +345,14 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, > loff_t length, void *data, > __bio_add_page(ctx->bio, page, plen, poff); > done: > /* > + * If we add a new page we need to increase the read count, and we > + * need to do so before submitting any previous full bio to make sure > + * that we don't prematurely unlock the page. > + */ > + if (iop && need_account) > + atomic_inc(&iop->read_count); > + > + /* >* Move the caller beyond our range so that it keeps making progress. >* For that we have to include any leading non-uptodate ranges, but >* we can skip trailing ones as they will be handled in the next > diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c > index 1f1829e506e8..d8e9cc9f751a 100644 > --- a/fs/xfs/xfs_aops.c > +++ b/fs/xfs/xfs_aops.c > @@ -603,6 +603,7 @@ xfs_add_to_ioend( > unsignedlen = i_blocksize(inode); > unsignedpoff = offset & (PAGE_SIZE - 1); > sector_tsector; > + boolneed_account; > > sector = xfs_fsb_to_db(ip, wpc->imap.br_startblock) + > ((offset - XFS_FSB_TO_B(mp, wpc->imap.br_startoff)) >> 9); > @@ -617,13 +618,18 @@ xfs_add_to_ioend( > } > > if (!__bio_try_merge_page(wpc->ioend->io_bio, page, len, poff)) { > - if (iop) > - atomic_inc(&iop->write_count); > + need_account = true; > if (bio_full(wpc->ioend->io_bio)) > xfs_chain_bio(wpc->ioend, wbc, bdev, sector); > __bio_add_page(wpc->ioend->io_bio, page, len, poff); > + } else { > + need_account = iop && bio_is_last_segment(wpc->ioend->io_bio, > + page, len, poff); Same here, no need for iop &&, rename it added_page, indentation is off. > } > > + if (iop && need_account) > + atomic_inc(&iop->write_count); > + > wpc->ioend->io_size += len; > } > > diff --git a/include/linux/bio.h b/include/linux/bio.h > index 1a2430a8b89d..5040e9a2eb09 100644 > --- a/include/linux/bio.h > +++ b/include/linux/bio.h > @@ -341,6 +341,17 @@ static inline st
[Cluster-devel] [PATCH V10 13/19] iomap & xfs: only account for new added page
After multi-page is enabled, one new page may be merged to a segment even though it is a new added page. This patch deals with this issue by post-check in case of merge, and only a freshly new added page need to be dealt with for iomap & xfs. Cc: Dave Chinner Cc: Kent Overstreet Cc: Mike Snitzer Cc: dm-de...@redhat.com Cc: Alexander Viro Cc: linux-fsde...@vger.kernel.org Cc: Shaohua Li Cc: linux-r...@vger.kernel.org Cc: linux-er...@lists.ozlabs.org Cc: David Sterba Cc: linux-bt...@vger.kernel.org Cc: Darrick J. Wong Cc: linux-...@vger.kernel.org Cc: Gao Xiang Cc: Christoph Hellwig Cc: Theodore Ts'o Cc: linux-e...@vger.kernel.org Cc: Coly Li Cc: linux-bca...@vger.kernel.org Cc: Boaz Harrosh Cc: Bob Peterson Cc: cluster-devel@redhat.com Signed-off-by: Ming Lei --- fs/iomap.c | 22 ++ fs/xfs/xfs_aops.c | 10 -- include/linux/bio.h | 11 +++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index df0212560b36..a1b97a5c726a 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -288,6 +288,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, loff_t orig_pos = pos; unsigned poff, plen; sector_t sector; + bool need_account = false; if (iomap->type == IOMAP_INLINE) { WARN_ON_ONCE(pos); @@ -313,18 +314,15 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, */ sector = iomap_sector(iomap, pos); if (ctx->bio && bio_end_sector(ctx->bio) == sector) { - if (__bio_try_merge_page(ctx->bio, page, plen, poff)) + if (__bio_try_merge_page(ctx->bio, page, plen, poff)) { + need_account = iop && bio_is_last_segment(ctx->bio, + page, plen, poff); goto done; + } is_contig = true; } - /* -* If we start a new segment we need to increase the read count, and we -* need to do so before submitting any previous full bio to make sure -* that we don't prematurely unlock the page. -*/ - if (iop) - atomic_inc(&iop->read_count); + need_account = true; if (!ctx->bio || !is_contig || bio_full(ctx->bio)) { gfp_t gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL); @@ -347,6 +345,14 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, __bio_add_page(ctx->bio, page, plen, poff); done: /* +* If we add a new page we need to increase the read count, and we +* need to do so before submitting any previous full bio to make sure +* that we don't prematurely unlock the page. +*/ + if (iop && need_account) + atomic_inc(&iop->read_count); + + /* * Move the caller beyond our range so that it keeps making progress. * For that we have to include any leading non-uptodate ranges, but * we can skip trailing ones as they will be handled in the next diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 1f1829e506e8..d8e9cc9f751a 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -603,6 +603,7 @@ xfs_add_to_ioend( unsignedlen = i_blocksize(inode); unsignedpoff = offset & (PAGE_SIZE - 1); sector_tsector; + boolneed_account; sector = xfs_fsb_to_db(ip, wpc->imap.br_startblock) + ((offset - XFS_FSB_TO_B(mp, wpc->imap.br_startoff)) >> 9); @@ -617,13 +618,18 @@ xfs_add_to_ioend( } if (!__bio_try_merge_page(wpc->ioend->io_bio, page, len, poff)) { - if (iop) - atomic_inc(&iop->write_count); + need_account = true; if (bio_full(wpc->ioend->io_bio)) xfs_chain_bio(wpc->ioend, wbc, bdev, sector); __bio_add_page(wpc->ioend->io_bio, page, len, poff); + } else { + need_account = iop && bio_is_last_segment(wpc->ioend->io_bio, + page, len, poff); } + if (iop && need_account) + atomic_inc(&iop->write_count); + wpc->ioend->io_size += len; } diff --git a/include/linux/bio.h b/include/linux/bio.h index 1a2430a8b89d..5040e9a2eb09 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -341,6 +341,17 @@ static inline struct bio_vec *bio_last_bvec_all(struct bio *bio) return &bio->bi_io_vec[bio->bi_vcnt - 1]; } +/* iomap needs this helper to deal with sub-pagesize bvec */ +static inline bool bio_is_last_segment(struct bio *bio, struct page *page, + unsigned int len, unsigned int off) +{ + struct bio_vec bv; + + bvec_last_segment(bio_last_bvec_all(bio), &bv); + + return bv.bv_page == page &&