linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Kairui Song <kasong@tencent.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] mm/filemap: return early if failed to allocate memory for split
Date: Tue, 19 Mar 2024 16:46:06 +0000	[thread overview]
Message-ID: <ZfnBTnXTIGck4lVR@casper.infradead.org> (raw)
In-Reply-To: <20240319092733.4501-2-ryncsn@gmail.com>

On Tue, Mar 19, 2024 at 05:27:30PM +0800, Kairui Song wrote:
> From: Kairui Song <kasong@tencent.com>
> 
> xas_split_alloc could fail with NOMEM, and in such case, it should abort
> early instead of keep going and fail the xas_split below.
> 
> Signed-off-by: Kairui Song <kasong@tencent.com>

The usual way of programming with an xa_state is to not do any error
handling; the xas_ functions check for error and become no-ops, so we
only have to check at the end.

I think this case is worth making an exception for because we avoid
acquiring/releasing the lock.  Not that we should be getting ENOMEM
very often; we only allocate about 8 nodes usually and we get 7
nodes/page.

Acked-by: Matthew Wilcox (Oracle) <willy@infradead.org>

>  mm/filemap.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 7437b2bd75c1..f07ea0b97698 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -880,9 +880,12 @@ noinline int __filemap_add_folio(struct address_space *mapping,
>  		unsigned int order = xa_get_order(xas.xa, xas.xa_index);
>  		void *entry, *old = NULL;
>  
> -		if (order > folio_order(folio))
> +		if (order > folio_order(folio)) {
>  			xas_split_alloc(&xas, xa_load(xas.xa, xas.xa_index),
>  					order, gfp);
> +			if (xas_error(&xas))
> +				goto error;
> +		}
>  		xas_lock_irq(&xas);
>  		xas_for_each_conflict(&xas, entry) {
>  			old = entry;
> -- 
> 2.43.0
> 


  reply	other threads:[~2024-03-19 16:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19  9:27 [PATCH 0/4] mm/filemap: optimize folio adding and splitting Kairui Song
2024-03-19  9:27 ` [PATCH 1/4] mm/filemap: return early if failed to allocate memory for split Kairui Song
2024-03-19 16:46   ` Matthew Wilcox [this message]
2024-03-19  9:27 ` [PATCH 2/4] mm/filemap: clean up hugetlb exclusion code Kairui Song
2024-03-19 16:48   ` Matthew Wilcox
2024-03-19  9:27 ` [PATCH 3/4] lib/xarray: introduce a new helper xas_get_order Kairui Song
2024-03-19 16:52   ` Matthew Wilcox
2024-03-19  9:27 ` [PATCH 4/4] mm/filemap: optimize filemap folio adding Kairui Song
2024-03-19 22:19   ` Matthew Wilcox
2024-03-20  9:06     ` Kairui Song
2024-03-21 18:35       ` Kairui Song

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=ZfnBTnXTIGck4lVR@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).