All of 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: [RESEND RFC PATCH v5 4/4] mm: swap: allow direct reclaim for synchronous multi-page swapin
Date: Sun, 06 Dec 2026 02:34:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-252069@kernel.org> (raw)
In-Reply-To: <20261205023024.3718932-5-zhaonanzhe@xiaomi.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] mm: __swap_cache_alloc() overrides THP defrag policy and leaks
  __GFP_RECLAIM
- [Medium] mm: __swap_cache_alloc() forces __GFP_NORETRY on
  MADV_HUGEPAGE swapin
- [Medium] mm: __swap_cache_alloc() hardcodes order 2 and skips NUMA
  shmem swapin
- [Medium] mm: swap: order-2 GFP override in __swap_cache_alloc() skips
  NUMA shmem
--

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

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

This commit adds __GFP_RECLAIM and __GFP_NORETRY to the allocation gfp
mask for order-2 folios in __swap_cache_alloc() when allocating for a VMA
fault without a mempolicy.

> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index da65d75ceead1..0e703dcc42105 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 | __GFP_NORETRY;

[Severity: High]
Does setting __GFP_RECLAIM here override the THP defrag policy?

With defrag=never or default defrag=madvise on non-MADV_HUGEPAGE VMAs,
vma_thp_gfp_mask() returns GFP_TRANSHUGE_LIGHT to avoid stalling.  Adding
__GFP_RECLAIM enables both direct reclaim and kswapd wakeups, running
synchronous reclaim and direct compaction in the fault path.

Mutating gfp in place also passes __GFP_RECLAIM to
mem_cgroup_swapin_charge_folio(), triggering synchronous memcg reclaim and
drain_all_stock() instead of failing fast to order-0.  Applying it after
thp_shmem_limit_gfp_mask() bypasses the caller's limit_gfp as well.

[Severity: Medium]
Can unconditionally ORing __GFP_NORETRY regress order-2 swap-in for
MADV_HUGEPAGE VMAs?

Under defrag=madvise, vma_thp_gfp_mask() already sets __GFP_DIRECT_RECLAIM
without __GFP_NORETRY for MADV_HUGEPAGE VMAs.  Forcing __GFP_NORETRY makes
__alloc_pages_slowpath() and try_charge_memcg() give up after a single pass
instead of retrying when reclaim makes progress, increasing order-0 fallbacks.

[Severity: Medium]
Should generic swap cache code hardcode order == 2 for zsmalloc multi-page
compression?

CONFIG_ZSMALLOC_MULTI_PAGES_ORDER is configurable from 1 to 3, so when set
to 1 or 3 the actual zram compression order misses direct reclaim while
order 2 triggers it unnecessarily.  It also fires with CONFIG_ZRAM_MULTI_PAGES
disabled or on non-zram synchronous swap devices like pmem, btt, and brd.

[Severity: Medium]
Why is the order-2 adjustment inside the else branch of if (mpol || !vmf)?

shmem_swap_alloc_folio() passes the policy from shmem_get_pgoff_policy() to
swapin_sync().  Under CONFIG_NUMA=y, shmem_get_pgoff_policy() always returns
a non-NULL policy via get_task_policy(), so shmem order-2 swap-in takes the
folio_alloc_mpol() branch and skips the override.

Under CONFIG_NUMA=n, shmem_get_pgoff_policy() returns NULL, so shmem_fault()
enters the else branch while non-fault shmem swap-in still skips it.  Moving
any gfp adjustment before thp_shmem_limit_gfp_mask() would keep NUMA and
non-NUMA shmem behavior consistent and preserve the limit_gfp contract.

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


      reply	other threads:[~2026-12-06  2:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  2:30 [RESEND RFC PATCH v5 0/4] zram/zsmalloc: multi-page compression for large folios Nanzhe Zhao
2026-12-05  2:30 ` [RESEND RFC PATCH v5 1/4] mm: zsmalloc: support objects compressed based on multiple pages Nanzhe Zhao
2026-12-06  2:34   ` sashiko-bot
2026-12-05  2:30 ` [RESEND RFC PATCH v5 2/4] zram: support compression at the granularity of multi-pages Nanzhe Zhao
2026-12-05  2:30 ` [RESEND RFC PATCH v5 3/4] zram: backend_zstd: use multi-page size for zstd parameter setup Nanzhe Zhao
2026-12-05  2:30 ` [RESEND RFC PATCH v5 4/4] mm: swap: allow direct reclaim for synchronous multi-page swapin Nanzhe Zhao
2026-12-06  2:34   ` 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-252069@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 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.