From patchwork Fri Apr 5 01:35:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618350 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 9B8F4CD1292 for ; Fri, 5 Apr 2024 01:36:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8BA86B00B0; Thu, 4 Apr 2024 21:35:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9F136B00B2; Thu, 4 Apr 2024 21:35:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9551F6B00B4; Thu, 4 Apr 2024 21:35:57 -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 77AFE6B00B0 for ; Thu, 4 Apr 2024 21:35:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3DB9AC01E1 for ; Fri, 5 Apr 2024 01:35:57 +0000 (UTC) X-FDA: 81973761954.19.7589C50 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 94CD512000C for ; Fri, 5 Apr 2024 01:35:55 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lEDqy7he; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3elUPZgoKCJkRHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3elUPZgoKCJkRHLKR3AF769HH9E7.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=1712280955; 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=yEGVZyHSwt0QZZ3iWSnf36Lx2mkJ2T39ZbIwvSBmEnQ=; b=bEwTpxhvzttjpQTdp1i0jpHXt6cKxEDf4T5Cgo9Z4eL1QDMnyt25yLOyTo3Tab98ZFaT/T B2UvwlTxk1f1CAAV2T4ToPG2XKXIwb8kGuV76HywM3SYfxK1sLjsJ/4rTY+moXHRIyDeGy 7bmSVNxMu42mEakIHy7IUZJwGLybSyY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lEDqy7he; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3elUPZgoKCJkRHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3elUPZgoKCJkRHLKR3AF769HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280955; a=rsa-sha256; cv=none; b=7WwFvd5oL3/j4Urc6SMwtJf/7o8uJ4x3dRVOCObFAwDPF5+Ph83k+Bd1KQStJpZ4QQmxd/ sXop8Xv4toaYin1y+MN0Iccv74zFOVEgwjH3Z6KC+b+Ki0m0dRfpbI9S6xYsQaV/8+djhS hUUykaZ34TsynVAiqC8a6EcZhiF+RHA= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6156b93c768so31847477b3.1 for ; Thu, 04 Apr 2024 18:35:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280955; x=1712885755; 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=yEGVZyHSwt0QZZ3iWSnf36Lx2mkJ2T39ZbIwvSBmEnQ=; b=lEDqy7hegds8eeCNEfeG19o0F675DlZ9rTsXVJAtOgKvArAVrsjBIdjB3gZTDVii83 W7CHp5gYhUR1PqjbkJOysKm/fbZY4pM2Y0pLzESzh/o7lDKnR4XhimVvciC6POuakusg zGKjTJJjlrDfoXBEm860lNFYfI0BBHL/nYtW0W2pRdT/4ez5T3crkoGnwflzbH9XvKrW McFLBAj45rFbqDQOlmFcA1Of/dnyplkfJx0zn+eMkcZ+G7oNGPiy19/t36cxi7EVQHnl 4woEf6AFYGDzdXqNl1pQrkW2iV0Dms++ZlqEhnGBQ9CWooE4K3klP+tc5onnWLiOAXGp 8wVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280955; x=1712885755; 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=yEGVZyHSwt0QZZ3iWSnf36Lx2mkJ2T39ZbIwvSBmEnQ=; b=IuFS/4GuBzT4Rt5szn16nkY+F50pz/odCXYZPJsTZh9GCjXVtiLJSYPjWQaT0ih/li mZkOkCwuB0hECj+z7PvOf5D9VklcbcDHS8FQNtMnLuUFkCCpRHlnBAqt7Tix7C7kf1XD GnC91ZGUALu+05nt6y/KVgfW0FIvXb7SoeX7EoEY8Kgytclg1zkDV0Fx3oFaCReSwtSX DVlOt6gaPNt4gUpnQqCOq3s1jObXQzbf1skVM8l1lKH7dfHynAhf56xysyFMIQubyLoI a+LnJfCuCibtDzf767puOiognLpWdYDixOIa7nHnbk82EzISpu3T7lL9rfPpOdmZaidO OafA== X-Forwarded-Encrypted: i=1; AJvYcCUMYtI5iz3uK7G2HHwHlzzI/K8ZQHRWl7tqXtFC971xpruwsn6W8e1MoMvD+39RMm8BccZUK8F9kNX6GWfa4AfZTns= X-Gm-Message-State: AOJu0Yx39cXvYkjp/gm3FdE+w/0nEcMWu38Ncz4iQYMpfxHGMtJDt+oM VjWTytNLqZMulW7RdhaVADvX7uHNtowsjxlRdhuoYMHBgEOHw9DxspRmrpt6Tj4VbM5/gRKuITg tY3GVe9XFpd4ndnUvNw== X-Google-Smtp-Source: AGHT+IH33+SVthekVVKeXhbUOG3wNDshSnpJ5/OwGTrydVxvAVq4kpl3zfciKOFqgaOZ9hcvtHjOLuShz0z5TQ52 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:e1e:b0:615:1b90:d987 with SMTP id cp30-20020a05690c0e1e00b006151b90d987mr342246ywb.6.1712280954789; Thu, 04 Apr 2024 18:35:54 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:45 +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-4-yosryahmed@google.com> Subject: [PATCH v1 3/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-Rspamd-Queue-Id: 94CD512000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: xjqbnww76wnegreyi4q63ychdxn4a69r X-HE-Tag: 1712280955-97019 X-HE-Meta: U2FsdGVkX1/RUj8vvuSftG+TNPQ1mYWEWZwP4yWNY/t0PErRaNNVnEO4Pio8wQkqzfVJexjPYZn/sA46OsoACSKL3PDy+nNi1q2cQcliMGdDa6PnaMe7q86F8czURSkHX2NBXm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USbXe76OfiW1V5K7RAfm+jddefITOpbIgsL+bHu22gTDVm251rDcMCNC468B9aUN9P/ne48wMPCbTZOAfE1bGviMFff1qOsNEA6Pbq2L/zc0O1zzyY1ER79sgRakRUUYQsL3Nf78KH49bSAG3Nq5bd2RrBFWWHI1k0d1qONBjorheLOEYm/13wsxSp7TcWZCa/Jog6DGc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000052, 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 fba8f3c3596ab..b92fa37bee277 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1361,26 +1361,32 @@ 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 = 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) @@ -1414,6 +1420,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)); @@ -1446,19 +1453,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) @@ -1481,7 +1480,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;