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 BA3D1C07E99 for ; Mon, 12 Jul 2021 03:45:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6387B60FF3 for ; Mon, 12 Jul 2021 03:45:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6387B60FF3 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 83E206B008C; Sun, 11 Jul 2021 23:45:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 814696B0092; Sun, 11 Jul 2021 23:45:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DD496B0096; Sun, 11 Jul 2021 23:45:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 41B0B6B008C for ; Sun, 11 Jul 2021 23:45:40 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 58BBB182EE03F for ; Mon, 12 Jul 2021 03:45:39 +0000 (UTC) X-FDA: 78352546398.28.FE4A865 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 1A397B000299 for ; Mon, 12 Jul 2021 03:45:38 +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=nAWWLd0Jw+HcPX/B0JYf+cxlTXgzq/qxcOfR9aFVYxk=; b=CsgQiIg9pHsyqehYbGhd9i+GGo /DqPhCzmQtjPUuhNo2NiyB4EMpcpedP+aiDevTqaiMejnx8+OVbfe3zq+J3RK8CuMAimBLL7YuuAk 4HmIEuPu/eSlejkcCnt19SOIKHYCTAEt/fuvKvuSOphKoUm7MxsZQVPAMUAmUWjLAJy3rI6SwMHBY 2HoDkF+JHCbBnUaRB3C42iy5vYC1bI/JUJlpJFkqsHz6+8TjNM5rt8AxrlpTY7FynBNdYjBOGqkKo CHv6Y92tfZRarEnjQB1617OT9PzI1NvhoTvzdH+ywkhvyhGhXo9HFAapHyXcRF2q/NsPteBU2FSV6 Op/I0Yuw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2mrk-00GpOc-Fy; Mon, 12 Jul 2021 03:44:30 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig Subject: [PATCH v13 070/137] mm/writeback: Add filemap_dirty_folio() Date: Mon, 12 Jul 2021 04:05:54 +0100 Message-Id: <20210712030701.4000097-71-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712030701.4000097-1-willy@infradead.org> References: <20210712030701.4000097-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=CsgQiIg9; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam02 X-Stat-Signature: f4jqu4u6pqbdycpd3gc9crtxgap5dhix X-Rspamd-Queue-Id: 1A397B000299 X-HE-Tag: 1626061538-211461 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_nobuffers() as a wrapper around filemap_dirty_folio(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig --- include/linux/writeback.h | 1 + mm/folio-compat.c | 6 ++++ mm/page-writeback.c | 60 ++++++++++++++++++++------------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 667e86cfbdcf..eda9cc778ef6 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -398,6 +398,7 @@ void writeback_set_ratelimit(void); void tag_pages_for_writeback(struct address_space *mapping, pgoff_t start, pgoff_t end); =20 +bool filemap_dirty_folio(struct address_space *mapping, struct folio *fo= lio); void account_page_redirty(struct page *page); =20 void sb_mark_inode_writeback(struct inode *inode); diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 2c2b3917b5dc..dad962b920e5 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -83,3 +83,9 @@ bool set_page_dirty(struct page *page) return folio_mark_dirty(page_folio(page)); } EXPORT_SYMBOL(set_page_dirty); + +int __set_page_dirty_nobuffers(struct page *page) +{ + return filemap_dirty_folio(page_mapping(page), page_folio(page)); +} +EXPORT_SYMBOL(__set_page_dirty_nobuffers); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3b5d2d42582f..35e998f064c2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2488,41 +2488,43 @@ void __folio_mark_dirty(struct folio *folio, stru= ct address_space *mapping, xa_unlock_irqrestore(&mapping->i_pages, flags); } =20 -/* - * For address_spaces which do not use buffers. Just tag the page as di= rty in - * the xarray. - * - * This is also used when a single buffer is being dirtied: we want to s= et the - * page dirty in that case, but not all the buffers. This is a "bottom-= up" - * dirtying, whereas __set_page_dirty_buffers() is a "top-down" dirtying= . - * - * The caller must ensure this doesn't race with truncation. Most will = simply - * hold the page lock, but e.g. zap_pte_range() calls with the page mapp= ed and - * the pte lock held, which also locks out truncation. +/** + * filemap_dirty_folio - Mark a folio dirty for filesystems which do not= use buffer_heads. + * @mapping: Address space this folio belongs to. + * @folio: Folio to be marked as dirty. + * + * Filesystems which do not use buffer heads should call this function + * from their set_page_dirty address space operation. It ignores the + * contents of folio_private(), so if the filesystem marks individual + * blocks as dirty, the filesystem should handle that itself. + * + * This is also sometimes used by filesystems which use buffer_heads whe= n + * a single buffer is being dirtied: we want to set the folio dirty in + * that case, but not all the buffers. This is a "bottom-up" dirtying, + * whereas __set_page_dirty_buffers() is a "top-down" dirtying. + * + * The caller must ensure this doesn't race with truncation. Most will + * simply hold the folio lock, but e.g. zap_pte_range() calls with the + * folio mapped and the pte lock held, which also locks out truncation. */ -int __set_page_dirty_nobuffers(struct page *page) +bool filemap_dirty_folio(struct address_space *mapping, struct folio *fo= lio) { - lock_page_memcg(page); - if (!TestSetPageDirty(page)) { - struct address_space *mapping =3D page_mapping(page); + folio_memcg_lock(folio); + if (folio_test_set_dirty_flag(folio)) { + folio_memcg_unlock(folio); + return false; + } =20 - if (!mapping) { - unlock_page_memcg(page); - return 1; - } - __set_page_dirty(page, mapping, !PagePrivate(page)); - unlock_page_memcg(page); + __folio_mark_dirty(folio, mapping, !folio_private(folio)); + folio_memcg_unlock(folio); =20 - if (mapping->host) { - /* !PageAnon && !swapper_space */ - __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); - } - return 1; + if (mapping->host) { + /* !PageAnon && !swapper_space */ + __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); } - unlock_page_memcg(page); - return 0; + return true; } -EXPORT_SYMBOL(__set_page_dirty_nobuffers); +EXPORT_SYMBOL(filemap_dirty_folio); =20 /* * Call this whenever redirtying a page, to de-account the dirty counter= s --=20 2.30.2