From: sashiko-bot@kernel.org
To: "Mike Snitzer" <snitzer@kernel.org>,
"Matthew Wilcox" <willy@infradead.org>, "Jan Kara" <jack@suse.cz>,
linux-mm@kvack.org, "Christian Brauner" <brauner@kernel.org>
Subject: Re: [PATCH v13 4/7] mm: add folio_mark_dropbehind() to mark a folio dropbehind and account it
Date: Sat, 05 Dec 2026 07:39:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-251238@kernel.org> (raw)
In-Reply-To: <ec92db9f65c5f8a1be9a71ad300e94c25cfa57cc.1796367526.git.snitzer@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: folio_mark_dropbehind() misses unlocked non-pte dirtier
race
--
commit 58745295037799f6e54ed4a50a7c62fe9301b14c
Author: Mike Snitzer <snitzer@kernel.org>
mm: add folio_mark_dropbehind() to mark a folio dropbehind and account it
This commit adds folio_mark_dropbehind() to mark an existing locked,
unmapped folio with PG_dropbehind and account it in WB_DONTCACHE_DIRTY if
it is already dirty.
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 9ecd5060ea4c9..dc270b668258b 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1654,6 +1654,41 @@ void folio_end_dropbehind(struct folio *folio)
[ ... ]
> +void folio_mark_dropbehind(struct folio *folio)
> +{
> + struct address_space *mapping = folio->mapping;
> + unsigned long flags;
> +
> + VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio);
> +
> + if (folio_test_dropbehind(folio))
> + return;
> + if (folio_mapped(folio))
> + return;
> + if (!mapping || !mapping_can_writeback(mapping)) {
> + folio_set_dropbehind(folio);
> + return;
> + }
> + xa_lock_irqsave(&mapping->i_pages, flags);
> + folio_set_dropbehind(folio);
> + if (folio_test_dirty(folio) &&
> + xa_get_mark(&mapping->i_pages, folio->index, PAGECACHE_TAG_DIRTY))
> + wb_stat_mod(inode_to_wb(mapping->host), WB_DONTCACHE_DIRTY,
> + folio_nr_pages(folio));
> + xa_unlock_irqrestore(&mapping->i_pages, flags);
> +}
[Severity: Medium]
Can WB_DONTCACHE_DIRTY still be double-counted when an unlocked dirtier
races on an unmapped folio?
Checking folio_mapped(folio) does not exclude unlocked non-page-table
dirtiers. For example, a GUP-pinned page from an O_DIRECT read (such as
nfs_direct_read_completion() calling set_page_dirty()) can be dirtied
without folio_lock() after userspace has called munmap() on the VMA:
CPU0 (unlocked dirtier) CPU1 (writeback / RWF_DONTCACHE)
folio_clear_dirty_for_io()
/* clears PG_dirty, keeps tag */
nfs_direct_read_completion()
set_page_dirty()
folio_test_set_dirty() /* 0->1 */
/* pauses before i_pages lock */
__folio_start_writeback()
/* sees PG_dirty, keeps tag */
folio_unlock()
...
folio_lock()
folio_mark_dropbehind()
xa_lock_irqsave(&mapping->i_pages)
folio_set_dropbehind()
wb_stat_mod(..., WB_DONTCACHE_DIRTY)
xa_unlock_irqrestore(...)
__folio_mark_dirty()
xa_lock_irqsave(&mapping->i_pages)
folio_account_dirtied()
wb_stat_mod(..., WB_DONTCACHE_DIRTY) <-- double-counted
Because folio_mark_dropbehind() sees both PG_dirty and PAGECACHE_TAG_DIRTY
set, it adds folio_nr_pages(folio) to WB_DONTCACHE_DIRTY, and the paused
__folio_mark_dirty() then sees PG_dropbehind and adds it a second time.
Cleaning the folio later subtracts it only once, leaving permanent upward
drift in WB_DONTCACHE_DIRTY and causing subsequent wb_check_start_dontcache()
kicks to pass an inflated target to wb_writeback() and flush unrelated
cached dirty pages on the same bdi_writeback.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796367526.git.snitzer@kernel.org?part=4
next prev parent reply other threads:[~2026-12-05 7:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 7:38 [PATCH v13 0/7] mm, iomap, NFSD: stop DONTCACHE writes reading back shared pages Mike Snitzer
2026-12-04 7:38 ` [PATCH v13 1/7] mm: move clearing the dropbehind flag of a found folio into a helper Mike Snitzer
2026-12-04 7:38 ` [PATCH v13 2/7] mm: take a folio off WB_DONTCACHE_DIRTY only if it was counted there Mike Snitzer
2026-12-05 7:39 ` sashiko-bot
2026-12-04 7:38 ` [PATCH v13 3/7] mm: expose WB_DONTCACHE_DIRTY in bdi debugfs stats Mike Snitzer
2026-12-05 7:39 ` sashiko-bot
2026-12-04 7:38 ` [PATCH v13 4/7] mm: add folio_mark_dropbehind() to mark a folio dropbehind and account it Mike Snitzer
2026-12-05 7:39 ` sashiko-bot [this message]
2026-12-04 7:38 ` [PATCH v13 5/7] iomap: keep a DONTCACHE edge folio until a write completes it Mike Snitzer
2026-12-05 7:39 ` sashiko-bot
2026-12-04 7:38 ` [PATCH v13 6/7] fs: let a DONTCACHE writer that syncs the range itself skip the kick Mike Snitzer
2026-12-04 7:38 ` [PATCH v13 7/7] NFSD: do not kick DONTCACHE writeback for a WRITE that NFSD syncs Mike Snitzer
2026-12-05 7:39 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-251238@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-mm@kvack.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=snitzer@kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.