Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1398208pxk; Fri, 25 Sep 2020 13:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxueTthx1iLfZAV6UbzTkqeuH+bwBin30nS/hHOLUo9ZeK54U9q0lSrMcWQMg+JspSw1JoQ X-Received: by 2002:aa7:d6c4:: with SMTP id x4mr3311555edr.98.1601066794393; Fri, 25 Sep 2020 13:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601066794; cv=none; d=google.com; s=arc-20160816; b=X3hm5dMlA9SlEDL8OkQrdgpFzSBavMxwFAmBeGB1xGKAj9filfCn2bNOkiKjXlaKGY LXN23qRdQw88WeKCFzTDYyT+5LxUPvpIESC2RalHKYvd5YrrhLFSGN8BZz4xRCyNKu1j wPjhQq+IVsXPwRqmlf5Du2SgZUh8iquji0wfM1nCHHeAXJcvLU6PiwkDk7hYMQZqrVEN pw45gKELcMnzb0RcZjkdtKGDomDww5tS7kY3faBcD+69K0rOml+YnOwNoHb7IiY7Xiku yYF1k8kwFkeOHg46XNFfSqlqnNhbEJCTH091W556I1gJoaV/fIAeEx9wnR3HDVCjzdoX tEcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=4UbYfQo9AxoYDYhHzSM52zo+QqA5U/JvLsALQgToAcw=; b=1IwKKPW2t3m4PSwMyvNQX8V0ShxK91+/4iph0y4Zhdzb1ocS5lYMuxmxRedctf6Rxc xf2qkOZIeqypSwQTGKopMxP2mT382lr3wrAJwYLXPfmdlY16ZdP9umMRTZ8dxNr91Hbq gWpoOYBqZSxX7DFCYQDwJC3VO3gWaahuhYcHaq8dIt6TRAFOcLEvmFZdlthTKIGSUYFC XWGhcGO+pUo9ynshX1tuKi4NUi5Un90+CthiTGi8S5aVhJY4J/u3ks+0DCFsXez7de48 1R/AO2RsF82tUvpXdVVXz1Dj0EGDBKqDXfApUeIHcfZt2ZTuTzuegoETU7Rpi7PQZpgA UMwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ppmFHJw0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mf3si2527187ejb.27.2020.09.25.13.46.11; Fri, 25 Sep 2020 13:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@nvidia.com header.s=n1 header.b=ppmFHJw0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727151AbgIYUov (ORCPT + 99 others); Fri, 25 Sep 2020 16:44:51 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:10746 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726239AbgIYUov (ORCPT ); Fri, 25 Sep 2020 16:44:51 -0400 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 25 Sep 2020 13:44:03 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 25 Sep 2020 20:44:48 +0000 Received: from rcampbell-dev.nvidia.com (10.124.1.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1473.3 via Frontend Transport; Fri, 25 Sep 2020 20:44:48 +0000 From: Ralph Campbell To: , , , CC: Dan Williams , Ira Weiny , Matthew Wilcox , Jerome Glisse , John Hubbard , Alistair Popple , Christoph Hellwig , Jason Gunthorpe , "Bharata B Rao" , Zi Yan , "Kirill A . Shutemov" , Yang Shi , Paul Mackerras , Ben Skeggs , "Andrew Morton" , Ralph Campbell Subject: [PATCH 1/2] ext4/xfs: add page refcount helper Date: Fri, 25 Sep 2020 13:44:41 -0700 Message-ID: <20200925204442.31348-2-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200925204442.31348-1-rcampbell@nvidia.com> References: <20200925204442.31348-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1601066643; bh=4UbYfQo9AxoYDYhHzSM52zo+QqA5U/JvLsALQgToAcw=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:X-NVConfidentiality: Content-Transfer-Encoding:Content-Type; b=ppmFHJw0FcvTTLsqEzpQGv1+HRZOAwtVEIxm0dWqH7qfJliBWPFv0mr0+bEjH9zMw 27oZK0wp+klIF1aR8bjlS0PCzsozHz0RU7MoXCOJoKJMskpwWXSYldy1pORDmvC6R6 nwaNeCE1ezdMPk1zip1/0XO+Y98S809xcq0vKiH1bot2OZ/NB/eLGflsWUFgvZXkC9 YCqnNcLDseWWA7vraoWncwMoTeSoOBhEK7AuZ8NEMrgLd7zwRTsmFjoPT1sSduX3aj aJXHU048cE+Gn7/oz0w8gMVrcgsNwJMIen9Fpp2fqb9izIrKOoovFISrkv3h1lyN0d xtnrv3qv5fzZg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are several places where ZONE_DEVICE struct pages assume a reference count =3D=3D 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 --- fs/dax.c | 8 ++++---- fs/ext4/inode.c | 2 +- fs/xfs/xfs_file.c | 2 +- include/linux/dax.h | 5 +++++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 994ab66a9907..8eddbcc0e149 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -358,7 +358,7 @@ static void dax_disassociate_entry(void *entry, struct = address_space *mapping, for_each_mapped_pfn(entry, pfn) { struct page *page =3D pfn_to_page(pfn); =20 - WARN_ON_ONCE(trunc && page_ref_count(page) > 1); + WARN_ON_ONCE(trunc && !dax_layout_is_idle_page(page)); WARN_ON_ONCE(page->mapping && page->mapping !=3D mapping); page->mapping =3D NULL; page->index =3D 0; @@ -372,7 +372,7 @@ static struct page *dax_busy_page(void *entry) for_each_mapped_pfn(entry, pfn) { struct page *page =3D pfn_to_page(pfn); =20 - if (page_ref_count(page) > 1) + if (!dax_layout_is_idle_page(page)) return page; } return NULL; @@ -560,11 +560,11 @@ static void *grab_mapping_entry(struct xa_state *xas, =20 /** * dax_layout_busy_page - find first pinned page in @mapping - * @mapping: address space to scan for a page with ref count > 1 + * @mapping: address space to scan for a page with ref count > 0 * * DAX requires ZONE_DEVICE mapped pages. These pages are never * 'onlined' to the page allocator so they are considered idle when - * page->count =3D=3D 1. A filesystem uses this interface to determine if + * page->count =3D=3D 0. A filesystem uses this interface to determine if * any page in the mapping is busy, i.e. for DMA, or other * get_user_pages() usages. * diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index bf596467c234..d9f8ad55523a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3927,7 +3927,7 @@ int ext4_break_layouts(struct inode *inode) return 0; =20 error =3D ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) =3D=3D 1, + dax_layout_is_idle_page(page), TASK_INTERRUPTIBLE, 0, 0, ext4_wait_dax_page(ei)); } while (error =3D=3D 0); diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index a29f78a663ca..29ab96541bc1 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -750,7 +750,7 @@ xfs_break_dax_layouts( =20 *retry =3D true; return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) =3D=3D 1, TASK_INTERRUPTIBLE, + dax_layout_is_idle_page(page), TASK_INTERRUPTIBLE, 0, 0, xfs_wait_dax_page(inode)); } =20 diff --git a/include/linux/dax.h b/include/linux/dax.h index 43b39ab9de1a..3f78ed78d1d6 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -238,4 +238,9 @@ static inline bool dax_mapping(struct address_space *ma= pping) return mapping->host && IS_DAX(mapping->host); } =20 +static inline bool dax_layout_is_idle_page(struct page *page) +{ + return page_ref_count(page) <=3D 1; +} + #endif --=20 2.20.1