From patchwork Fri Apr 5 05:35:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618547 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 E704ACD1284 for ; Fri, 5 Apr 2024 05:35:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A7586B00EB; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62E6D6B00EC; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 481E76B00ED; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 228806B00EB for ; Fri, 5 Apr 2024 01:35:23 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E632640803 for ; Fri, 5 Apr 2024 05:35:22 +0000 (UTC) X-FDA: 81974365284.25.D80C639 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf26.hostedemail.com (Postfix) with ESMTP id 2B8C914000F for ; Fri, 5 Apr 2024 05:35:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tzIeoCuH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712295321; 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=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; b=D1JVKXKbhx8HNMP8UQevA2LKGvlQGZCtFDbR5yZa6Q4u3OEHmdTLXGS7SGdWBsmlENztxV B0ay/LOGvpI+Gu4g6YG93+8KcaGWCJWSnyA+sxS95z/gVEp10Rpkiy3fNGfFUT810i6I9v 8e723iYA6cEYOLx0th12nuxFskGHJkA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tzIeoCuH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3mI0PZgoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712295321; a=rsa-sha256; cv=none; b=2D/KuJC019OlDPVkL5VYjtdED+fyE99emmA2LybnB62M2mE2e3ERjsdJBnqkxNB7EZUQkL t/Nuo/PZCwA6Aiso3zMuua/BcsXoo6/H1CMqSNKUmZ05IG9QoseMEwlloizIAyBm2I6DxI Y3QKV4/1lmNepmhkZpt2GSyq9MSeXGo= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcbfe1a42a4so3078993276.2 for ; Thu, 04 Apr 2024 22:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712295320; x=1712900120; 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=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; b=tzIeoCuHwP29wUW8aLlKa4YtXhxi3NpGjSF+oWQCze08LRmqNXJugwP84zlwmYkhYD 9UWGuikHT1yDcY/dgllkT/uUmSIHwezYeeNd8s1l0DObu1oP82BStBbpJ/T0dKp11O38 SlSSMkebhe9fL1oFbsaLHxNvdzZAtdW3+ZIbz+2GHW9TT2RkCCQLhdq49tEKm72oT6V4 Gvpuufgv3aPX9h9IXhqIA8KIPOiMP9RLaqDfKxYaFT4hq3pJDLTq1F2w7JT09atqud+J I4ZTOvoTEUX+ygz2tYzJIE85bVwxxrfDd12QCmAUzVogPCuPicB+sZ0r2dnzl2jQUTCE ijzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712295320; x=1712900120; 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=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; b=LHDzxxMHzhkLctIsSPRtSeURDCNdZj02tM7g33Zfrf/ZRezrJcaSRjVB9lZYz6MJ3F 39FM+rKFPjvfG8DxmkKpbDAFp1id4D/BmHeVFcYPFuMmN/K5fSez7DiuqWFhtuairNiB L9w8+B9bdgvpYzRqyleH4CyC1lT8dLuxxvlLF7Y5AQLFCoVgPBsHhNJH24qgpEE1S1Zr G6sQsz8vBRdTLFrfxsYycPLTjYeXb89QK5jJLsnrvtfmciccjQxwZaTUAS+PUU5gKPwk Tf5QjWLjjlHCEPitMH4Z0lv7oo1waIBNQM0FzN4g1XSSHLcg7dWvf6+UOJPW5w0BSz3V UKJw== X-Forwarded-Encrypted: i=1; AJvYcCWjeWTFvm0cMrS2yJL9Rk0LstJC/KSj0OowMpguOIlLBdlPn6u8AK3lieox60X+wk+MJ8gkiuxNQS3YiZI6+4qFNGU= X-Gm-Message-State: AOJu0YwEIDwkRqdRvaNyv4sX4NmmvZUM189eKZuV1BySmtxunK2CXa9I RWFEvccBx3McTAr/HcXuVFDdWs2cERVYpy9D1nPU1yX/ZrSO60690/csXfgnLPJMKsmqNveYuGm ikbTitLIZw0LdXWSu2A== X-Google-Smtp-Source: AGHT+IHCdA/5X8U1gt0bJVEbJvMDtws+40Zw9BGN0s2+vFjCACLLPLTtlCpMI+FJ2Yy+eJlQHuE46wlM5C0M0oGx X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a25:f30f:0:b0:dc6:cafd:dce5 with SMTP id c15-20020a25f30f000000b00dc6cafddce5mr105083ybs.12.1712295320201; Thu, 04 Apr 2024 22:35:20 -0700 (PDT) Date: Fri, 5 Apr 2024 05:35:09 +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-5-yosryahmed@google.com> Subject: [PATCH v2 4/5] mm: zswap: move more same-filled pages checks outside of 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-Rspam-User: X-Stat-Signature: 7c4bw1pwr4pr66rns9nm739myrikmrqk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2B8C914000F X-HE-Tag: 1712295320-11087 X-HE-Meta: U2FsdGVkX1/xnISEqWqIAqvMle2tX013oNXAe70gksllFpoeRiQx7hBg4WpZWrwzvqX76t/MIbeNPsIC3tHa10uvefhBCtAFC6FoLb4xTaR3uF5d4PZ0Mv59yh/ebAt64YSlOJXXgN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f7Z4PpHz/gBa1OMuV0WehmHZwLtMqsL6avx3E2xaY/Hp8sddzVZgcQgeX9PiU1Y+QXwTVqgmUmlLSJqL5wW79ZIiawmdnqbp1zNIVkNshJQ1wroIDwvMPtAOxH+DAoZf47h32ym4W/Hm04ItMdPv8dtYp4qlCtGhD8zcqqNTO3nlnoxYuXSaxPMiaVdcyvBdx95jKFMwMuNqKJuviKrPDPLaB0CCwRFn6we3aWuZGuDPTI4zj1NQgIcQrD9Wxms1hwI+tKp8bKrL53G5ioMX4UrlFmUYG0wXg5P/EImuP3PYKNDOmp/2QhnJ8ZZUFiRsq/YcZsblaR1iemXifzGiW+9Qz8AFU6/iZJlEidnt3Y3ybm+nkOucvRFRq38Rs1ZZcMXcuwcVn44LITC7fZrwxP64EeCozry9Z/EYNrYc6nRHkGpIV6DKAMno3U2Yp5mnsV1bG2uu7oDEj4MhrihEu/AwzRNwMD7S2CGz+jJv8yjo5O90jiy04LRt7AXo1h9X40QUNyks2mn2Gjei3+VoISuLIaH2fbxsW0= 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: Currently, zswap_store() checks zswap_same_filled_pages_enabled, kmaps the folio, then calls zswap_is_page_same_filled() to check the folio contents. Move this logic into zswap_is_page_same_filled() as well (and rename it to use 'folio' while we are at it). This makes zswap_store() cleaner, and makes following changes to that logic contained within the helper. While we are at it, rename the insert_entry label to store_entry to match xa_store(). No functional change intended. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou Acked-by: Johannes Weiner --- mm/zswap.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index ab3cd43cdfc9d..13869d18c13bd 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1414,26 +1414,32 @@ static void shrink_worker(struct work_struct *w) } while (zswap_total_pages() > READ_ONCE(zswap_accept_thr_pages)); } -static int zswap_is_page_same_filled(void *ptr, unsigned long *value) +static bool zswap_is_folio_same_filled(struct folio *folio, unsigned long *value) { unsigned long *page; unsigned long val; unsigned int pos, last_pos = PAGE_SIZE / sizeof(*page) - 1; + bool ret = false; - page = (unsigned long *)ptr; + if (!zswap_same_filled_pages_enabled) + return false; + + page = kmap_local_folio(folio, 0); val = page[0]; if (val != page[last_pos]) - return 0; + goto out; for (pos = 1; pos < last_pos; pos++) { if (val != page[pos]) - return 0; + goto out; } *value = val; - - return 1; + ret = true; +out: + kunmap_local(page); + return ret; } static void zswap_fill_page(void *ptr, unsigned long value) @@ -1466,6 +1472,7 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; + unsigned long value; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1498,19 +1505,11 @@ bool zswap_store(struct folio *folio) goto reject; } - if (zswap_same_filled_pages_enabled) { - unsigned long value; - u8 *src; - - src = kmap_local_folio(folio, 0); - if (zswap_is_page_same_filled(src, &value)) { - kunmap_local(src); - entry->length = 0; - entry->value = value; - atomic_inc(&zswap_same_filled_pages); - goto insert_entry; - } - kunmap_local(src); + if (zswap_is_folio_same_filled(folio, &value)) { + entry->length = 0; + entry->value = value; + atomic_inc(&zswap_same_filled_pages); + goto store_entry; } if (!zswap_non_same_filled_pages_enabled) @@ -1533,7 +1532,7 @@ bool zswap_store(struct folio *folio) if (!zswap_compress(folio, entry)) goto put_pool; -insert_entry: +store_entry: entry->swpentry = swp; entry->objcg = objcg;