Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3009855lqp; Mon, 25 Mar 2024 16:51:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXqJJwe4A3nN3IdSFcUIosTrVZULdaMBefQoeLc+dj89uXY1SaWSM67QLROODolGjLj0XUUemP85RY3/3mq9GNmZW549Jp7rHQO/wEuA== X-Google-Smtp-Source: AGHT+IG9mADMdAMgQhQG1LmxmPUuOIgIYTnX2X7FMSKanK2txF41Zhk0Ry2j5PcN0ct6EpW11Y3K X-Received: by 2002:a05:6a00:2b44:b0:6ea:9a20:3d8a with SMTP id du4-20020a056a002b4400b006ea9a203d8amr7359102pfb.30.1711410667325; Mon, 25 Mar 2024 16:51:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711410667; cv=pass; d=google.com; s=arc-20160816; b=yFIGu7l07Rw5DCeXmkPMIPCY47BRNTe/Mf6bkLcet9R+quO6HVHyfN5jzVGyK7v08c cl/gnXR7aDWjKtheJF7NU3aPc3y/DzBgGj7YgwxGPQlVQFR9KNq2q7Bjrzn0SBJHdqeY DhJmTw77u/eM2VdNlQoBnZnZ9iFM8of0QA0N7G5yii09rbJu7AaE+4pElY81NYDtwi1f ExmUHe2CZK9tgBqNva3t1Q50xXNnrxcpQgghKzhHMfvRqUSK6gK4NKIHwQRKCgdeH8cH d0yuYDuQ8qjvshTUKJlz2OHlgvJ9aQ0ggCiiSeifCNp9oUSOezntOPEpwcabeQw8GrSb wnWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=+3t/0JKEdL4mJ/vvKrn6t1zV3oNIlUMv4pczMFevQsk=; fh=xhlOGpz83hiRDuFcRWbMwb+jP/aSBx14ekkDcoSOGw0=; b=VuXbSKt8VyHoRLLyRO9Cjr+7ZPjYSK/to4ja6JOX/wETZFSarDVAePLGiPRGkbgpWX B2d0bj9iJ/j/x4FBWAWjn4IyzJLQmMKq9owKlV+OQ5NHrHhbFuX+puSMR6X6+X8o9cHR YYSXoY6AP/IbL7yU65l81TO4XXCNpASrJiykdKyA1ND8lypZxZ0CA1grBPO9ELfaAtRW Gao5EHnVHeM5UDUS6/uMBKndfwJ723Eyz/mylgsps6NmSW2rL2qIwCJ+kgE+oB0qjOpR vviqCPJ10+lkNViYtaZUEj/c1dLpHZiUHL9B2kt2HzE5A0rqXo4Zn9CRuKttJ+LXQn3I E9fA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xRmxL7y9; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-118187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118187-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g17-20020aa79dd1000000b006e69b40d4adsi5939597pfq.100.2024.03.25.16.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:51:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xRmxL7y9; arc=pass (i=1 spf=pass spfdomain=flex--yosryahmed.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-118187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118187-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2DFC32E72C9 for ; Mon, 25 Mar 2024 23:51:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC0331272D1; Mon, 25 Mar 2024 23:50:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xRmxL7y9" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65C9286634 for ; Mon, 25 Mar 2024 23:50:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410628; cv=none; b=lRA0is4D++XaephA8RnhlNzRSQIp0/0r9jnelEUgAZluDuSksKGSn0K5to5D3Pnp2zndDLmh30nalkGynIwDJ+fHX/q1/ReVNWykyVptNH7h3zmJ/FFQljqArMBOTJd6SIM552fLcuh2JoBsuEzeJpl05itBSqBUO9Aq3nwL7uA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410628; c=relaxed/simple; bh=wNdfsIJSEt5cPySFHvOGJeIj3izJ/ngdP5B8j4GiEoc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=smXi13iPi3no5/H4cjF4cQmumHramSz5Pl4pd1U7Qghf7zaVxdAFmUNY3lA3Xgzz3Fw7TI31VVs+qDxFd5rBiYZcsdBlcuujJkWEKOzL4i5GwEWKdlmKN6C51hCQHFJt25LPpprQEJP3EO5igI9vphO2RjhnWtXAjjfTO1LkXTA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xRmxL7y9; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yosryahmed.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcd94cc48a1so7800325276.3 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=vger.kernel.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=xRmxL7y9CJkqpPOM5WwWgGekrwDkSD3dR70jQdPdERU+EKQAO20kzXLXcdUsicisP+ te9VbC4tVwmj5zZFQU/U2vl4mWRrZCx9t4rYxceZu+rxSLCi0meWxNXVH0cTt5vcqel9 zKx1JFMdlqS3szNCpMKpcIfAGZ+vCvMtpfy4q24gHgj2gZblG+A2Vhkw7vGJoVxFEGdh ict3+W650Zra+qi8DAPwytSvXFZJpiHOgd4YSQjXoX86yBAQEGkJtLrU6sDTxbgMAZFA WQvedOwnAeSuzUUIRpecGbdHwCXsj9jMz0afRer5u0xrs4pTyHXE/iIQnZ9WxWum4CdG XI6A== 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=iMyMYsaOidsNVCxF69tRE9Jkr1xaGeAFo5BnBQLYUG1PrHwMqo0YD6B/TtLki4pOYs MaRFhl+kvESvImXyyOLZjBjXe/Ix7BMd2MmUXUz8ZU1qGczTxkWwjKfbuXPjPZCbu8FC hmWBY1lmy9lHoXZD4l0GihYalemJjQ95dG2v81//p4eryTd296Sbs07BPi4hi0fWK2Kk g1LEXeZIWK5rho0lVRWOjeq/bwVufklUxJcEbzXmBhu0DnDjB8k5ADfU3dMrlP60s+5P ceKrCixYQIKGge8bqbhWNrboNw3GQOc/OizLhzyrCNnI9uEyHkusi9wHskZlJbHr50ov OVPw== X-Forwarded-Encrypted: i=1; AJvYcCV17+cjAh+gd2VT3Ix0JeqAQcTA74ldJzVpOefQ1yKW9rqjcbr4sDv4tatE7G6343hTLNr9nwTXualbGPDuhCiLCT232W9vC0xsbHRV X-Gm-Message-State: AOJu0YyFcYQdfeX5Y3dVaX8M9E1O7nVv7v4Sd3ZP2YE6Tk5u4mWbTRVR UoMjfXmOh6b6XKY6tMeXypoUPrIqajgK0WsLNKrPhiwtidbv4K95wlT7+hiZeuf7W12L4E9jS4f ki3Ks6p10ijYWGdBymQ== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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 --- 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) -- 2.44.0.396.g6e790dbe36-goog