From: David Howells <dhowells@redhat.com>
To: Yun Zhou <yun.zhou@windriver.com>,
Matthew Wilcox <willy@infradead.org>,
Christoph Hellwig <hch@infradead.org>,
Christian Brauner <brauner@kernel.org>
Cc: dhowells@redhat.com, pc@manguebit.org, netfs@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Is writeback_iter() missing some error handling? -- was Re: [PATCH] netfs: fix ENOMEM handling in netfs_writepages() to drain all dirty folios
Date: Wed, 22 Jul 2026 15:04:03 +0100 [thread overview]
Message-ID: <82546.1784729043@warthog.procyon.org.uk> (raw)
In-Reply-To: <20260707052555.2055002-1-yun.zhou@windriver.com>
Yun Zhou <yun.zhou@windriver.com> wrote:
> When netfs_create_write_req() fails with -ENOMEM in netfs_writepages(),
> the couldnt_start error path redirties and unlocks the first folio, then
> calls writeback_iter() expecting it to return NULL. However, if the
> mapping contains multiple dirty folios, writeback_iter() returns the
> next one, triggering WARN_ON_ONCE(folio != NULL).
>
> This can be reproduced via 9p (cache=loose) with shared mmap writes and
> fault injection (fail_nth), where v9fs_mmap_vm_close() triggers
> writeback on a mapping with multiple dirty folios during mmap overlap.
>
> Fix this by looping over all remaining dirty folios in the ENOMEM path,
> redirtying and unlocking each one. This ensures all folios taken by the
> writeback iterator are properly released, and they will be retried on
> the next writeback cycle when memory is available.
>
> ...
> --- a/fs/netfs/write_issue.c
> +++ b/fs/netfs/write_issue.c
> @@ -597,10 +597,11 @@ int netfs_writepages(struct address_space *mapping,
>
> couldnt_start:
> if (error == -ENOMEM) {
> - folio_redirty_for_writepage(wbc, folio);
> - folio_unlock(folio);
> - folio = writeback_iter(mapping, wbc, folio, &error);
> - WARN_ON_ONCE(folio != NULL);
> + /* Redirty all dirty folios and let writeback retry later. */
> + do {
> + folio_redirty_for_writepage(wbc, folio);
> + folio_unlock(folio);
> + } while ((folio = writeback_iter(mapping, wbc, folio, &error)));
> } else {
> netfs_kill_dirty_pages(mapping, wbc, folio);
> }
This seems like the wrong thing to do - or, at least, a bug in the
writeback_iter() API. Getting something like ENOMEM would seem to indicate
that all subsequent writeback_iter() calls in this loop are pointless as it
looks like the sequence will just go { lock, undirty, dirty, unlock } for each
folio.
David
next prev parent reply other threads:[~2026-07-22 14:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 5:25 Yun Zhou
2026-07-07 6:13 ` Zhou, Yun
2026-07-19 12:32 ` Zhou, Yun
2026-07-22 14:04 ` David Howells [this message]
2026-07-23 3:43 ` Is writeback_iter() missing some error handling? -- was " Zhou, Yun
2026-07-23 12:44 ` Matthew Wilcox
2026-07-23 4:59 ` Christoph Hellwig
2026-07-23 7:25 ` Zhou, Yun
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=82546.1784729043@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=brauner@kernel.org \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netfs@lists.linux.dev \
--cc=pc@manguebit.org \
--cc=willy@infradead.org \
--cc=yun.zhou@windriver.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome