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: [PATCH 4/4] mm: swap: allow direct reclaim for synchronous multi-page swapin
Date: Sun, 06 Dec 2026 02:20:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-252056@kernel.org> (raw)
In-Reply-To: <20261205021803.3704464-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 for
  order-2 swapin
- [Medium] mm: __swap_cache_alloc() forces __GFP_NORETRY on
  MADV_HUGEPAGE order-2 swapin
- [Medium] mm: __swap_cache_alloc() hardcodes order 2 ignoring
  ZSMALLOC_MULTI_PAGES_ORDER
- [Medium] mm: __swap_cache_alloc() order-2 override diverges for shmem
  by CONFIG_NUMA
--

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

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

This commit adds __GFP_RECLAIM | __GFP_NORETRY to the gfp mask for order-2
allocations in __swap_cache_alloc() when allocating via vma_alloc_folio().

> 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;
>  		address = round_down(vmf->address, PAGE_SIZE << order);
>  		folio = vma_alloc_folio(gfp, order, vmf->vma, address);
>  	}

[Severity: High]
Does unconditionally adding __GFP_RECLAIM here override the
transparent_hugepage/defrag policy from vma_thp_gfp_mask()?

Because order 2 is within PAGE_ALLOC_COSTLY_ORDER, __alloc_pages_slowpath()
keeps __GFP_DIRECT_RECLAIM despite __GFP_NORETRY.  Under defrag=never or on
non-MADV_HUGEPAGE VMAs, faults on any SWP_SYNCHRONOUS_IO device (such as
brd, pmem, or single-page zram) will stall in direct reclaim and compaction.

Using __GFP_RECLAIM also enables __GFP_KSWAPD_RECLAIM, which GFP_TRANSHUGE
omits.  Mutating gfp in place also passes __GFP_DIRECT_RECLAIM to the later
mem_cgroup_swapin_charge_folio() call, causing blocking memcg reclaim.

[Severity: Medium]
Can unconditionally ORing __GFP_NORETRY regress MADV_HUGEPAGE VMAs?

Under defrag=madvise, vma_thp_gfp_mask() returns GFP_TRANSHUGE without
__GFP_NORETRY for MADV_HUGEPAGE VMAs.  Forcing __GFP_NORETRY here makes
both __alloc_pages_slowpath() and try_charge_memcg() abort after a single
reclaim pass, increasing order-0 fallbacks and partial reads.

[Severity: Medium]
Should this avoid hardcoding order == 2 for zsmalloc in generic swap code?

CONFIG_ZSMALLOC_MULTI_PAGES_ORDER can be configured from 1 to 3, and zram's
is_multi_pages_partial_io() checks against ZCOMP_MULTI_PAGES_SIZE.  When
configured to order 1 or 3, the actual compression order gets no direct
reclaim while order 2 stalls unnecessarily and still incurs partial reads.

This also runs when CONFIG_ZRAM_MULTI_PAGES is disabled or on non-zram
synchronous devices, and assumes a 4 KiB PAGE_SIZE.  Querying a swap-device
or block-layer property would avoid coupling mm/swap_state.c to zsmalloc.

[Severity: Medium]
Why is this override placed in the else branch of if (mpol || !vmf), after
thp_shmem_limit_gfp_mask()?

In shmem_swap_alloc_folio(), shmem_get_pgoff_policy() is always non-NULL on
CONFIG_NUMA kernels (via get_task_policy()), so shmem always skips this
branch.  On !CONFIG_NUMA kernels it returns NULL, making shmem_fault()
diverge from both CONFIG_NUMA and non-fault shmem reads (vmf == NULL).

ORing __GFP_RECLAIM after thp_shmem_limit_gfp_mask() also breaks its
contract that the result never exceeds the caller's limit_gfp reclaim flags.

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


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

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