Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp542351pxb; Wed, 25 Aug 2021 09:04:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfQ0Kp76yYX51W6ulbuAany4GJv4j/AZEgZ3uAGYHdrSbhsUJ22NnfMwfeJdpnyyWvMifF X-Received: by 2002:a17:907:7848:: with SMTP id lb8mr47355754ejc.494.1629907460053; Wed, 25 Aug 2021 09:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629907459; cv=none; d=google.com; s=arc-20160816; b=I3m8ZNYkeqm++cbYx8HVtLbd6bXob1ZoS1Vpwdy7VdguC/T6zKyWnhk9KPiONVGPyw PxyDBfqcx8NtL+31GrxZMxTs4365SepmGTkeGW1l+fLES/p4+j6ul43b0tlRDMeT0XGG 1JKo2ljbT5IzXGq5xdHS3wkfdVsjr8jCtsxK8fIHDMJ/+G+aummXo0yXYC5y6ng775uH Fb2LzCJmgU/CCgIHD90M/GYbbPNI53/+gR1iwUXcCA2eHHtykFpQjz/E8qrmTZGTBx/U YVUUm/ZEAv9wK6jz7up63XG96KGcBfkEJM8kCP+xvxkHQ+ljR1cqdi8e2gRT8twml0Js UL0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=J/lc0kiceLXkjcpj3UZK9mN4IFejU0ut9T4kHiXDXNg=; b=AMlRwq13APpumhz/8sQaUCM8XFKlKJyz3SDfgULFgBje8/wtUS0m0Tc+yGl7cBK7Gg fKKxcZj3jaBfCB3aB2tahNmhye4s8fxaV3TCTTplmC2aK9w9mw87y6Vy6PPKR6Bfvnvp Br53IjDqOa3AvvfxIaY1tj5zAaYi6WWo4QdgJ0zacS00M0d4ADb/SgHl3jeW8CvFg6Tp tt9E2PIaCRkI/McoM+ziyJxq6enNgLPlhgY1Bgk9HQB1L2rmC9asATaMFK3WeBwB2JaF XuPBL23SsMzzjOHD3GwMFxKE4op5QTr34qMj8WWwCWOTKrRAK1eRCT4Kdk4aIHM6rd3i G7fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HAiwhNJ1; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si199737ejj.578.2021.08.25.09.03.47; Wed, 25 Aug 2021 09:04:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HAiwhNJ1; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241228AbhHYPuK (ORCPT + 99 others); Wed, 25 Aug 2021 11:50:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:41474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241145AbhHYPuK (ORCPT ); Wed, 25 Aug 2021 11:50:10 -0400 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> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 >