From patchwork Mon Mar 25 23:50:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13603185 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 9F39FC54E58 for ; Mon, 25 Mar 2024 23:50:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 805BD6B0088; Mon, 25 Mar 2024 19:50:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78C7D6B0089; Mon, 25 Mar 2024 19:50:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DE9C6B008A; Mon, 25 Mar 2024 19:50:29 -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 425C76B0088 for ; Mon, 25 Mar 2024 19:50:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 110A4A0A99 for ; Mon, 25 Mar 2024 23:50:29 +0000 (UTC) X-FDA: 81937208178.08.5253B8A Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 4CF3918000E for ; Mon, 25 Mar 2024 23:50:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lS941FnH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3wg0CZgoKCB0RHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3wg0CZgoKCB0RHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711410627; 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=+3t/0JKEdL4mJ/vvKrn6t1zV3oNIlUMv4pczMFevQsk=; b=fVIzdyn5bfTX8Mna9sPMpuHilYqOcBCeq0TX60x7TqjZW6HXIhMMLLSMEZFkzcvKSbBlup 3VVo0gLnOXGQirvI2pzD2BiPKUV+O3iDo1K+AtOrlTnSzTHJx33UZgxpNtVPbCgDuNtLcG kPyMjIQSpu8q+WWjD4wbAHHA27YQ+CE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lS941FnH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3wg0CZgoKCB0RHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3wg0CZgoKCB0RHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711410627; a=rsa-sha256; cv=none; b=LwAUjzwmhewoZYsg2Oh0CGfp4Bdc/3Gjt2LSn8VsfGX8fRNtv/kpMa5ZuJwEEWrnNwcwHl i336HJNNBhS53miKo4FM+aFsUgRpFTgQ6zzakrTUgixdmHU0n8t7pAw9PvKOQoOqfU5T/s aVygn4k0n+WOQObW+VOdWYZIFYH3/sA= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc693399655so9148470276.1 for ; Mon, 25 Mar 2024 16:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711410626; x=1712015426; 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=+3t/0JKEdL4mJ/vvKrn6t1zV3oNIlUMv4pczMFevQsk=; b=lS941FnHlnffa2C6nL1yI0YqZiv44baydsU7kR+IOCzGJ2ewU5rxiG2nDmLIrPVMyb WgKM3A65rfR5JyfCPun+2lHXwfVnJa0QmSXFZp1N84gmrDbKQCZFpg93QtNZZPB5urhs IpMzMziE2cYCSaG88vPw5SH3I0C7gWZwlWxLzRFJxhhGdtopqKIicFnQonTBnkqm6mio FkolHPEd5ud4VU3koHEHfrQebm6F3b4Tg9p21YVJo3dVSutYPR1IsO9sbn5I2Z0g0Y5L SYxB1DGZqm4KkwLotECl4z1aW+SupHbafuRg+WuecgyZh3Xu9njbcXdECgPl7SziSzTn 7ANA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711410626; x=1712015426; 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=+3t/0JKEdL4mJ/vvKrn6t1zV3oNIlUMv4pczMFevQsk=; b=t7C7yB/BjjnoD7LFjGQw5/jKT6KUrtSfbgZwejLSrmukcc/syWm0hQg65r2377FBqD P5ZVlHv/prm/6ba3EeeRQ9n1sKgWVtChr3BAWOJpYck0oGSyL7eV/nzcBS4lH6XT8u3N v7H7H9PcFrLvfW5JZz7azkTpMT24or8ixFHG63Nsxdu5XhV0Nmz0UeOQ8og7hUKCYuQo n3QKZhM6cteDY5XYKcR89XK5/M6jSA2jC7X9P0HK1OoWPPrgjxj61AtG0SLpd44kx8E7 kwXL79pZSdPJt/Gm/I73X/IiTK9xNxNp+fcLDvUuUS5vtcATG1QTWZVOjpnuXMvY/daa nlkA== X-Forwarded-Encrypted: i=1; AJvYcCXUhk+EMynjott5IAjy76OaV57w0+0NvS5NXM9U8nJJ9JTIgh/oNT2oZlZUtWMfnPbupuN5vaxRjfxOHwI9tx7eC4E= X-Gm-Message-State: AOJu0YwLUMY8uEXg0qDclRPS4JhvOUKxuQ6sw2a6Eu+CXOxdwaFUgQHc Dzi0zX1s5HjrYlVXyE10m5N6DUjKWT/gdB2XT6h1x0fVbiP56XrPYczgHkfTqUveHYO2900R+/X +mW4N9SFjCUfg88MOng== X-Google-Smtp-Source: AGHT+IGK+u8xbKSjmKMyfk167gHIuEXTDEJgFDPVRTLSrDn75a8RPhmRcxr7pMVWHrDhD2ZGkE5Banp7zX8fMMUb X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:18cd:b0:dc6:fec4:1c26 with SMTP id ck13-20020a05690218cd00b00dc6fec41c26mr2628277ybb.1.1711410626525; Mon, 25 Mar 2024 16:50:26 -0700 (PDT) Date: Mon, 25 Mar 2024 23:50:12 +0000 In-Reply-To: <20240325235018.2028408-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240325235018.2028408-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Message-ID: <20240325235018.2028408-5-yosryahmed@google.com> Subject: [RFC PATCH 4/9] 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: kobauhgfqryh1ahm6m5hfu7d4zanntxs X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4CF3918000E X-HE-Tag: 1711410627-700690 X-HE-Meta: U2FsdGVkX1+sQ+v3VQYsu5Rxly7GWcYGtv0yVukn2vveaJzhqsyHFPtP3UA9TeHmeXUvHOTV3HftF5kKkFr50rWtLTsTXoGsZupgOGVR3t10AAPlYuvdIbbCfbsxvXp5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Wb9b1BM0XhdruU96yngO/QjV8bnNCncLyrbkJLdXexk2jweZY9c3Hup4ITtKvtK1sQVwedR7qiowS1ZTpOEoJNfy0TAAe42CVhrCTM8L1iw2P0ooASHHdKpRHRC3j2eZMJOBc8pKJNLjmGe3fn9VfU4Zx4wCaPFkyj7UIBYyrY+Oi0VwZ8u4OiDHCQYTL5l8EIrcYPxmRDoZ6i0uD14cqiNTV8nB1/rKHyZ0wCaQ/1NqJ9+QxDDZQnaG65L3+m2sHF+abG/7d23i0RqeTIflOUoOFBt2nBvgDvBSY5ZnDaiNYnqVvXi3FHMglVTwolRa7gCXWhUloBfOsTls+NTuj9sXMBHzxfLNt+qNGHC5V4JcGcFRGT8/8JaezqSloCyA5g7rn1uXL5GmqH7M7mCwLAfmnt4S1F6wYB79b8dBqL/ajGhs4GaDr656uI63tksIOMSnIDHqUUTraU9Kwld2PdoW071juJAE5Bc3PO3HEF2w== 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() check 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. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou --- mm/zswap.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6b890c8590ef7..498a6c5839bef 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1385,26 +1385,36 @@ static void shrink_worker(struct work_struct *w) } while (zswap_total_pages() > thr); } -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; - 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; + if (val != page[last_pos]) { + ret = false; + goto out; + } for (pos = 1; pos < last_pos; pos++) { - if (val != page[pos]) - return 0; + if (val != page[pos]) { + ret = false; + goto out; + } } *value = val; - - return 1; + ret = true; +out: + kunmap_local(page); + return ret; } static void zswap_fill_page(void *ptr, unsigned long value) @@ -1438,6 +1448,7 @@ bool zswap_store(struct folio *folio) struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; struct zswap_entry *entry; + unsigned long value; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1470,19 +1481,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 insert_entry; } if (!zswap_non_same_filled_pages_enabled)