From nobody Sun Sep 14 00:34:16 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AF9FC38142 for ; Sat, 28 Jan 2023 07:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233192AbjA1HVK (ORCPT ); Sat, 28 Jan 2023 02:21:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232929AbjA1HVG (ORCPT ); Sat, 28 Jan 2023 02:21:06 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8176588CCF for ; Fri, 27 Jan 2023 23:20:55 -0800 (PST) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4P3m5z2lVhzJsF6; Sat, 28 Jan 2023 15:19:19 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sat, 28 Jan 2023 15:20:50 +0800 From: Longlong Xia To: CC: , , , , , , Longlong Xia Subject: [RFC PATCH] mm/swapfile: add cond_resched() in get_swap_pages() Date: Sat, 28 Jan 2023 07:20:14 +0000 Message-ID: <20230128072014.1030445-1-xialonglong1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We found that the plist_for_each_entry_safe() loop in get_swap_pages() could reach tens of thousands of times to find available space (extreme case: cond_resched() is not called in the loop). The test scenario is like commit de1ccfb64824 ("swapfile: fix soft lockup in scan_swap_map_slots") does. On the other hand, scan_swap_map_slots() needs to reach LATENCY_LIMIT before calling cond_resched(), so cond_resched() is needed when failed to find available space to avoid softlockup. Signed-off-by: Longlong Xia --- mm/swapfile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 908a529bca12..4fa440e87cd6 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1100,6 +1100,7 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entrie= s[], int entry_size) goto check_out; pr_debug("scan_swap_map of si %d failed to find offset\n", si->type); + cond_resched(); =20 spin_lock(&swap_avail_lock); nextsi: --=20 2.25.1