From patchwork Thu Apr 18 13:56:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13634790 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9156C04FF8 for ; Thu, 18 Apr 2024 13:58:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 329AF6B009C; Thu, 18 Apr 2024 09:58:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DA6A6B009D; Thu, 18 Apr 2024 09:58:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A3A56B009E; Thu, 18 Apr 2024 09:58:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EFB386B009C for ; Thu, 18 Apr 2024 09:58:50 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9CDE91610D1 for ; Thu, 18 Apr 2024 13:58:50 +0000 (UTC) X-FDA: 82022808420.09.C3C3ABB Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf01.hostedemail.com (Postfix) with ESMTP id B075A4000B for ; Thu, 18 Apr 2024 13:58:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713448728; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=OOnCgQFn63Ck+w5QYoGJFNcFqDBu2x8xYoKPoEtFNfk=; b=PHP1PFEmZUyMYXyCTjY0E19qFgt4vj9MpstT1HhHxrObzUy+25Gs6AbiihI3SdObdUOmgq zrBbFlDLmrxpqzc0nWGLF6hr9Gw/m0Jn9MI2rz54SJKyRIl+P6zl2SbRcfS9E1QQMSYIWD Htb0h3ur5a2X1QdX8oiShYGiiXdQKIg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713448728; a=rsa-sha256; cv=none; b=X59Kp80g6iBETFfaCzjQTbFAMX7TtmNQmJMtPslSIpBfGVwOBQZDyy2pBVsisVGalZHfR2 +saAi3Olz6EOF7lUnEHL7cQEJN3Q9+bKj3EzB09OxBdhqIj1qzcWj6b+DNAwMgrYv56Bgf J9Rtclp33NYWylty5zBbniHaZRY5NEE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VKznd3MHDztXgS; Thu, 18 Apr 2024 21:55:49 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 80B3014044F; Thu, 18 Apr 2024 21:58:43 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 18 Apr 2024 21:58:43 +0800 From: Kefeng Wang To: Andrew Morton CC: , Tejun Heo , Kefeng Wang Subject: [PATCH] mm: swapfile: check usable swap device in __folio_throttle_swaprate() Date: Thu, 18 Apr 2024 21:56:44 +0800 Message-ID: <20240418135644.2736748-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B075A4000B X-Stat-Signature: hrp3sccffwjcxmb7pssyxgu31s4kam3y X-HE-Tag: 1713448727-491641 X-HE-Meta: U2FsdGVkX1/vrNOuW1peYy2ZwEgS4qCAIjKrYdmMh1Hgsa/CwcYGekLRwiWZ+mKHstbGBy+fM4rGYAZmjvBIzhwIQa7lfgZz7kcaPFsdlQGKhgEoY3m2+2NSjzdRdR/X3LW16BJrvZUxVYGTla06muTUI5Qr4tXGOydNTeKM70EIDibD6YPTfi3ynArKPz1NEiJP/wB1ZonOprnQJ5Gh/WUA0JC/kL8p0QgUoPM1d6w41QLPYGN0yf+2ne3L6pr1FaaonojdboMQ0S54osAtJFToPQsTpO3ALgdXDYCADtiT4uj0pMHx4+0Jmr2MNkWkZsSWJ6++CyU+kScE7YUVj1A+zRZ97v+o+pBPpxradYESoLJtXjPIoe7IFTbgLH0Q6XlrOrtgzt9Wqk2h8Ovw/aFA7/Hom2/1GsyPmsIF0dIZNkdvE37W1ioBLAifWXwiCLQqLn2kdXVx6aCcJ1CD114rQzVGk/y5M4cxekUn0xZpVFM0UzViseT+kxFyDKzcQn1u2FIditiaOX/LB4pKPLmSXcsPhj7YvG1pwUCKx5LvyrEsLkd2vJO0R8scYHfzcuxEXfkA0CkNdAD7oFm+FJDlfBhSsiplcg9pSzTmQiuRocUwXS+eSBLlLWod5vgcWwkTwtDjIRdRx9/KZbd2rMMb/PPo7mV3v5Yc4GPUZ8e1qhDtiz+Q0BMsirYyTyDsljGMqHtbQzG/WRVosDQ+N3ztzmsQpoDI/qvGwUVRD6aJbXcTSR43yceDWCjl3sfkAqu+XQyL0AHoy7Fvcr9fJghiCZshNrThcZFITV458wQcIJEeax8HWeBRjRJP2jWoaxl8z2YAw/XPwPjrai5Bxj5834MO4oL2JnaP1i26j/f3yZmDBZeqK7H5UoXbXmS5xxvw/qg7enxSYsyLavI76Q4+rjPGegzAHgaCCGrp0nNQo6XwYCP4LgQxoGku0P4ps/twCrQ7TNSF6iTqJGB 68D/lKhq h2NpwdvIEe6m90lyOvy9YY0URHSV2VQgVdBG4IcCFTDWlQPuLvWNpl0aRc2VwkQXHbPcxHrofmhDd2GlLFmaz09y3vkRoogUdHml0YEQJSReeCkNTmQVtJnmMDxIfop43/s+sOZU2CPTV2gfCZW7m95DJBQJRsucJ8XRDFCBWJFugpfBkIcaq17EEl3t6hbSbo0Un X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Skip blk_cgroup_congested() if no usable swap device since no swapin/out, suppose that no thorottle when swapon/swapoff, so no swap_lock, difference as shows below from perf date of CoW pagefault, perf report -g -i perf.data.swapoff | egrep "blk_cgroup_congested|__folio_throttle_swaprate" 1.01% 0.16% page_fault2_pro [kernel.kallsyms] [k] __folio_throttle_swaprate 0.83% 0.80% page_fault2_pro [kernel.kallsyms] [k] blk_cgroup_congested perf report -g -i perf.data.swapon | egrep "blk_cgroup_congested|__folio_throttle_swaprate" 0.15% 0.15% page_fault2_pro [kernel.kallsyms] [k] __folio_throttle_swaprate Signed-off-by: Kefeng Wang --- mm/swapfile.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 28642c188c93..96606580ee09 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2444,13 +2444,17 @@ static void reinsert_swap_info(struct swap_info_struct *p) spin_unlock(&swap_lock); } +static bool __has_usable_swap(void) +{ + return !plist_head_empty(&swap_active_head); +} + bool has_usable_swap(void) { - bool ret = true; + bool ret; spin_lock(&swap_lock); - if (plist_head_empty(&swap_active_head)) - ret = false; + ret = __has_usable_swap(); spin_unlock(&swap_lock); return ret; } @@ -3710,6 +3714,9 @@ void __folio_throttle_swaprate(struct folio *folio, gfp_t gfp) if (!(gfp & __GFP_IO)) return; + if (!__has_usable_swap()) + return; + if (!blk_cgroup_congested()) return;