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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 8D790C433B4 for ; Wed, 5 May 2021 17:24:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 16A6E60FD7 for ; Wed, 5 May 2021 17:24:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16A6E60FD7 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 9505F6B006C; Wed, 5 May 2021 13:24:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FFAE6B006E; Wed, 5 May 2021 13:24:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C8156B0070; Wed, 5 May 2021 13:24:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0023.hostedemail.com [216.40.44.23]) by kanga.kvack.org (Postfix) with ESMTP id 5A9826B006C for ; Wed, 5 May 2021 13:24:37 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 14C338249980 for ; Wed, 5 May 2021 17:24:37 +0000 (UTC) X-FDA: 78107851794.08.069C78F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id AC185E000113 for ; Wed, 5 May 2021 17:24:11 +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=iR+jUREiomMhRTmoseCoiGMsLSDkdzy18VAyMLzYr0Y=; b=tDqTcdLd+VRgq+jmVe5kpmm8i4 BlnFUzII4z3bIp+CMpwYUIzH6qMF5NuU0d+bWqCy09OvoOen8lM9Ru7uvgnNo1l8iHQNHv85LSW4+ 61brQMUMwcCJfwr+kWdi6xX0S/WP59GlNBUe/LCCpTXz4ZM30x/W0AeLqiET6pCGZP8OHy+EuSK8c vTikp4+nnQlAPYv1k2AqSjnCchMAcvNV1mxoWyaoDRYT1IVeI5O39NZI6EDsCk+OEucw7Z1RKh/iq BjC7hAFdaF0PFOUWuXznIUWDZx7nXO0M9Mye4ST01sBkZHM16wI6qsTmHlgAHPO2d5Jj38t5RzeYa MPEaiuvw==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1leKBg-000Zkc-OZ; Wed, 05 May 2021 16:16:06 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v9 59/96] mm/writeback: Add folio_mark_dirty Date: Wed, 5 May 2021 16:05:51 +0100 Message-Id: <20210505150628.111735-60-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505150628.111735-1-willy@infradead.org> References: <20210505150628.111735-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AC185E000113 X-Stat-Signature: k8ktit58jmdmw9tmuq54yugow97ko9qw Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tDqTcdLd; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620235451-176839 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: Reimplement set_page_dirty() as a wrapper around folio_mark_dirty(). There is no change to filesystems as they were already being called with the compound_head of the page being marked dirty. We avoid several calls to compound_head(), both statically (through using folio_dirty() instead of PageDirty() and dynamically by calling folio_mapping() instead of page_mapping(). Also return bool instead of int to show the range of values actually returned, and add kernel-doc. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm.h | 3 ++- mm/folio-compat.c | 6 ++++++ mm/page-writeback.c | 28 +++++++++++++++------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 75279db82040..c72cecbfe00d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1998,7 +1998,8 @@ int redirty_page_for_writepage(struct writeback_con= trol *wbc, void account_page_dirtied(struct page *page, struct address_space *mappi= ng); void account_page_cleaned(struct page *page, struct address_space *mappi= ng, struct bdi_writeback *wb); -int set_page_dirty(struct page *page); +bool folio_mark_dirty(struct folio *folio); +bool set_page_dirty(struct page *page); int set_page_dirty_lock(struct page *page); void __cancel_dirty_page(struct page *page); static inline void cancel_dirty_page(struct page *page) diff --git a/mm/folio-compat.c b/mm/folio-compat.c index d229b979b00d..a504ecf1d695 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -60,3 +60,9 @@ void mem_cgroup_uncharge(struct page *page) folio_uncharge_cgroup(page_folio(page)); } #endif + +bool set_page_dirty(struct page *page) +{ + return folio_mark_dirty(page_folio(page)); +} +EXPORT_SYMBOL(set_page_dirty); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 4d36f4d3037f..d810841ed03a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2543,8 +2543,9 @@ int redirty_page_for_writepage(struct writeback_con= trol *wbc, struct page *page) } EXPORT_SYMBOL(redirty_page_for_writepage); =20 -/* - * Dirty a page. +/** + * folio_mark_dirty - Mark a folio as being modified. + * @folio: The folio. * * For pages with a mapping this should be done under the page lock * for the benefit of asynchronous memory errors who prefer a consistent @@ -2553,12 +2554,13 @@ EXPORT_SYMBOL(redirty_page_for_writepage); * * If the mapping doesn't provide a set_page_dirty a_op, then * just fall through and assume that it wants buffer_heads. + * + * Return: True if the folio was newly dirtied, false if it was already = dirty. */ -int set_page_dirty(struct page *page) +bool folio_mark_dirty(struct folio *folio) { - struct address_space *mapping =3D page_mapping(page); + struct address_space *mapping =3D folio_mapping(folio); =20 - page =3D compound_head(page); if (likely(mapping)) { int (*spd)(struct page *) =3D mapping->a_ops->set_page_dirty; /* @@ -2571,21 +2573,21 @@ int set_page_dirty(struct page *page) * it will confuse readahead and make it restart the size rampup * process. But it's a trivial problem. */ - if (PageReclaim(page)) - ClearPageReclaim(page); + if (folio_reclaim(folio)) + folio_clear_reclaim_flag(folio); #ifdef CONFIG_BLOCK if (!spd) spd =3D __set_page_dirty_buffers; #endif - return (*spd)(page); + return (*spd)(&folio->page); } - if (!PageDirty(page)) { - if (!TestSetPageDirty(page)) - return 1; + if (!folio_dirty(folio)) { + if (!folio_test_set_dirty_flag(folio)) + return true; } - return 0; + return false; } -EXPORT_SYMBOL(set_page_dirty); +EXPORT_SYMBOL(folio_mark_dirty); =20 /* * set_page_dirty() is racy if the caller has no reference against --=20 2.30.2