From patchwork Fri Apr 5 05:35:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618546 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 05342CD11C2 for ; Fri, 5 Apr 2024 05:35:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A91676B00E9; Fri, 5 Apr 2024 01:35:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0FD6B00EB; Fri, 5 Apr 2024 01:35:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 853006B00EC; Fri, 5 Apr 2024 01:35:21 -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 65A976B00E9 for ; Fri, 5 Apr 2024 01:35:21 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0755F40157 for ; Fri, 5 Apr 2024 05:35:21 +0000 (UTC) X-FDA: 81974365242.21.0D4AEF7 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf01.hostedemail.com (Postfix) with ESMTP id 42A204000D for ; Fri, 5 Apr 2024 05:35:19 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XKgGy6cS; spf=pass (imf01.hostedemail.com: domain of 3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712295319; a=rsa-sha256; cv=none; b=U+wqE3s3M5FD1MtBYe0Mvwaimz/sGw5m8IX8zGQ+/ev2kJpKku9lFgmATEDiixOgVUh82o 4qQaKFJ8e6VLp637Jin3ynH7WlDaFYwVP6DtD7R0T40a5AI4jl+qBZpBavVc+ldtmI8n30 Im6J09S5A0Kv7NUt1p1Ieo1y6Btbmqg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XKgGy6cS; spf=pass (imf01.hostedemail.com: domain of 3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3lo0PZgoKCCcbRVUbDKPHGJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712295319; 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=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=lgksMciua8G9UMMiRrazs8vlMc4RtHLXlShJW2mGX6VfY7Tzrjy7m5VZmc0Z0g7zD21Pz7 9ZPSiITrQ1/CLhrgxxesF6rxcpwhR5eWEI1z9e1jiWXB1cMODrryQ2pVeodk8PjKEBm3z6 twEXeZfaq7ENQuUSZgqbFthMhsrtJXk= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61510f72bb3so31328957b3.0 for ; Thu, 04 Apr 2024 22:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295318; x=1712900118; 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=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=XKgGy6cS2RErH5HmK5dcGAFLTDD8no4tR+3+vWqUMhWTziBob92qID1uuKb49rQp8n GK/iFT0/fBeCfwQTeikqkq8Q+ODdsDQBzmygBZRWf4cyMvXLNm9F18SXi00kt2/MKfdg K/USW/nrLlE4JmeXTpq7inbpTvWpOb+iX1y2zORMdBFSThjM4uHoECdCWzEQSb3tt8tQ 47RSnXI3zD+W0pFAIsCSmAz9BwwO57L4X0uuDxAyQp/fRCMjZ6rBRcVvE6jvQ0agw9vV IBSrsFFR7E0uBsyFDDBCfiQlcVrXHQC3C8XsYA8h1TU1rk46fMi5n8MIDH2hoW94GOog sv1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295318; x=1712900118; 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=WDqFLsTFGLxbu9w6SZiJvC7ASuSVfXA4IdBaekrBdf8=; b=F7xPjf7qj6IT4q63oubSfxXNCGS2b/6EyBCcR7NLPzLUuxQ+1DTYEyHee/t8l3LoBr uMYf5Cn3dyKVsrI6OvWyXkylgOx6OgGUzbNRjYXIFsKkFU1ZxkgO9vo4DJnt0ZAG1+qv n6pe9uWqkIQriuL7j50wbb7VdM7iNvEeGRdhpS/ZhiT55p5jQ0cTTDDHWfPM07fSrRid Xhz0JmRhjpoU7cbLtylmds8QPhXdg+m9Fj19gcLuBt5Pxz1SWFCYrlQjLjDfPX54DpUe 0PugjtV7gFqxDbcvW0UVycA0dYRM8V6dCDBKmUy7qGMy4WOmdE57eYitqVG2FvfPbrsW JZZg== X-Forwarded-Encrypted: i=1; AJvYcCUIyw37H8K51+JKxZKP0jdQQrlgEbqnZTj1BZiRgrcXbDDGJ4PyYKRrPsrgOlvFe357HWjm3XDxT1LBN+tCOrxfIAc= X-Gm-Message-State: AOJu0YwDYG7kAvklpd/ImUPkaCNwTCkuFoGLjCFE6h/lpJS5d+tJlHS3 9QoWL5lWh0+63DM28ufneFqh0Wk3Pa1LVd9xrQS7hT6Shb8d4HTRenitbr0DmX+ouq4WFM8t3YJ jmU4Y60n/fF9BfD+Vrw== X-Google-Smtp-Source: AGHT+IEIkNqISvh3/kP7GIAdlqcFQuxDthw7sLxMpCyp0IlORn7H21arD9nnFY26GvXJUA85AaAzJMEQR86jOyJW X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1893:b0:dcc:5a91:aee9 with SMTP id cj19-20020a056902189300b00dcc5a91aee9mr112599ybb.7.1712295318409; Thu, 04 Apr 2024 22:35:18 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:08 +0000 In-Reply-To: <20240405053510.1948982-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405053510.1948982-4-yosryahmed@google.com> Subject: [PATCH v2 3/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-Server: rspam08 X-Rspamd-Queue-Id: 42A204000D X-Stat-Signature: qxqmw8jeam54d3db3oncq11qpgjrj4gz X-Rspam-User: X-HE-Tag: 1712295319-921742 X-HE-Meta: U2FsdGVkX1/mOOwf0cW/yi7/B3INkgr/ZwZK/EUThlOWpa8Waj4ER/jhuXLsVdwAbf07nMwCDOs90g+xRSp9z3gGYO4i+C38Tjo01mAIy/mxH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Cz8ALzoHDwxAcNRisRnxv9s5A4mBDXvSqkJeEvhX9aJpbiesRq/D7uUOwgTnJDoGK7WF82n65+504i5/6ltKCMDgUJ9/JsHGDelzyC+06q8/XNYYSn8aopjayMnqKNFJHmy4Mzn/9JVLgJjNEfaYFtisRGpR4Ctj3rNA1PDqWiVHudlr56cd2JZEikWDXFjc0qmzZX8SOwG7/a22qq8auCy2DxhByYSNFnxWUNLZ7sw1MJrCtWJGX8CAubc8LRX9WdLX90Qnc04omjXcHE+KYAgIcwowyFoWHq3zqkzqKofcra86ROxfjA0DbEQJ9VOQrGKFWaQCTm7koNw55/3KfCDsk3CjBluK3LSr4kdLsxyRPNFMS+JTLTVD3ldYtT+zVAS0lEDTiOEdqkpKhwZmfNvHmAkyTE0B7mlScexkY2VuHgDFTCkpe4CqZ3n8v7oJjCfJFtG66+h/MCOWkCZDo1pzJS55NVjwR2+zOpuhed4FeILirWiSE/8hdATnNgOQHXC462tGiqjdJfQw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000016, 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 Reviewed-by: Chengming Zhou --- mm/zswap.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 832e3f56232f0..ab3cd43cdfc9d 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1444,6 +1444,20 @@ 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(); + + if (cur_pages >= READ_ONCE(zswap_max_pages)) { + zswap_pool_limit_hit++; + zswap_pool_reached_full = true; + } else if (zswap_pool_reached_full && + cur_pages <= READ_ONCE(zswap_accept_thr_pages)) { + zswap_pool_reached_full = false; + } + return zswap_pool_reached_full; +} + bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; @@ -1452,7 +1466,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)); @@ -1475,20 +1488,8 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - /* Check global limits */ - cur_pages = zswap_total_pages(); - if (cur_pages >= READ_ONCE(zswap_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 > READ_ONCE(zswap_accept_thr_pages)) - goto reject; - else - zswap_pool_reached_full = false; - } /* allocate entry */ entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio));