From nobody Tue Dec 2 00:46:32 2025 Received: from out28-51.mail.aliyun.com (out28-51.mail.aliyun.com [115.124.28.51]) (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 38FD92DFA2D for ; Mon, 24 Nov 2025 06:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763967087; cv=none; b=Psw5inBsig91twaqXzDgH8CY+35nwwdFxktS38wYCm/+fIjFSoBFBoy/KOUCNX1SHI3Ovi71OKstV9TP+O1WX0ZvCk7Gqk4D7vOsQVAtTeSEYTtxAEfmOZapya5oesxPA83ysZM4Pmm28tz+iC2SW2rFci2Bklwm9YRc1DDvDbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763967087; c=relaxed/simple; bh=+SfmgeJC7BmzN6G5tbETkb4Ue85KIMPk8uVUDHyzKE0=; h=From:To:Cc:Subject:Date:Message-Id; b=bXWSgz34HGzUk5P3kb/tVaV2fQvWnsr6ysv2BrQCMkRbyWschyT2q8w3yy8jFq9Dmo+pyPDE39ROTDcXWzD2H4+yc7hF8X9MOlU5isSvn//mcoKShfD3LSIYrgP1yzYbyPux6H5XXPYjiK2haWeCQxh88D4yfNJFmTUOX7ctz90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=CO698A2A; arc=none smtp.client-ip=115.124.28.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="CO698A2A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1763967075; h=From:To:Subject:Date:Message-Id; bh=21RHootz6QRBrJkseztSpqOrZvyghcAQRZ1d5BBCZLs=; b=CO698A2AU2rEprWNVw24ftCfaMTHiGww4STWgGz0r7JdnAn/j4u1H5tvPf3oSr80EKUzobJ008ziVuW3t8a6Cqpx7JH07581a7GADXYpSHcNUvMw0GdihZIVQaYnlFkaBwRTg0jv5Ni4rYWi+6x7/8cX7u1ceA62rdX+jiZru2U= Received: from i85a15111.eu95sqa.tbsite.net(mailfrom:junchuan.tzh@antgroup.com fp:SMTPD_---.fUM99rp_1763965205 cluster:ay29) by smtp.aliyun-inc.com; Mon, 24 Nov 2025 14:20:21 +0800 From: Zhiheng Tao To: akpm@linux-foundation.org, david@kernel.org, lorenzo.stoakes@oracle.com Cc: ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, shy828301@gmail.com, zokeefe@google.com, peterx@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhiheng Tao Subject: [PATCH] mm/khugepaged: Fix skipping of alloc sleep after second failure Date: Mon, 24 Nov 2025 14:19:17 +0800 Message-Id: <1763965157-58413-1-git-send-email-junchuan.tzh@antgroup.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In khugepaged_do_scan(), two consecutive allocation failures cause the logic to skip the dedicated 60s throttling sleep (khugepaged_alloc_sleep_millisecs), forcing a fallback to the shorter 10s scanning interval via the outer loop Since fragmentation is unlikely to resolve in 10s, this results in wasted CPU cycles on immediate retries. Reorder the failure logic to ensure khugepaged_alloc_sleep() is always called on each allocation failure. Fixes: c6a7f445a272 ("mm: khugepaged: don't carry huge page to the next loo= p for !CONFIG_NUMA") Signed-off-by: Zhiheng Tao --- mm/khugepaged.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index abe54f0..c3f9721 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2562,12 +2562,12 @@ static void khugepaged_do_scan(struct collapse_cont= rol *cc) if (result =3D=3D SCAN_ALLOC_HUGE_PAGE_FAIL) { /* * If fail to allocate the first time, try to sleep for - * a while. When hit again, cancel the scan. + * a while. When hit again, sleep and cancel the scan. */ + khugepaged_alloc_sleep(); if (!wait) break; wait =3D false; - khugepaged_alloc_sleep(); } } } --=20 1.8.3.1