From patchwork Sat Apr 13 02:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13628596 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 3A256C4345F for ; Sat, 13 Apr 2024 02:24:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50D486B008C; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 445A66B0092; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E92C6B0093; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0A5306B008C for ; Fri, 12 Apr 2024 22:24:16 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C4BBD120760 for ; Sat, 13 Apr 2024 02:24:15 +0000 (UTC) X-FDA: 82002914070.30.CB8FA97 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf17.hostedemail.com (Postfix) with ESMTP id 08AC34000F for ; Sat, 13 Apr 2024 02:24:13 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tttt37ak; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712975054; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pFcpj0TvebZcgya6byXyrm5KOadn+Q+ON/Bz5Cqkl5I=; b=QKBHE5z8RmN4s7SRdZcxuIXx7VeLEHHuV+APM4Sv5idqxReQ0k8PKcHeEGDXphoviRMeED BWxzRZaXosMiuqHsroMvhofKvnQGqS5eXp3N/Iw/XDLpd8rURZb7PUgX3GhaGLxmX09fgJ 8ESUHKMNOkBI+YlflUeSXFlMJRKyA7Y= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tttt37ak; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3zewZZgoKCEY6w0z6ipumlowwotm.kwutqv25-uus3iks.wzo@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712975054; a=rsa-sha256; cv=none; b=NCdu2nmuInoJt41Ua2em7XyF4REqiSQt15AAej2ktqdYAhOTba3HyqC8ypC9Z1CLExezQl QT49DXbtryzk0xdR3S/Q5AREmF9ejtj2SMXqgw9FW+nTSA5kbYqyM1dxcb6c4slzgVqGew wT+qUiBJT44hK0ujD8pYSBG17F8AGk8= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60a2386e932so30661987b3.1 for ; Fri, 12 Apr 2024 19:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712975053; x=1713579853; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pFcpj0TvebZcgya6byXyrm5KOadn+Q+ON/Bz5Cqkl5I=; b=tttt37ak0nCpBt78G06Pe5Ji0RkH/a+4HPBs94GhA88jCh9NlEwKtHAyuRxHWUCnYV KEuX16lN0kyYW7GdOnR11rWd9pWAAsJUwaFyhZUBr5VfLjuR1QrwysCJtf5dqXfImCH/ 8eimo3jLf6LIDYgNSnuV5sePy1R9swLbPraLCOJoc4ynTKJCBtupWdtQrHdj6p73fUlr gm/aG6OTKX77ro/4qLF4F12CGMBXSegMUY4wzrxif0ZOl7RWISJbOrTG9qvyKsCJBLUx og4iuv/Wwe2qNTm4Xd1NWZA6avCV1DiuJse9kl00py/yQwEjtj79slxpp28pbkBIN+F6 bC4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712975053; x=1713579853; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pFcpj0TvebZcgya6byXyrm5KOadn+Q+ON/Bz5Cqkl5I=; b=ph2j2o5ASVQBZociwfNy+ap+DX/krmuIqO1nVNk8rT2rO68s6c/7Jtwq0wZ73fj/Gw mi/mgWJ7/63b0Xl4et+5COy8wtpKm54rSGWtOw0zPZuMg0lWUMYTGSQBimfXkN0yumPS uC7aYnWqCko9IqN0fLYOIM+s0nhq+q4070tYYAZ8uL3Anlabk/OtFoKzWocQ0X/kCGiO Y1qUhbXxxm+kiYC1OjhNCPZUbk9Vvvv5vVWjvXNq7j27/QQJ2czHnT3san5Ott3+i7AI vKhycCYtk8Uhs9GPCF726SBYq3PiVkQS9YTQQ4y4nQ/VdBzfhxYF8xdH86fufTvCTBf8 QLeQ== X-Forwarded-Encrypted: i=1; AJvYcCVUKb/sbEKIHdVUaV04Z0Um+9CsWHthnovjvh7oxhm2J/X8cVXB3zw2zmhX4ZZXWE4vwlVJSOTyXtzAPZG+EtosAFw= X-Gm-Message-State: AOJu0Yw8kiUoWlrjk5hE88FdG2/jF9vFUIY+vT0yN80Y+d+Ef6jmdsc1 FLDuKl2dmf9xYsUR9WSCfvt1WuP2EXfvCbGDZXa2yPSHMiEkJM1g2fhthldi+jU7nvDI0eu6IRd y9qGFMBCcTnenGgMO7w== X-Google-Smtp-Source: AGHT+IHAlbeOydfvBUQ+AYR1qIuBuBzl/BOKahweaVpfLg8kz58GaVMgBySWi8xxEMGZJABW5nfoPZGjO8NmCCMB X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a0d:e209:0:b0:618:80c0:1a2e with SMTP id l9-20020a0de209000000b0061880c01a2emr834009ywe.6.1712975053165; Fri, 12 Apr 2024 19:24:13 -0700 (PDT) Date: Sat, 13 Apr 2024 02:24:05 +0000 In-Reply-To: <20240413022407.785696-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240413022407.785696-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Message-ID: <20240413022407.785696-3-yosryahmed@google.com> Subject: [PATCH v3 2/4] mm: zswap: refactor limit checking from zswap_store() From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 08AC34000F X-Stat-Signature: eqksuwfjg13wxeugpu1p7mtxs9w1cw5i X-Rspam-User: X-HE-Tag: 1712975053-414122 X-HE-Meta: U2FsdGVkX1+nc5QfX2z1Zaro4Z6iVQ5Mc6qxQheSDY+0ER2zNKi+ERLVyUjol05/w/S/8HJEoiIpbmBwm0wxNd5Ub4ldivhp54B7ZaTXMQYILlxuhrMh4DcypwHYLEzRkBiWyt3/RkRTytgYJmoY4rhfIaQQAxChLAJuEhyDeNKE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TUQ9s7Fub0urTwVfAkgZazs9N4BnH8afAA7HPb5Dgt4Cvr+J5qHlxhJsB4ak+6Odzy2XBlrOk1/eDaE4BIP1cVzZtyDReZblQ9+fO3RJtaeSJ4LKbuBSr6aUpMh/lbFfczoqJm5SRE1sWMw6Qey7sEL/M5m7X/I2ssxovHov4lzX1f8ZMxnhw0wH78F0zppGutY9MuV7wG9dJZMyotiZY0VaU7ca99GOSMXxdCxpgO58hiOaMHyoGJLOhFZxZaWhZSIwv3ks3TjbMWPsYyFvfG81tpFW+N+Nn7URgkaTWgujZh96WcNCSWxhSEbgdVnQTMPrj7PNQlKrdo+WLfpYFRCiJ91IuOfy9tbMEpFg+uVltZezf99A5+69uLeied+AS+sa0YlKFbGccpN6x55yD1sp6OQ== 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: Refactor limit and acceptance threshold checking outside of zswap_store(). This code will be moved around in a following patch, so it would be cleaner to move a function call around. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham --- mm/zswap.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 77b6bb2099763..7cddbca3ac62c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -517,6 +517,21 @@ unsigned long zswap_total_pages(void) return total; } +static bool zswap_check_limits(void) +{ + unsigned long cur_pages = zswap_total_pages(); + unsigned long max_pages = zswap_max_pages(); + + if (cur_pages >= max_pages) { + zswap_pool_limit_hit++; + zswap_pool_reached_full = true; + } else if (zswap_pool_reached_full && + cur_pages <= zswap_accept_thr_pages()) { + zswap_pool_reached_full = false; + } + return zswap_pool_reached_full; +} + /********************************* * param callbacks **********************************/ @@ -1399,7 +1414,6 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; - unsigned long max_pages, cur_pages; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1422,22 +1436,8 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - /* Check global limits */ - cur_pages = zswap_total_pages(); - max_pages = zswap_max_pages(); - - if (cur_pages >= max_pages) { - zswap_pool_limit_hit++; - zswap_pool_reached_full = true; + if (zswap_check_limits()) goto reject; - } - - if (zswap_pool_reached_full) { - if (cur_pages > zswap_accept_thr_pages()) - goto reject; - else - zswap_pool_reached_full = false; - } /* allocate entry */ entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio));