From patchwork Fri Apr 5 01:35:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618349 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 63BBDCD1284 for ; Fri, 5 Apr 2024 01:35:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33D386B00AD; Thu, 4 Apr 2024 21:35:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EF0C6B00B0; Thu, 4 Apr 2024 21:35:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CEAE6B00B2; Thu, 4 Apr 2024 21:35:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D2B126B00AD for ; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8CD711202EF for ; Fri, 5 Apr 2024 01:35:55 +0000 (UTC) X-FDA: 81973761870.25.108998D Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf05.hostedemail.com (Postfix) with ESMTP id EA3EB10000D for ; Fri, 5 Apr 2024 01:35:53 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4C14Ouxz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712280953; 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=l7c0YAXHYAARa4t+azzKsBRh7TpDkWZPSyUcI/Ckh5E=; b=7m6HUrWXe788ymXBiTmSNDDEFqQsflo8ZMBFYu/neQC9C7bxi6xlijselWMBkxkTwDokYg P+mXPV3HZx54uhqK/Dwr0aGLgKAj3VI8gKIWL+D6RNLR+NoHfDlc/MVdtRBrX/7gHUVA7G PZ1bAcg416hChPoqNUAFVdR/Y3JvhVE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4C14Ouxz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of 3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3eVUPZgoKCJgQGKJQ29E658GG8D6.4GEDAFMP-EECN24C.GJ8@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280954; a=rsa-sha256; cv=none; b=pJowheln1+aFp1JOyHcTChnwcN827cPssL9pDbWCMgffG1j0mFLpBOat/0weh44W1/Q9Ml LFCGk9DOwPHiAjfFagCstTHCMJGDSKEmhGK2CnPlT+HiCcAexz2Uu+nu4J2vLnvfqatVpa qoZiupn2cwXUHQs7EaPxWHKJsLHaFyA= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-617bd0cf61fso19983517b3.3 for ; Thu, 04 Apr 2024 18:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280953; x=1712885753; 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=l7c0YAXHYAARa4t+azzKsBRh7TpDkWZPSyUcI/Ckh5E=; b=4C14Ouxzsl3UC4Pc8d4FyLfA2jCrBFFq1G+Z/XjzTGwQGF08kQsq0DQLLpaLLANX5m TfIDHC5XYJQJ32vT0H1klnbUG8sfPf7Pd2QaiwCyC6PiecDPXjqFozxQpNmKHmlY0REc r0foFxCgRxuEG0YmYcojzX964UNvVJOccwNjdUZK9BOBzmRqywOoCzr5NPq/nEP8d/OZ DtrTX+DepFv96iu5snYGSzwgrOd2siw8R7qT4cdva/00PwYXBS8qK0FRFKR57rO+TcKv 6Iq6zicQMNQseiI6f4G/7OyA1VnEO/grG+TOb7pf5YH7qBzHnAKuodlZitpO9SThcNny Obkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280953; x=1712885753; 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=l7c0YAXHYAARa4t+azzKsBRh7TpDkWZPSyUcI/Ckh5E=; b=Lb3iVAdi3Wq5DEHCeYTclf36mWsGxh9366yjHsJQ98NajrS5SkRfaEZbpGldIHxmLb zQvxdh+CkFXzE+qeqL61Nhkkug86bdhO0zRqBO+JJeBJaWGTkaNZQkW44EyrdN+unLMA 4HQlRaMH3FNbACMrsiyhDutargqjmUYNzBWnioUQqeWxJsH+l/VEx3aN3L0+VhTEE3GS R63o81DePP2gOHcEJfINB94ydvwOdQ+3BmloUTNWsTl7QPClChXrgsjPQ8aiaoM6xO3w +0WrmBiAUCiXvlnZfVM1bqdU9A9hrlDjRbUQvqPFJvpNZFqn6sq7yIgm2cC9WAlieXEj iPtg== X-Forwarded-Encrypted: i=1; AJvYcCWGDc6gtt0SBMLuTOpQ7SUbSMtUacWryE69AIzABjkzP+xgUPP5z747c8Md1qu7b7jADcXVZJXcoT4zcDY9POtAoZM= X-Gm-Message-State: AOJu0YzZPxykZOhKB7ZJ1jLyhb9dmzt1GV+OTZ2ZF51hNwy1r655zo25 OmWgs8bYYeiej6GhYQJBx20KATm5jT6GiS5E9HBMqDDKFZvypySwA94FQ33fDfQ9Rc89nAPg99U BGEOZrQH0J/nhA9kitQ== X-Google-Smtp-Source: AGHT+IGnr9sjDIzkHfWFA3r7NPAbrRE0n1gPgA8ilwWP/trrO+2CchhEjdvuhVNlYmxNUVKzC30LK0N41cvBJ/wG X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:24f:b0:615:2f17:17ca with SMTP id ba15-20020a05690c024f00b006152f1717camr300974ywb.8.1712280953119; Thu, 04 Apr 2024 18:35:53 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:44 +0000 In-Reply-To: <20240405013547.1859126-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405013547.1859126-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405013547.1859126-3-yosryahmed@google.com> Subject: [PATCH v1 2/5] 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-Queue-Id: EA3EB10000D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: rbdwen6j8n1jtzozfdrbk3j7sxao17oe X-HE-Tag: 1712280953-83040 X-HE-Meta: U2FsdGVkX1/1MOsJqvSe+cvJlWl6qBc0jQgh+DVhAbSd1VwvGNl0JinCAQeOZDfe3x8lR59PQ8moKXgTfvx/ElecnJ9NLO4kHZNL0+EJbX27K0oRWWShBT23FJTLPRaFqyybwErDfo1Vu8fi3M2WuWd2cwIRz7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ZqGFKanZSOKg4dyZO7KTPSUD8issr5Vl9MFDjTE2xNJljgrNHL9ta3TMM4iV2jugF7PtPCIIFMJNWeigJ1eI6yGWUuo23cMlSBKEQ1XW5fNP3HSAwCY/1rG2mLoamXdqSkeo/2FbZYfXmr7CdC29ZGeNfyi6uqdu0CqS2euOkoi37pseNq0wan9rrZ7uvGYq24= 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 --- mm/zswap.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 1cf3ab4b22e64..fba8f3c3596ab 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1391,6 +1391,21 @@ static void zswap_fill_page(void *ptr, unsigned long value) memset_l(page, value, PAGE_SIZE / sizeof(unsigned long)); } +static bool zswap_check_full(void) +{ + unsigned long cur_pages = zswap_total_pages(); + unsigned long thr = zswap_accept_thr_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 <= thr) { + zswap_pool_reached_full = false; + } + return zswap_pool_reached_full; +} + bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; @@ -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_full()) 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));