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 09700C07E99 for ; Mon, 12 Jul 2021 03:47:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A647B61003 for ; Mon, 12 Jul 2021 03:47:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A647B61003 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 C32636B0096; Sun, 11 Jul 2021 23:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C08B56B0098; Sun, 11 Jul 2021 23:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF8CF6B009A; Sun, 11 Jul 2021 23:47:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0230.hostedemail.com [216.40.44.230]) by kanga.kvack.org (Postfix) with ESMTP id 8A7026B0096 for ; Sun, 11 Jul 2021 23:47:54 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AF7E5230E4 for ; Mon, 12 Jul 2021 03:47:53 +0000 (UTC) X-FDA: 78352552026.27.323BBE2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 6559590000B9 for ; Mon, 12 Jul 2021 03:47:53 +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=VUoFFES+MyX2ydoKEt/DR9LLbb03jHDkt5vlqFuG18M=; b=EaYuP+9RIjdTcMQEVpB0dzikS8 dpM0XnGVSt8+h1OMmOCrFsRIbvgDd33HD+H4Sv75O4vNxhGmkcV/88Ar/7ODugB/VJUJO7Mt3RjmF zBog97CLINvSyLAhFQpMVTQZ3bcZK8qd6NR0x4rNpn58/HKQIwPq+2kHoHgKNNB1vtzY8nIQd+Htg mZzzBeNRaeTKPsPYTesCKq9MGN+uNMA///KinS0CFeRhcCIZI8gEAj6T7RkGhXypQJc99sHYChdMj dh1f6+ByN2jayBrLmfcSRnQN0b8aWRKTJ5BSLl/CIS8gRozGsA1y+k9QG77VWk84hIrBeQ+k10Jng RDbezWCQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2mu7-00GpXm-J1; Mon, 12 Jul 2021 03:47:13 +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 074/137] mm/writeback: Add folio_account_redirty() Date: Mon, 12 Jul 2021 04:05:58 +0100 Message-Id: <20210712030701.4000097-75-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: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=EaYuP+9R; spf=none (imf23.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: rspam05 X-Stat-Signature: w11aqcu5yiuqatnc6sbyjp157tii6zxa X-Rspamd-Queue-Id: 6559590000B9 X-HE-Tag: 1626061673-908140 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: Account the number of pages in the folio that we're redirtying. Turn account_page_dirty() into a wrapper around it. Also turn the comment on folio_account_redirty() into kernel-doc and edit it slightly so it makes sense to its potential callers. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig --- include/linux/writeback.h | 6 +++++- mm/page-writeback.c | 32 +++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index eda9cc778ef6..50cb6e25ab9e 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -399,7 +399,11 @@ void tag_pages_for_writeback(struct address_space *m= apping, 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); +void folio_account_redirty(struct folio *folio); +static inline void account_page_redirty(struct page *page) +{ + folio_account_redirty(page_folio(page)); +} =20 void sb_mark_inode_writeback(struct inode *inode); void sb_clear_inode_writeback(struct inode *inode); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index a2a6b4b169c6..593b4f4f5f22 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1084,7 +1084,7 @@ static void wb_update_write_bandwidth(struct bdi_wr= iteback *wb, * write_bandwidth =3D ------------------------------------------------= --- * period * - * @written may have decreased due to account_page_redirty(). + * @written may have decreased due to folio_account_redirty(). * Avoid underflowing @bw calculation. */ bw =3D written - min(written, wb->written_stamp); @@ -2527,30 +2527,36 @@ bool filemap_dirty_folio(struct address_space *ma= pping, struct folio *folio) } EXPORT_SYMBOL(filemap_dirty_folio); =20 -/* - * Call this whenever redirtying a page, to de-account the dirty counter= s - * (NR_DIRTIED, WB_DIRTIED, tsk->nr_dirtied), so that they match the wri= tten - * counters (NR_WRITTEN, WB_WRITTEN) in long term. The mismatches will l= ead to - * systematic errors in balanced_dirty_ratelimit and the dirty pages pos= ition - * control. +/** + * folio_account_redirty - Manually account for redirtying a page. + * @folio: The folio which is being redirtied. + * + * Most filesystems should call folio_redirty_for_writepage() instead + * of this fuction. If your filesystem is doing writeback outside the + * context of a writeback_control(), it can call this when redirtying + * a folio, to de-account the dirty counters (NR_DIRTIED, WB_DIRTIED, + * tsk->nr_dirtied), so that they match the written counters (NR_WRITTEN= , + * WB_WRITTEN) in long term. The mismatches will lead to systematic erro= rs + * in balanced_dirty_ratelimit and the dirty pages position control. */ -void account_page_redirty(struct page *page) +void folio_account_redirty(struct folio *folio) { - struct address_space *mapping =3D page->mapping; + struct address_space *mapping =3D folio->mapping; =20 if (mapping && mapping_can_writeback(mapping)) { struct inode *inode =3D mapping->host; struct bdi_writeback *wb; struct wb_lock_cookie cookie =3D {}; + unsigned nr =3D folio_nr_pages(folio); =20 wb =3D unlocked_inode_to_wb_begin(inode, &cookie); - current->nr_dirtied--; - dec_node_page_state(page, NR_DIRTIED); - dec_wb_stat(wb, WB_DIRTIED); + current->nr_dirtied -=3D nr; + node_stat_mod_folio(folio, NR_DIRTIED, -nr); + wb_stat_mod(wb, WB_DIRTIED, -nr); unlocked_inode_to_wb_end(inode, &cookie); } } -EXPORT_SYMBOL(account_page_redirty); +EXPORT_SYMBOL(folio_account_redirty); =20 /* * When a writepage implementation decides that it doesn't want to write= this --=20 2.30.2