From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792422451; b=05ZuaICILdJhpFtveA4IHyor2NWxrFzX2M7xWF5TVothID8+ag2zgSg5jPkWEsGglBaq 4zvMmoc2RN44l78aARUjlXzH90JB4WQ4MrpAXbhxgNvPwmjgNXmiudnQWagT1h/u/0KPT GA8T5A6Scatj2y/5Upx6UmbOhoD8cOLi5vVcw4d/gZoeQ9qOx7oC+CM5ut8udIHxHUVlQ YeJXstHLRC9yTHePd19iWw2RIA80feqdMS8aXC5RdWjSgXxribJpNDj9TglZzkgrvtpMB EGM0adYc1buBCt9MnqHXPkXOcCRjR7AM4nHwL3JhYUyYy1wiYDt1jKfEdBFCYp8zkXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792422451; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=7y3NOM7xqvWmL65AFq+ZWC79CgE7opPLQwAIectARfc=; b=5PwMGx5uRTmkNcfw1pF+RDExYBO9po1bCkba1G8H8/hQT47wzkggKFc3m2BJdnF/zJ6D SZT7NgKTlpNGE7bNd4GEe/n25XHh8lUWpqGt+RZPS9xslow6nGhrl1sfxg/2aCZAHa45u HQBEjTV5ULMqn2ooKixyNZ124VKszN/B+/tDCmELhcI0QPphpynyQDi3byX6+vZcPWTb5 FGVhvp1pB3xHWcN51kJzhGlrGzADIZ57WoSZ/HkweL/6X9LgJ2LPwHSXv0nYUGynsKIHP Ga6Wsl757BF0XZweswl3DNKbSzFtl5js0ErubVSN4hX6PdCyjD60KDxfOzQoMX9rrCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=essh9OvE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05957608343A; Mon, 19 Oct 2026 15:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=essh9OvE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AD2B1F000C4; Mon, 19 Oct 2026 15:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792422450; bh=7y3NOM7xqvWmL65AFq+ZWC79CgE7opPLQwAIectARfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=essh9OvEhCNgIzvXj70luMYDVXtcP8DELRtgMlhe1mMVJnzfaVGUkxkYbOPRmTL8D OGUqMGkYVSgbRgupoV8D/5a+w+s6wsnLtP1XfgxGHzcGCXPwRTGP7YrTSTONWKRCzp ImUT0DzjRA74z3ukf+xedel4OBNzDoykCxxg5TX81/qvSPy7dAPVJsQZf9W9jjMf+4 DvNkhL1xMliJLz9ZMTlIhD5wdz8dw2PFfkgGXfxNlfQzi/vxAO0OVYvkOFftRIQl2L BV2u2yshAT72wI+uW+QCFE8gOH6AJivte2T9movH2sbplMjbA8Ah0YHlbspTiyWvPL YBgF2o/in2O6w== From: Mike Snitzer To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Christoph Hellwig , Jens Axboe , Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v5 3/6] mm: add folio_mark_dropbehind() to mark a folio dropbehind and account it Date: Mon, 19 Oct 2026 11:07:22 -0400 Message-ID: <20261019150725.1507-4-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20261019150725.1507-1-snitzer@kernel.org> References: <20261019150725.1507-1-snitzer@kernel.org> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A folio allocated by an RWF_DONTCACHE write is marked dropbehind before it is dirtied, so folio_account_dirtied() adds it to WB_DONTCACHE_DIRTY and folio_clear_dirty_for_io() or folio_account_cleaned() subtracts it when it is cleaned. Nothing marks a folio that already exists. A caller that sets PG_dropbehind on a folio that is already dirty unbalances the counter: the clean subtracts what was never added, and once the counter goes negative, wb_stat_sum() reads it as zero and the DONTCACHE writeback kick stops writing anything back for every writer on that bdi_writeback. Add folio_mark_dropbehind(), the inverse of the clear in __filemap_get_folio_mpol(): with the folio locked, mark it and, if it is dirty, add it to WB_DONTCACHE_DIRTY. The folio lock orders this against dirtying and against folio_clear_dirty_for_io(). A concurrent lookup without FGP_DONTCACHE that clears the flag again subtracts what this added. The name follows folio_set_dirty() and folio_mark_dirty(): the first only sets PG_dirty, the second also accounts the dirty folio. folio_set_dropbehind() likewise only sets PG_dropbehind, and folio_mark_dropbehind() also accounts it in WB_DONTCACHE_DIRTY. A later commit uses it in NFSD to drop a page shared by two misaligned WRITEs once both have written it. Cc: Jeff Layton Cc: Jens Axboe Cc: Matthew Wilcox (Oracle) Cc: linux-mm@kvack.org Assisted-by: LLM Signed-off-by: Mike Snitzer --- include/linux/pagemap.h | 1 + mm/filemap.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 0adfa6605653..3012bd95812a 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1310,6 +1310,7 @@ void end_page_writeback(struct page *page); void folio_end_writeback(struct folio *folio); void folio_end_writeback_no_dropbehind(struct folio *folio); void folio_end_dropbehind(struct folio *folio); +void folio_mark_dropbehind(struct folio *folio); void folio_wait_stable(struct folio *folio); void __folio_mark_dirty(struct folio *folio, struct address_space *, int warn); void folio_account_cleaned(struct folio *folio, struct bdi_writeback *wb); diff --git a/mm/filemap.c b/mm/filemap.c index 00fd89cf6f55..ed7e4dbea653 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1644,6 +1644,37 @@ void folio_end_dropbehind(struct folio *folio) } EXPORT_SYMBOL_GPL(folio_end_dropbehind); +/** + * folio_mark_dropbehind - mark an existing folio dropbehind + * @folio: the folio, locked by the caller + * + * Mark @folio so that the writeback that cleans it drops it. A folio that + * is already dirty is added to WB_DONTCACHE_DIRTY, as folio_account_dirtied() + * would have added it had it been marked when dirtied, so that the clean + * that subtracts it leaves the counter balanced. + */ +void folio_mark_dropbehind(struct folio *folio) +{ + struct address_space *mapping = folio->mapping; + + VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio); + + if (folio_test_dropbehind(folio)) + return; + folio_set_dropbehind(folio); + if (mapping && folio_test_dirty(folio) && + mapping_can_writeback(mapping)) { + struct inode *inode = mapping->host; + struct bdi_writeback *wb; + struct wb_lock_cookie cookie = {}; + + wb = unlocked_inode_to_wb_begin(inode, &cookie); + wb_stat_mod(wb, WB_DONTCACHE_DIRTY, folio_nr_pages(folio)); + unlocked_inode_to_wb_end(inode, &cookie); + } +} +EXPORT_SYMBOL_GPL(folio_mark_dropbehind); + /** * folio_end_writeback_no_dropbehind - End writeback against a folio. * @folio: The folio. -- 2.52.0