From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (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 02F116F2F2 for ; Fri, 6 Feb 2026 05:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770354788; cv=none; b=ROQOf9+AFSHy5d0ebwQzSvzohSZxhZGLwMwSYhDIzsMVm9vcnHjrZ3AFkXYc3cdiPAkeErAVsTebf28UfybTwAHUPgaeuHGr4C7VKaVU0HGD2AdOVrdeS+E6rb/vHb3Il9LaPV7yRg3M1QfYtgCwpxCRsznCAP7BtWbGi1qimzE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770354788; c=relaxed/simple; bh=qvk/Wf14HpYa88csoWOYqIglSZi9nK85aC5ScbSLdBI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HjDLdOVkfJ5LVsSuu/xxL1SEU1G1JzKHXAbV44+3uW6zcqsF5wTCRln3Xyv6yzeEWnU/TtDLziLggqHGBQKnTiD5R/djnE0w/k2MShMLV8jFnvZG9AvHHZP5trwDboACXkaDFMsEhx/Jt1Nfxtbu/1X9YBKco7QD4x/cBDDQWCY= 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=R7hh7Eus; arc=none smtp.client-ip=115.124.30.101 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="R7hh7Eus" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770354779; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=l3AhZNM4Q5k2W3T5e95C5Di+O3vwziEW75l5gal323E=; b=R7hh7Eus3hAtc9x/ZOs0GNE3RjyeIk21nE/Tw4y3+bCrJiIsqdsbuYE7vnILUZflocE+WcM6ivOdYSPbGJL22RWUyRSK9bZ/Hi8N+W8VZGFmidSPr4/oDY8TEI5YcZmMg0JKdfu3u8nWMzAybt6jzhJcHuTDH4Q0RVYBl0dsrk4= Received: from 30.74.144.131(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WydO178_1770354776 cluster:ay36) by smtp.aliyun-inc.com; Fri, 06 Feb 2026 13:12:57 +0800 Message-ID: <1179320d-6bab-40a4-a7ac-dbcfbab24623@linux.alibaba.com> Date: Fri, 6 Feb 2026 13:12:56 +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 Cc: Andrew Morton , David Hildenbrand , 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> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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.