From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F7FE347BDB for ; Tue, 10 Feb 2026 10:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770718092; cv=none; b=qcaw+6nC5TrPCwzYpNUCGYYMBLEfPCkhP/WnW5BM79/O4XQ6pvNAumWmu8zsqh2enThsnp8j8+MPOjUX7ZoJsxdKa4q+fhsO4C0JUeJaRlxSdzcpi4ZGiiArBa3EhjLO7uXg8gbpytEP+sLkA+OQ8/XVqv9mzKYpo/usT4+FEM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770718092; c=relaxed/simple; bh=El2o5kb3ZLVH9N/8GvK3Pku+1vxo1gzltbIuKG/prPI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dNxmoxS2BBLrVJmZADJ9gtpB3d3EYNuAtylnkOGQl3SEYrXTBQVJNIMQd3/Hge7hxajCjApcYLDvXmG55ZS/vVs2tkudyVshtaSm2eWHUeI3KegtD4u62sFIPfXajbYTrzV5mzSMbPazi+ecOC3RK+oLARhS4C+zvDAsGI4kwiY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=oxcCZdpz; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="oxcCZdpz" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770718080; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=DWoaJhbhh9LSr2qIWoaa8qkMPfZNPVdj8qV+JYMSPq0=; b=oxcCZdpzqVbosi2YFLHiQhy9uAC50+adGlFn26ZF13ArSnZFBo0InsnHbP3QWIJhBjROI8qO4S4Aq9qIdmQmbptZK0lDA+L0DPfiEKxnFHUP+WYvJo4XdToNtgjmHoYGrVwD8jGGspoUJSLd8UA7lpPuPhkQ/4a5ycEXyztRQKk= Received: from 30.74.144.109(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WyypYqH_1770718078 cluster:ay36) by smtp.aliyun-inc.com; Tue, 10 Feb 2026 18:07:58 +0800 Message-ID: Date: Tue, 10 Feb 2026 18:07:57 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [stable-6.6.y] mm: khugepaged refuses to freeze To: Sergey Senozhatsky , "David Hildenbrand (Arm)" Cc: Andrew Morton , Lorenzo Stoakes , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <3d0f189b-faab-4452-b9cc-8f4e7a15025f@linux.alibaba.com> <1179320d-6bab-40a4-a7ac-dbcfbab24623@linux.alibaba.com> <70ed2de7-3e66-4a23-85bb-e0a4c5b61088@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/10/26 11:21 AM, Sergey Senozhatsky wrote: > On (26/02/06 10:00), David Hildenbrand (Arm) wrote: >>>> I recall that there is a notifier when the system is preparing to >>>> sleep (pm notifier or something). Could we simply hook into that to >>>> tell khugepaged to suspend+resume? >>> >>> Do you mean “struct dev_pm_ops”, which is used to register PM callbacks >>> for devices? However, I don’t know how to use it with a kernel thread. >>> >>> Also look at how kswapd does it, kswapd also uses >>> kthread_freezable_should_stop() to check the freeze state. >> >> Right, mimicking what kswapd does sound reasonable! > > I may be missing something, as I'm not seeing dev_pm_ops in vmscan code. > Would something like this work? > > --- > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index fa6a018b20a8..c5d89ec223d3 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -394,8 +394,12 @@ static inline int hpage_collapse_test_exit(struct mm_struct *mm) > > static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm) > { > + bool was_frozen; > + int ret = kthread_freezable_should_stop(&was_frozen); > + > return hpage_collapse_test_exit(mm) || > - mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm); > + mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm) || > + was_frozen || ret; > } Since the hpage_collapse_test_exit_or_disable() can be called by madvise_callapse(), which is not a kernel thread. So I think using the try_to_freeze() is enough? or pass the cc->is_khugepaged to check if current thread is khugepaged.