Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nanzhe Zhao" <zhaonanzhe@xiaomi.com>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, "Jens Axboe" <axboe@kernel.dk>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Minchan Kim" <minchan@kernel.org>,
	"Kairui Song" <kasong@tencent.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Nhat Pham" <nphamcs@gmail.com>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Yosry Ahmed" <yosry@kernel.org>,
	"Chengming Zhou" <chengming.zhou@linux.dev>,
	"Chris Li" <chrisl@kernel.org>,
	"David Hildenbrand" <david@kernel.org>,
	"Ying Huang" <ying.huang@intel.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Kanchana P Sridhar" <kanchana.p.sridhar@intel.com>,
	"Wajdi K Feghali" <wajdi.k.feghali@intel.com>,
	"Bala Seshasayee" <bala.seshasayee@linux.intel.com>,
	"Nick Terrell" <terrelln@fb.com>,
	"Barry Song" <baohua@kernel.org>,
	"Tangquan Zheng" <zhengtangquan@oppo.com>,
	"Bo Zhang" <zhangbo56@xiaomi.com>
Subject: Re: [RFC PATCH v4 4/4] mm: swap: allow direct reclaim for synchronous multi-page swapin
Date: Mon, 16 Nov 2026 02:46:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-216091@kernel.org> (raw)
In-Reply-To: <20261115024455.1465726-5-zhaonanzhe@xiaomi.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] mm: __GFP_RECLAIM without __GFP_NORETRY in __swap_cache_alloc()
  triggers OOM
- [Medium] mm: hardcoded order-2 __GFP_RECLAIM in __swap_cache_alloc()
  bypasses policies
--

commit cb747b328cc1a8c3f1c43755cbc281a7af714c90
Author: Nanzhe Zhao <zhaonanzhe@xiaomi.com>

mm: swap: allow direct reclaim for synchronous multi-page swapin

This commit enables __GFP_RECLAIM for order-2 folio allocations in
__swap_cache_alloc() when allocating via vma_alloc_folio() to improve
multi-page swapin allocation success.

> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index da65d75ceead1..912b0e21a781e 100644
> --- a/mm/swap_state.c
> +++ b/mm/swap_state.c
> @@ -462,6 +462,13 @@ static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
>  	if (mpol || !vmf) {
>  		folio = folio_alloc_mpol(gfp, order, mpol, ilx, numa_node_id());
>  	} else {
> +		/*
> +		 * zsmalloc uses order-2 pages to store compressed data.
> +		 * Allow direct reclaim to improve allocation success and
> +		 * avoid partial reads.
> +		 */
> +		if (order == 2)
> +			gfp |= __GFP_RECLAIM;
>  		address = round_down(vmf->address, PAGE_SIZE << order);
>  		folio = vma_alloc_folio(gfp, order, vmf->vma, address);
>  	}

[Severity: High]
Can setting __GFP_RECLAIM without __GFP_NORETRY or __GFP_RETRY_MAYFAIL
trigger premature OOM kills on order-2 swapin faults instead of falling
back to order 0?

Under the default THP defrag policy (madvise), as well as defer,
defer+madvise, and never, vma_thp_gfp_mask() returns GFP_TRANSHUGE_LIGHT
without __GFP_NORETRY.  Because order 2 is within PAGE_ALLOC_COSTLY_ORDER
(3), adding __GFP_DIRECT_RECLAIM without __GFP_NORETRY causes
__alloc_pages_slowpath() to enter full reclaim/compaction retry loops and
invoke __alloc_pages_may_oom() -> out_of_memory() when an order-2 page
cannot be formed.  The same gfp mask is also passed to
mem_cgroup_swapin_charge_folio() -> try_charge_memcg(), so a cgroup with 1
to 3 pages of headroom triggers mem_cgroup_oom() instead of returning
-ENOMEM and letting __swap_cache_alloc_folio() fall back to order 0.

[Severity: Medium]
Should __swap_cache_alloc() unconditionally override the GFP mask for
order 2 here?

__swap_cache_alloc() is shared by all swap devices even when zram or
CONFIG_ZRAM_MULTI_PAGES is not used, and when multi-page compression is
enabled its order is configured via CONFIG_ZSMALLOC_MULTI_PAGES_ORDER
(1..9) rather than hardcoded to 2.  Or'ing __GFP_RECLAIM after
thp_shmem_limit_gfp_mask(vma_thp_gfp_mask(vma), gfp) also overrides
defrag=never/defer and caller GFP restrictions, and placing it only in the
else branch leaves out the mpol path while causing shmem_fault() swapins
to behave differently between CONFIG_NUMA=y (where
shmem_get_pgoff_policy() returns a non-NULL policy) and CONFIG_NUMA=n
(where it returns NULL).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115024455.1465726-1-zhaonanzhe@xiaomi.com?part=4


      reply	other threads:[~2026-11-16  2:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15  2:44 [RFC PATCH v4 0/4] mTHP-friendly compression in zsmalloc and zram based on multi-pages Nanzhe Zhao
2026-11-15  2:44 ` [RFC PATCH v4 1/4] mm: zsmalloc: support objects compressed based on multiple pages Nanzhe Zhao
2026-11-16  2:46   ` sashiko-bot
2026-11-15  2:44 ` [RFC PATCH v4 2/4] zram: support compression at the granularity of multi-pages Nanzhe Zhao
2026-11-16  2:46   ` sashiko-bot
2026-11-15  2:44 ` [RFC PATCH v4 3/4] zram: backend_zstd: use multi-page size for zstd parameter setup Nanzhe Zhao
2026-11-15  2:44 ` [RFC PATCH v4 4/4] mm: swap: allow direct reclaim for synchronous multi-page swapin Nanzhe Zhao
2026-11-16  2:46   ` sashiko-bot [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=sashiko-outbox-216091@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bala.seshasayee@linux.intel.com \
    --cc=baohua@kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kanchana.p.sridhar@intel.com \
    --cc=kasong@tencent.com \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=senozhatsky@chromium.org \
    --cc=surenb@google.com \
    --cc=terrelln@fb.com \
    --cc=usama.arif@linux.dev \
    --cc=wajdi.k.feghali@intel.com \
    --cc=ying.huang@intel.com \
    --cc=yosry@kernel.org \
    --cc=zhangbo56@xiaomi.com \
    --cc=zhaonanzhe@xiaomi.com \
    --cc=zhengtangquan@oppo.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