From: Greg KH <greg@kroah.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: stable@vger.kernel.org, Sven van Ashbrook <svenva@chromium.org>,
Karthikeyan Ramasubramanian <kramasub@chromium.org>,
Brian Geffon <bgeffon@google.com>,
Curtis Malainey <cujomalainey@chromium.org>,
Jaroslav Kysela <perex@perex.cz>,
Mel Gorman <mgorman@techsingularity.net>,
Michal Hocko <mhocko@kernel.org>, Takashi Iwai <tiwai@suse.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 4.19.y] mm, vmscan: prevent infinite loop for costly GFP_NOIO | __GFP_RETRY_MAYFAIL allocations
Date: Fri, 5 Apr 2024 11:26:35 +0200 [thread overview]
Message-ID: <2024040526-antarctic-figurine-e00f@gregkh> (raw)
In-Reply-To: <20240404153315.1766-2-vbabka@suse.cz>
On Thu, Apr 04, 2024 at 05:33:16PM +0200, Vlastimil Babka wrote:
> Sven reports an infinite loop in __alloc_pages_slowpath() for costly order
> __GFP_RETRY_MAYFAIL allocations that are also GFP_NOIO. Such combination
> can happen in a suspend/resume context where a GFP_KERNEL allocation can
> have __GFP_IO masked out via gfp_allowed_mask.
>
> Quoting Sven:
>
> 1. try to do a "costly" allocation (order > PAGE_ALLOC_COSTLY_ORDER)
> with __GFP_RETRY_MAYFAIL set.
>
> 2. page alloc's __alloc_pages_slowpath tries to get a page from the
> freelist. This fails because there is nothing free of that costly
> order.
>
> 3. page alloc tries to reclaim by calling __alloc_pages_direct_reclaim,
> which bails out because a zone is ready to be compacted; it pretends
> to have made a single page of progress.
>
> 4. page alloc tries to compact, but this always bails out early because
> __GFP_IO is not set (it's not passed by the snd allocator, and even
> if it were, we are suspending so the __GFP_IO flag would be cleared
> anyway).
>
> 5. page alloc believes reclaim progress was made (because of the
> pretense in item 3) and so it checks whether it should retry
> compaction. The compaction retry logic thinks it should try again,
> because:
> a) reclaim is needed because of the early bail-out in item 4
> b) a zonelist is suitable for compaction
>
> 6. goto 2. indefinite stall.
>
> (end quote)
>
> The immediate root cause is confusing the COMPACT_SKIPPED returned from
> __alloc_pages_direct_compact() (step 4) due to lack of __GFP_IO to be
> indicating a lack of order-0 pages, and in step 5 evaluating that in
> should_compact_retry() as a reason to retry, before incrementing and
> limiting the number of retries. There are however other places that
> wrongly assume that compaction can happen while we lack __GFP_IO.
>
> To fix this, introduce gfp_compaction_allowed() to abstract the __GFP_IO
> evaluation and switch the open-coded test in try_to_compact_pages() to use
> it.
>
> Also use the new helper in:
> - compaction_ready(), which will make reclaim not bail out in step 3, so
> there's at least one attempt to actually reclaim, even if chances are
> small for a costly order
> - in_reclaim_compaction() which will make should_continue_reclaim()
> return false and we don't over-reclaim unnecessarily
> - in __alloc_pages_slowpath() to set a local variable can_compact,
> which is then used to avoid retrying reclaim/compaction for costly
> allocations (step 5) if we can't compact and also to skip the early
> compaction attempt that we do in some cases
>
> Link: https://lkml.kernel.org/r/20240221114357.13655-2-vbabka@suse.cz
> Fixes: 3250845d0526 ("Revert "mm, oom: prevent premature OOM killer invocation for high order request"")
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> Reported-by: Sven van Ashbrook <svenva@chromium.org>
> Closes: https://lore.kernel.org/all/CAG-rBihs_xMKb3wrMO1%2B-%2Bp4fowP9oy1pa_OTkfxBzPUVOZF%2Bg@mail.gmail.com/
> Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org>
> Cc: Brian Geffon <bgeffon@google.com>
> Cc: Curtis Malainey <cujomalainey@chromium.org>
> Cc: Jaroslav Kysela <perex@perex.cz>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: Michal Hocko <mhocko@kernel.org>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> (cherry picked from commit 803de9000f334b771afacb6ff3e78622916668b0)
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
All backports now queued up, thanks!
greg k-h
prev parent reply other threads:[~2024-04-05 9:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 15:16 FAILED: patch "[PATCH] mm, vmscan: prevent infinite loop for costly GFP_NOIO |" failed to apply to 4.19-stable tree gregkh
2024-04-04 15:33 ` [PATCH 4.19.y] mm, vmscan: prevent infinite loop for costly GFP_NOIO | __GFP_RETRY_MAYFAIL allocations Vlastimil Babka
2024-04-05 9:26 ` Greg KH [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=2024040526-antarctic-figurine-e00f@gregkh \
--to=greg@kroah.com \
--cc=akpm@linux-foundation.org \
--cc=bgeffon@google.com \
--cc=cujomalainey@chromium.org \
--cc=kramasub@chromium.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=perex@perex.cz \
--cc=stable@vger.kernel.org \
--cc=svenva@chromium.org \
--cc=tiwai@suse.com \
--cc=vbabka@suse.cz \
/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.