From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (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 F05BB1DE3DB for ; Wed, 11 Feb 2026 03:10:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.98 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770779407; cv=none; b=cGrqDA8djMi49IZBqoAxTJbA6mrfFRFMJpyqs+HpOph/xL93z3RfSGTnRSRTSLpKngCR6xENRF4wjilas6F+/Qky6Hn3Ef2aakFcKyosDTikGUQ+C6ewfhNKJz1R+FHgqeX/uOiHncoXUCojKkdRLoXAOsGtduARRM2dX+7ItY0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770779407; c=relaxed/simple; bh=hUUbhEGaOLqZCy1/p7Vq/HI1z7EQDvulkHPoKw/3OmE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ulxjgRhb9ZPgBfOKbS5Yu2FYEKlcZ9f5ycyrN8hwakZxSvWWZPPtJV1tkxDmx6ne5h6N1p3bqDeOHZlVtogmYYiXyg7yzAdB8vt9Sq0SnPJXQIubEziu6V27RgZUyerX3PXYpO3NV90yvYymigGSJSvJPRzj33fCfeeHmMkn4xw= 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=bvJHap8h; arc=none smtp.client-ip=115.124.30.98 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="bvJHap8h" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770779398; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=1fvkuiHH7HqSqBbMLyMhpWj5hv20P71nPqWvwq16YUQ=; b=bvJHap8hxL4Y1TMkfkcqHXTpsWyir/rWzz2adiIQw0Z/pVJf4nQoeY8uAgnm+YD4ukjKdt1Z/CSMlLPocBARRNsrT1xIuvG5/OCngEMDLSDJmOtkEw8Ap3QPvPAh4bKbMJEad91635rm/ZRHkxEQsMO2q4vODoycGeCzGCe/2Wc= Received: from 30.74.144.106(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Wz.HSpq_1770779079 cluster:ay36) by smtp.aliyun-inc.com; Wed, 11 Feb 2026 11:04:40 +0800 Message-ID: Date: Wed, 11 Feb 2026 11:04:39 +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: [PATCH] mm: khugepaged: make scan loops suspend aware To: Sergey Senozhatsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan Cc: "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260211030024.232964-1-senozhatsky@chromium.org> From: Baolin Wang In-Reply-To: <20260211030024.232964-1-senozhatsky@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Sergey, On 2/11/26 10:59 AM, Sergey Senozhatsky wrote: > A number of khugepaaged's loops, e.g. khugepaged_scan_mm_slot(), > are time unbound, which can become problematic during system > suspend: > > PM: suspend entry (s2idle) > Filesystems sync: 0.003 seconds > Freezing user space processes > Freezing user space processes completed (elapsed 0.003 seconds) > OOM killer disabled. > Freezing remaining freezable tasks > Freezing remaining freezable tasks failed after 20.004 seconds (1 tasks refusing to freeze, wq_busy=0): > task:khugepaged state:D stack:0 pid:1345 ppid:2 flags:0x00004000 > Call Trace: > > schedule+0x523/0x16a0 > schedule_timeout+0x23b/0x6e0 > io_schedule_timeout+0x3f/0x80 > wait_for_completion_io_timeout+0xe4/0x170 > submit_bio_wait+0x79/0xc0 > swap_readpage+0x150/0x2d0 > swap_cluster_readahead+0x3be/0x750 > shmem_swapin+0xa7/0x100 > shmem_swapin_folio+0xcd/0x2e0 > shmem_get_folio+0x237/0x580 > collapse_file+0x247/0x1280 > hpage_collapse_scan_file+0x26e/0x380 > khugepaged+0x43b/0x810 > kthread+0xfb/0x120 > > > Make hpage_collapse_test_exit_or_disable() suspend aware so > that khugepaaged's scan loops can terminate in a timely manner > and let system enter the sleep state. > > Co-developed-by: Baolin Wang > Signed-off-by: Sergey Senozhatsky > --- I just provided some sample code. Please make sure your patch can be built before submitting a formal patch. Obviously, you should also modify the callers to pass in the 'cc' pointer. > mm/khugepaged.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index eff9e3061925..9b3201fb6840 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -392,10 +392,18 @@ static inline int hpage_collapse_test_exit(struct mm_struct *mm) > return atomic_read(&mm->mm_users) == 0; > } > > -static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm) > +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); > + mm_flags_test(MMF_DISABLE_THP_COMPLETELY, mm) || > + was_frozen; > } > > static bool hugepage_pmd_enabled(void)