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=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 05054C43216 for ; Wed, 25 Aug 2021 15:49:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9C97261100 for ; Wed, 25 Aug 2021 15:49:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9C97261100 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 385216B0071; Wed, 25 Aug 2021 11:49:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 334E96B0072; Wed, 25 Aug 2021 11:49:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 224306B0073; Wed, 25 Aug 2021 11:49:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id 097C16B0071 for ; Wed, 25 Aug 2021 11:49:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 878198249980 for ; Wed, 25 Aug 2021 15:49:25 +0000 (UTC) X-FDA: 78514037490.29.D33E8ED Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf12.hostedemail.com (Postfix) with ESMTP id 281BA10000A5 for ; Wed, 25 Aug 2021 15:49:25 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 3B57F6108F; Wed, 25 Aug 2021 15:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629906564; bh=FVD2vqdsUZTR9hZG05ACoaP6ReYdgDUa885m2ElXSE0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HAiwhNJ1ACq2z2H2TMp9dVF76jCCuZqsMCCYfkazWMyoAgJqTgQzIbM/bwgH2Ci8T 9rnvGNiiu2J1lVNdcQUIhbB8jv0+IcWrnzLrr1K2B8jSpZ5TjYoqEAgzEwG5cjyE+X vHLFfu4r70i7cCH1w8cKQUTcURZmxFpzcqxbt0cZ6UFMXB54n50Uw8HuN3C6Ow12Q7 EPNBfCXZY5gvFPoWY8Ja1kzrkP8EPpMQo7srRrOUNGU+1AO7uMPiKitzJurcKStCgb hmEpCrWdwrfqQImLQA+tojsCLnsnCHPdvs440xdif865dG9JR5HZzIqBLBmM85Nfw1 FHvU8nF1D6lSw== Date: Wed, 25 Aug 2021 08:49:23 -0700 From: "Darrick J. Wong" To: Alex Sierra Cc: akpm@linux-foundation.org, Felix.Kuehling@amd.com, linux-mm@kvack.org, rcampbell@nvidia.com, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, hch@lst.de, jgg@nvidia.com, jglisse@redhat.com Subject: Re: [PATCH v1 01/14] ext4/xfs: add page refcount helper Message-ID: <20210825154923.GF12640@magnolia> References: <20210825034828.12927-1-alex.sierra@amd.com> <20210825034828.12927-2-alex.sierra@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210825034828.12927-2-alex.sierra@amd.com> Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HAiwhNJ1; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of djwong@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=djwong@kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 281BA10000A5 X-Stat-Signature: 6t5sdu3gpm4xfgaccha9ybf6hc5dm7tf X-HE-Tag: 1629906565-813412 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Aug 24, 2021 at 10:48:15PM -0500, Alex Sierra wrote: > From: Ralph Campbell > > There are several places where ZONE_DEVICE struct pages assume a reference > count == 1 means the page is idle and free. Instead of open coding this, > add a helper function to hide this detail. > > Signed-off-by: Ralph Campbell > Signed-off-by: Alex Sierra > Reviewed-by: Christoph Hellwig Looks fine to me, Acked-by: Darrick J. Wong --D > --- > v3: > [AS]: rename dax_layout_is_idle_page func to dax_page_unused > > v4: > [AS]: This ref count functionality was missing on fuse/dax.c. > --- > fs/dax.c | 4 ++-- > fs/ext4/inode.c | 5 +---- > fs/fuse/dax.c | 4 +--- > fs/xfs/xfs_file.c | 4 +--- > include/linux/dax.h | 10 ++++++++++ > 5 files changed, 15 insertions(+), 12 deletions(-) > > diff --git a/fs/dax.c b/fs/dax.c > index 62352cbcf0f4..c387d09e3e5a 100644 > --- a/fs/dax.c > +++ b/fs/dax.c > @@ -369,7 +369,7 @@ static void dax_disassociate_entry(void *entry, struct address_space *mapping, > for_each_mapped_pfn(entry, pfn) { > struct page *page = pfn_to_page(pfn); > > - WARN_ON_ONCE(trunc && page_ref_count(page) > 1); > + WARN_ON_ONCE(trunc && !dax_page_unused(page)); > WARN_ON_ONCE(page->mapping && page->mapping != mapping); > page->mapping = NULL; > page->index = 0; > @@ -383,7 +383,7 @@ static struct page *dax_busy_page(void *entry) > for_each_mapped_pfn(entry, pfn) { > struct page *page = pfn_to_page(pfn); > > - if (page_ref_count(page) > 1) > + if (!dax_page_unused(page)) > return page; > } > return NULL; > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index fe6045a46599..05ffe6875cb1 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c > @@ -3971,10 +3971,7 @@ int ext4_break_layouts(struct inode *inode) > if (!page) > return 0; > > - error = ___wait_var_event(&page->_refcount, > - atomic_read(&page->_refcount) == 1, > - TASK_INTERRUPTIBLE, 0, 0, > - ext4_wait_dax_page(ei)); > + error = dax_wait_page(ei, page, ext4_wait_dax_page); > } while (error == 0); > > return error; > diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c > index ff99ab2a3c43..2b1f190ba78a 100644 > --- a/fs/fuse/dax.c > +++ b/fs/fuse/dax.c > @@ -677,9 +677,7 @@ static int __fuse_dax_break_layouts(struct inode *inode, bool *retry, > return 0; > > *retry = true; > - return ___wait_var_event(&page->_refcount, > - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, > - 0, 0, fuse_wait_dax_page(inode)); > + return dax_wait_page(inode, page, fuse_wait_dax_page); > } > > /* dmap_end == 0 leads to unmapping of whole file */ > diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c > index 396ef36dcd0a..182057281086 100644 > --- a/fs/xfs/xfs_file.c > +++ b/fs/xfs/xfs_file.c > @@ -840,9 +840,7 @@ xfs_break_dax_layouts( > return 0; > > *retry = true; > - return ___wait_var_event(&page->_refcount, > - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, > - 0, 0, xfs_wait_dax_page(inode)); > + return dax_wait_page(inode, page, xfs_wait_dax_page); > } > > int > diff --git a/include/linux/dax.h b/include/linux/dax.h > index b52f084aa643..8b5da1d60dbc 100644 > --- a/include/linux/dax.h > +++ b/include/linux/dax.h > @@ -243,6 +243,16 @@ static inline bool dax_mapping(struct address_space *mapping) > return mapping->host && IS_DAX(mapping->host); > } > > +static inline bool dax_page_unused(struct page *page) > +{ > + return page_ref_count(page) == 1; > +} > + > +#define dax_wait_page(_inode, _page, _wait_cb) \ > + ___wait_var_event(&(_page)->_refcount, \ > + dax_page_unused(_page), \ > + TASK_INTERRUPTIBLE, 0, 0, _wait_cb(_inode)) > + > #ifdef CONFIG_DEV_DAX_HMEM_DEVICES > void hmem_register_device(int target_nid, struct resource *r); > #else > -- > 2.32.0 >