From: Dave Chinner <david@fromorbit.com>
To: "Raphael S. Carvalho" <raphaelsc@scylladb.com>
Cc: linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
djwong@kernel.org, hch@lst.de, willy@infradead.org
Subject: Re: [PATCH v3] mm: Fix error handling in __filemap_get_folio() with FGP_NOWAIT
Date: Wed, 26 Feb 2025 07:25:46 +1100 [thread overview]
Message-ID: <Z74nSu3q2b3sy5wY@dread.disaster.area> (raw)
In-Reply-To: <20250224143700.23035-1-raphaelsc@scylladb.com>
On Mon, Feb 24, 2025 at 11:37:00AM -0300, Raphael S. Carvalho wrote:
> original report:
> https://lore.kernel.org/all/CAKhLTr1UL3ePTpYjXOx2AJfNk8Ku2EdcEfu+CH1sf3Asr=B-Dw@mail.gmail.com/T/
>
> When doing buffered writes with FGP_NOWAIT, under memory pressure, the system
> returned ENOMEM despite there being plenty of available memory, to be reclaimed
> from page cache. The user space used io_uring interface, which in turn submits
> I/O with FGP_NOWAIT (the fast path).
....
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 804d7365680c..3e75dced0fd9 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1986,8 +1986,19 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
>
> if (err == -EEXIST)
> goto repeat;
> - if (err)
> + if (err) {
> + /*
> + * When NOWAIT I/O fails to allocate folios this could
> + * be due to a nonblocking memory allocation and not
> + * because the system actually is out of memory.
> + * Return -EAGAIN so that there caller retries in a
> + * blocking fashion instead of propagating -ENOMEM
> + * to the application.
> + */
> + if ((fgp_flags & FGP_NOWAIT) && err == -ENOMEM)
> + err = -EAGAIN;
> return ERR_PTR(err);
> + }
> /*
> * filemap_add_folio locks the page, and for mmap
> * we expect an unlocked page.
Looks good to me.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
prev parent reply other threads:[~2025-02-25 20:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-24 14:37 Raphael S. Carvalho
2025-02-24 14:45 ` Christoph Hellwig
2025-02-24 15:34 ` Matthew Wilcox
2025-02-25 20:25 ` Dave Chinner [this message]
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=Z74nSu3q2b3sy5wY@dread.disaster.area \
--to=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=raphaelsc@scylladb.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox