From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 1175523A564 for ; Wed, 11 Feb 2026 01:04:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770771844; cv=none; b=UBvdgEfr4tILAKPSFHfVIyFJV3hAkgn/GBDdkRUG7qZH0BQ+q1HXMhCfedYucQFTU+c2sJi1O7RQzLVajsWrTGoE18c/RSy82NCVDfxlPxWN1G0Vi5mKSRUNeYK0fcaRJ7JEjjc1JnW068q7vCL0G22J1VLwfbT6R+Hruh6hj18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770771844; c=relaxed/simple; bh=TqdhwrmNEPdLCIHbi7fcu4lmATFZW1rmRnZY4XIrz4s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=CJv1mDqOEX8Ix67YjUXH9SlsCIWDrPh6/zRCC38Y4lkOBHDeLN8O+Lb/tx1guNd6Hz0aXI6dK7Gnyu8/jFmfz9y3/UKuoNzgjU7dDPuK3XTRFaqarV3rZ0wINRhzc7dqH/O+TMkC3Wfz+E6tF7Uvp7yOvJyCA2haucS0wq4833E= 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=eigzsu9v; arc=none smtp.client-ip=115.124.30.132 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="eigzsu9v" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770771834; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=5m2AbjOPxKKnOcMkXmc4uuC7NcmlCqX4pUjFET6O+r8=; b=eigzsu9vwxUZTeJgh9sN52cYfRYQJ/nVCnWQ7WQvvOMHE2fKSgWL6LiT2SDLr4EM+uH2oJfRp6CaP00Lo/t8wInsboP/KDdzBR0fOd7S78Ep2Kt/+tiCHdAwC6Pun7MoE9RXRnBGnnewkBcMPV1boDAI7xi99xgcasPtw+Q4Ebc= Received: from 30.74.144.106(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Wz-ykxt_1770771831 cluster:ay36) by smtp.aliyun-inc.com; Wed, 11 Feb 2026 09:03:52 +0800 Message-ID: Date: Wed, 11 Feb 2026 09:03:51 +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: "David Hildenbrand (Arm)" , Sergey Senozhatsky 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 6:21 PM, David Hildenbrand (Arm) wrote: > On 2/10/26 11:07, Baolin Wang wrote: >> >> >> On 2/10/26 11:21 AM, Sergey Senozhatsky wrote: >>> On (26/02/06 10:00), David Hildenbrand (Arm) wrote: >>>> >>>> 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. > > Which raises the question whether we should forward that context > (khugepaged vs. madvise) to hpage_collapse_test_exit_or_disable(). Passing in the 'cc' pointer looks fine to me. Something like: static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm, struct collapse_control *cc) { bool was_frozen = false; if (cc->is_khugepaged && unlikely(kthread_freezable_should_stop(&was_frozen))) return 1; return hpage_collapse_test_exit(mm) || mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm) || was_frozen; } Sergey, could you submit a formal patch for review?