From: sashiko-bot@kernel.org
To: "Kairui Song" <kasong@tencent.com>, linux-mm@kvack.org
Cc: "David Hildenbrand" <david@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Hocko" <mhocko@kernel.org>,
"Qi Zheng" <qi.zheng@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Barry Song" <baohua@kernel.org>,
"Axel Rasmussen" <axelrasmussen@google.com>,
"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
"Baoquan He" <baoquan.he@linux.dev>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Zi Yan" <ziy@nvidia.com>, "Nico Pache" <nico.pache@linux.dev>,
"Ryan Roberts" <ryan.roberts@arm.com>,
"Dev Jain" <dev.jain@arm.com>,
"Lance Yang" <lance.yang@linux.dev>,
"Usama Arif" <usama.arif@linux.dev>,
"Kiryl Shutsemau" <kas@kernel.org>
Subject: Re: [PATCH RFC 8/8] mm/huge_memory: walk the folios reversely for the release loop
Date: Sat, 14 Nov 2026 21:27:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-215048@kernel.org> (raw)
In-Reply-To: <20261114-swap-thp-split-v1-8-dfa8d4fa448d@tencent.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm/huge_memory: __folio_split() skips unlocking and putting
first sub-folio
--
commit 896336ac7b9114a702349806a3b2f69599192c04
Author: Kairui Song <kasong@tencent.com>
mm/huge_memory: walk the folios reversely for the release loop
This commit changes the after-split folio release loop in __folio_split()
to iterate backwards with folio_prev() instead of forwards with
folio_next().
Link: https://lore.kernel.org/r/DKJSFCLP967N.YBR4DNK1NM2N@nvidia.com [1]
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 2ff201a5e5f3b..bb09465a39488 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -4366,7 +4366,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
> const bool is_anon = folio_test_anon(folio);
> const bool is_swapcache = folio_test_swapcache(folio);
> int old_order = folio_order(folio);
> - struct folio *new_folio, *next;
> + struct folio *new_folio, *lock_folio;
> int ret;
>
> VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio);
> @@ -4399,9 +4399,10 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
> * Unlock all after-split folios except the one containing
> * @lock_at page. If @folio is not split, it will be kept locked.
> */
> - for (new_folio = folio; new_folio != end_folio; new_folio = next) {
> - next = folio_next(new_folio);
> - if (new_folio == page_folio(lock_at))
> + lock_folio = page_folio(lock_at);
> + for (new_folio = folio_prev(end_folio); new_folio != folio;
> + new_folio = folio_prev(new_folio)) {
> + if (new_folio == lock_folio)
> continue;
[Severity: High]
Does stopping the loop at new_folio != folio skip unlocking and putting
@folio when @lock_at belongs to a non-head sub-folio (lock_folio != folio)?
__split_huge_page_to_list_to_order() passes its @page argument as @lock_at:
mm/huge_memory.c:__split_huge_page_to_list_to_order() {
...
return __folio_split(folio, new_order, &folio->page, page, list,
SPLIT_TYPE_UNIFORM);
}
When a caller such as try_to_merge_one_page() -> split_huge_page() splits a
large folio on a tail page outside the first sub-folio and then switches to
page_folio(page), the first sub-folio (@folio) is never visited by this
loop and remains permanently locked and referenced, leaking @folio (and its
swap entry if unmapped in swapcache) and hanging any task that later waits
on its folio lock.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261114-swap-thp-split-v1-0-dfa8d4fa448d@tencent.com?part=8
next prev parent reply other threads:[~2026-11-14 21:27 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 21:26 [PATCH RFC 0/8] mm/huge_memory: clean up and speed up large folio splitting Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-13 21:26 ` [PATCH RFC 1/8] mm: add folio_prev() Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-13 21:26 ` [PATCH RFC 2/8] xarray: add xas_prev_canonical() Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-14 21:27 ` sashiko-bot
2026-11-13 21:26 ` [PATCH RFC 3/8] mm/huge_memory: avoid an unnecessary folio size reading Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-13 21:26 ` [PATCH RFC 4/8] mm/huge_memory: walk the after-split file folios in reverse order Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-13 21:26 ` [PATCH RFC 5/8] mm/huge_memory: publish split folios by walking backwards Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-13 21:26 ` [PATCH RFC 6/8] mm/huge_memory: rearrange split routine handling for better optimization Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-13 21:26 ` [PATCH RFC 7/8] mm/huge_memory: walk the after-split anon folios in reverse order Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-13 21:26 ` [PATCH RFC 8/8] mm/huge_memory: walk the folios reversely for the release loop Kairui Song via B4 Relay
2026-11-13 21:26 ` Kairui Song
2026-11-14 21:27 ` sashiko-bot [this message]
2026-11-13 21:40 ` [PATCH RFC 0/8] mm/huge_memory: clean up and speed up large folio splitting David Hildenbrand (Arm)
2026-11-13 21:46 ` 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=sashiko-outbox-215048@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=hannes@cmpxchg.org \
--cc=kas@kernel.org \
--cc=kasong@tencent.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=nico.pache@linux.dev \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=yuanchu@google.com \
--cc=ziy@nvidia.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.