From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Zi Yan <ziy@nvidia.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [stable-6.6.y] mm: khugepaged refuses to freeze
Date: Fri, 6 Feb 2026 13:12:56 +0800 [thread overview]
Message-ID: <1179320d-6bab-40a4-a7ac-dbcfbab24623@linux.alibaba.com> (raw)
In-Reply-To: <h3bbxn4omwe2jv32vyjou34me73x5nwg6ai57goqo2qlntq73y@ra75spa3tlzr>
On 2/6/26 12:31 PM, Sergey Senozhatsky wrote:
> On (26/02/06 12:38), Sergey Senozhatsky wrote:
> [..]
>>>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>>>> index eff9e3061925..fa6a018b20a8 100644
>>>> --- a/mm/khugepaged.c
>>>> +++ b/mm/khugepaged.c
>>>> @@ -1894,6 +1894,9 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
>>>> xas_set(&xas, index);
>>>> folio = xas_load(&xas);
>>>> + if (try_to_freeze())
>>>> + goto xa_unlocked;
>>>> +
>>>> VM_BUG_ON(index != xas.xa_index);
>>>> if (is_shmem) {
>>>> if (!folio) {
>>>
>>> Your analysis is reasonable. When the system is freezing, khugepaged is
>>> still trying to swap-in shmem to collapse, which prevents the system from
>>> entering suspend state. However, it’s not only shmem that will swap in,
>>> collapsing anonymous folios may also trigger swap-in operations.
>>
>> Right, I thought about it but wasn't sure. Could the inner loop (e.g.
>> collapse_file() in this particular case) loop long enough to fail suspend
>> w/o ever giving the outer loop (khugepaged_do_scan()) a chance to freeze?
Yes, that’s possible. However, if we add a try_to_freeze() check in the
inner loop, we need to consider various scenarios (such as anonymous
folio swap-in and other potential cases?), which feels too hacky to me.
> For inner loops I wondered if cond_resched() could be an indicator of
> where try_to_freeze() should be placed. Those cond_resched() calls
> are there for a reason, after all. E.g. something like:
>
> ---
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index fa6a018b20a8..cee08466a069 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2431,6 +2431,9 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, enum scan_result
> unsigned long hstart, hend;
>
> cond_resched();
> + if (try_to_freeze())
> + break;
> +
> if (unlikely(hpage_collapse_test_exit_or_disable(mm))) {
> progress++;
> break;
> @@ -2453,6 +2456,9 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, enum scan_result
> bool mmap_locked = true;
>
> cond_resched();
> + if (try_to_freeze())
> + goto breakouterloop;
> +
> if (unlikely(hpage_collapse_test_exit_or_disable(mm)))
> goto breakouterloop;
This looks better than the previous version. Let’s also wait to see if
others have any better suggestions.
next prev parent reply other threads:[~2026-02-06 5:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 2:47 Sergey Senozhatsky
2026-02-06 3:33 ` Baolin Wang
2026-02-06 3:38 ` Sergey Senozhatsky
2026-02-06 4:31 ` Sergey Senozhatsky
2026-02-06 5:12 ` Baolin Wang [this message]
2026-02-06 8:36 ` David Hildenbrand (Arm)
2026-02-06 8:55 ` Baolin Wang
2026-02-06 9:00 ` David Hildenbrand (Arm)
2026-02-10 3:21 ` Sergey Senozhatsky
2026-02-10 10:07 ` Baolin Wang
2026-02-10 10:12 ` Sergey Senozhatsky
2026-02-10 10:21 ` David Hildenbrand (Arm)
2026-02-11 1:03 ` Baolin Wang
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=1179320d-6bab-40a4-a7ac-dbcfbab24623@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=senozhatsky@chromium.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox