From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8036C43441 for ; Fri, 16 Nov 2018 01:47:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74A2C2146D for ; Fri, 16 Nov 2018 01:47:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="tlCSCYlS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74A2C2146D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=osandov.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-btrfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389253AbeKPL5d (ORCPT ); Fri, 16 Nov 2018 06:57:33 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35536 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389172AbeKPL5Y (ORCPT ); Fri, 16 Nov 2018 06:57:24 -0500 Received: by mail-pg1-f194.google.com with SMTP id 32-v6so9851918pgu.2 for ; Thu, 15 Nov 2018 17:47:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eZ7HbQIRxvEcUa8+6JyijRuyQka1DIWraav67RGQvQ8=; b=tlCSCYlSuNpOsZ9EAIWkxk1cOrAxhKZsygh3SHH1cKivG3QGJsktihGTN8ZMhLHTTx PegZpHgHvuv1l7Y0LSp6qHZU0e1RCGeSajz02HzsZ/ccaMVR3Qo4Pj+qS2oQYQ4LP3Uu RF/tvX8GlY/TL46LEXjDThmBzTGWw6hOEUdLZmJ0pu1q6bLzOzSxXIBH1NDfnDySSP56 MH2ejdgdMiL3sS1v82bChpC89XXTrty1BQ0BmOQNw+yJNeBwHiCVLITGeLFwzQoMvVnV R3cUMkf76n9pe/6RS9O5fZsRaxlsNRZOREfIwNVajES+nU+43CE5l0hcLCMvY2an6ik3 n54A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=eZ7HbQIRxvEcUa8+6JyijRuyQka1DIWraav67RGQvQ8=; b=TsWwgsB+yGZd2SNgYCnAGVgudmrY9PgbdPIKIooaCatpMWMqX3LMYQGwEm0489OJGX Bi3d3HczdwAOUZyOYAvJZI6BsUeVNADhgrvylEgwiTbodLQrO7ovBaWgAnhvDGYnuchY t8vebfjwZ9Ig5S5nepgQm5CY6itRaoAGP/ReThvKiGVEj5vJLfp0evx+jaKb9JHQFx8/ bpcz/iLchzWFDRm1z52tU1tvcG80ilbHz8zFDh4DG4leI70KIUk2JweIxvJRrCnBoq01 FyaPLFqK1dpcn+IRiLISE1Qwx8eQnZn1BWQHdL8TCaD6BuTy1HwQg+6cbSY3bstP2G7d 1yuA== X-Gm-Message-State: AGRZ1gJFMhUavltWQ2Vhtik28T35itBiUrrMnZ3U9yqPrWCZHFZXOQJb 1B05vHiq3l7Ud/x/mXjEOUWL2Q== X-Google-Smtp-Source: AJdET5df+nafMezpXytHyYR6EhpgofZ0jZv3s9mjgnJ9QMQju1kdxhr6LHxseO9OJ0UrD0T1nx5yRw== X-Received: by 2002:a63:3e05:: with SMTP id l5mr7546695pga.96.1542332820805; Thu, 15 Nov 2018 17:47:00 -0800 (PST) Received: from vader ([64.114.255.97]) by smtp.gmail.com with ESMTPSA id i2-v6sm24936887pgq.35.2018.11.15.17.46.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Nov 2018 17:47:00 -0800 (PST) Date: Thu, 15 Nov 2018 17:46:58 -0800 From: Omar Sandoval To: Ming Lei Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, linux-erofs@lists.ozlabs.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , Theodore Ts'o , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: Re: [PATCH V10 13/19] iomap & xfs: only account for new added page Message-ID: <20181116014658.GH23828@vader> References: <20181115085306.9910-1-ming.lei@redhat.com> <20181115085306.9910-14-ming.lei@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181115085306.9910-14-ming.lei@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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-devel@redhat.com > Cc: Alexander Viro > Cc: linux-fsdevel@vger.kernel.org > Cc: Shaohua Li > Cc: linux-raid@vger.kernel.org > Cc: linux-erofs@lists.ozlabs.org > Cc: David Sterba > Cc: linux-btrfs@vger.kernel.org > Cc: Darrick J. Wong > Cc: linux-xfs@vger.kernel.org > Cc: Gao Xiang > Cc: Christoph Hellwig > Cc: Theodore Ts'o > Cc: linux-ext4@vger.kernel.org > Cc: Coly Li > Cc: linux-bcache@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( > unsigned len = i_blocksize(inode); > unsigned poff = offset & (PAGE_SIZE - 1); > sector_t sector; > + bool need_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 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) Indentation. > +{ > + struct bio_vec bv; > + > + bvec_last_segment(bio_last_bvec_all(bio), &bv); > + > + return bv.bv_page == page && bv.bv_len == len && bv.bv_offset == off; > +} > + > enum bip_flags { > BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */ > BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */ > -- > 2.9.5 >