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=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 2E7EBC433DF for ; Tue, 4 Aug 2020 16:18:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E50BE2086A for ; Tue, 4 Aug 2020 16:18:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OHO238re" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E50BE2086A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E71A8D0175; Tue, 4 Aug 2020 12:18:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7968B8D0081; Tue, 4 Aug 2020 12:18:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D45D8D0175; Tue, 4 Aug 2020 12:18:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 556738D0081 for ; Tue, 4 Aug 2020 12:18:19 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 074E1181AEF0B for ; Tue, 4 Aug 2020 16:18:19 +0000 (UTC) X-FDA: 77113393518.18.shoe71_5b0803a26fa7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id BB1D4100ED3A5 for ; Tue, 4 Aug 2020 16:18:15 +0000 (UTC) X-HE-Tag: shoe71_5b0803a26fa7 X-Filterd-Recvd-Size: 4824 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Tue, 4 Aug 2020 16:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=+aj+hTcmyQ/ZxfRwwyhlTJL7pLaB+BkTSJfzBBgI/q8=; b=OHO238reNTCqUaIKEk+I2PVyf/ 8z9DmI82B4usqHm6Sy3qgsL1BcZnsELUqPX5VD6f8Alk7w07CcozvEfAWNalxZZ8CkY4NKVZVQ/Da CiufiKZyhaI2viUdnj08hu6WNWDmGz04xOh/lwGsbtGzT14Lc2QOud0vXTnJIw0Uy2PPFvPioXetF cEjX7iwUpdLCMPo/+2OHAZj7arwcfR/aQ2g7wkq7Xn5k6q2u4uj/2ucVzje1a7CqrEd1OnZIVLel/ iWl9UMS/c71q2TlQnHwx/i8VjO9FoRh+ZBaHyZecTNSe/qMYq6nCUQ5XGe5+DGRGhGqRtm5BW/D+C pE9HMj8Q==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k2zdV-0002e1-IW; Tue, 04 Aug 2020 16:17:57 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-nvdimm@lists.01.org Subject: [PATCH 1/4] mm: Introduce and use page_cache_empty Date: Tue, 4 Aug 2020 17:17:52 +0100 Message-Id: <20200804161755.10100-2-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200804161755.10100-1-willy@infradead.org> References: <20200804161755.10100-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: BB1D4100ED3A5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable 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: Instead of checking the two counters (nrpages and nrexceptional), we can just check whether i_pages is empty. Signed-off-by: Matthew Wilcox (Oracle) --- fs/block_dev.c | 2 +- fs/dax.c | 2 +- include/linux/pagemap.h | 5 +++++ mm/truncate.c | 18 +++--------------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 0ae656e022fd..2a77bd2c6144 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -79,7 +79,7 @@ static void kill_bdev(struct block_device *bdev) { struct address_space *mapping =3D bdev->bd_inode->i_mapping; =20 - if (mapping->nrpages =3D=3D 0 && mapping->nrexceptional =3D=3D 0) + if (page_cache_empty(mapping)) return; =20 invalidate_bh_lrus(); diff --git a/fs/dax.c b/fs/dax.c index 11b16729b86f..2f75ee2cd41f 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -949,7 +949,7 @@ int dax_writeback_mapping_range(struct address_space = *mapping, if (WARN_ON_ONCE(inode->i_blkbits !=3D PAGE_SHIFT)) return -EIO; =20 - if (!mapping->nrexceptional || wbc->sync_mode !=3D WB_SYNC_ALL) + if (page_cache_empty(mapping) || wbc->sync_mode !=3D WB_SYNC_ALL) return 0; =20 trace_dax_writeback_range(inode, xas.xa_index, end_index); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 484a36185bb5..a474a92a2a72 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -18,6 +18,11 @@ =20 struct pagevec; =20 +static inline bool page_cache_empty(struct address_space *mapping) +{ + return xa_empty(&mapping->i_pages); +} + /* * Bits in mapping->flags. */ diff --git a/mm/truncate.c b/mm/truncate.c index dd9ebc1da356..7c4c8ac140be 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -300,7 +300,7 @@ void truncate_inode_pages_range(struct address_space = *mapping, pgoff_t index; int i; =20 - if (mapping->nrpages =3D=3D 0 && mapping->nrexceptional =3D=3D 0) + if (page_cache_empty(mapping)) goto out; =20 /* Offsets within partial pages */ @@ -488,9 +488,6 @@ EXPORT_SYMBOL(truncate_inode_pages); */ void truncate_inode_pages_final(struct address_space *mapping) { - unsigned long nrexceptional; - unsigned long nrpages; - /* * Page reclaim can not participate in regular inode lifetime * management (can't call iput()) and thus can race with the @@ -500,16 +497,7 @@ void truncate_inode_pages_final(struct address_space= *mapping) */ mapping_set_exiting(mapping); =20 - /* - * When reclaim installs eviction entries, it increases - * nrexceptional first, then decreases nrpages. Make sure we see - * this in the right order or we might miss an entry. - */ - nrpages =3D mapping->nrpages; - smp_rmb(); - nrexceptional =3D mapping->nrexceptional; - - if (nrpages || nrexceptional) { + if (!page_cache_empty(mapping)) { /* * As truncation uses a lockless tree lookup, cycle * the tree lock to make sure any ongoing tree @@ -692,7 +680,7 @@ int invalidate_inode_pages2_range(struct address_spac= e *mapping, int ret2 =3D 0; int did_range_unmap =3D 0; =20 - if (mapping->nrpages =3D=3D 0 && mapping->nrexceptional =3D=3D 0) + if (page_cache_empty(mapping)) goto out; =20 pagevec_init(&pvec); --=20 2.27.0