Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp489251lqp; Thu, 4 Apr 2024 22:36:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVn2ckYAD4mFUp/OwhDW8gfESy/RVCH5apYB4nJGRwC2boy05Yq0Zm7RUs0WxTKkHBR6vGRU/Oe4zDqjTrpfAyeddHzYB0xAWVYJ43BxA== X-Google-Smtp-Source: AGHT+IEABBWYc+jdfO5xpcIj7bBXFeiw5AACnxiEpD/im9BAv46IH74JAEBxQ+eoLs0sZYciM5U6 X-Received: by 2002:a50:c04f:0:b0:56e:2e4d:884e with SMTP id u15-20020a50c04f000000b0056e2e4d884emr406009edd.0.1712295386730; Thu, 04 Apr 2024 22:36:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712295386; cv=pass; d=google.com; s=arc-20160816; b=vblIWQj1OLteMvac4BaxZC10kKR+hgQ0xIru2jxeNf+2oCfyc8Y93Ss46iRxgiOrZV guMBPrqkuzTn6H/FEa5XCx75GG6bES95LFst66iTvBqBPD6ZUv3F/Xl58deTmQoMBdAI 7a4TkFFZDuhqwraxyA9vWLj+VMd/j09njmjvBB1Y7D4oaYT93z9G8S22hEUNkgN/rfWa phCP/52i8Onhz52Mbhmws1FuwOQCEC9Y0oVoytlephjEKUBZ7XDGjVQii1pCTfqPTPC1 1l6MR5T2zctDrChXhx4pjdIVYp+++Oa1eHrrOoS64GAbiLp9ztEWPWERuwFVWkMl/viv bcqw== 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=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; fh=v9Nd9GNBqLs7GFWamkPIIXV2EHiWcsVidN40a3UBsH4=; b=G95bwLckCKY8+Gh4K/7JFu6NfOdVSocLG/2g41NveGX+0iZdSN/mLd27lLKQMmMzmg HGpAQCgCmoq2bkk8rkaP0O6LorZvUGcUpSZy6ioHY6CfNPnVPZM8jOvt1pSTt7mm1HZg j5qe6epchNr7yvy/Ji1UxjH755/D0w1iXp2zUqNTq2APQBDBN1JuLhUcsB7BLAk4+Yk7 fxyDLZBl5kKgKMl84/GTVGekCnFgNU+EEF/+9VFpkAQzaLJbX08P1MTQaXNeHrCSZhAo gzDZaKnmzw4Uu9M4PWJFVNPhKDkEwS2C4yzOAAUXdJse/YBoFBFg40Hw31j+tqbpTQYi 5kfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K+8uXzf3; 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-132428-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132428-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u26-20020a50d51a000000b0056df488dfafsi369657edi.95.2024.04.04.22.36.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 22:36:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132428-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=K+8uXzf3; 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-132428-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132428-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 488881F2331C for ; Fri, 5 Apr 2024 05:36:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C43112C1AD; Fri, 5 Apr 2024 05:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="K+8uXzf3" 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 47BE525774 for ; Fri, 5 Apr 2024 05:35:21 +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=1712295322; cv=none; b=pyWZhdiNrWcs2eH3FQGy3tf+Fap93T5eabVgDQeNmtWAeRIy8UflIVdjPMRA+GO6Xd2dPh74VgciGRg21FmClCu3oXHgqZFYL1EQK+B9XmqIHL+ojHeu8LUGHBwBRioLGkAChzp0b7YHHPqS9eMtagVizQBbVWQQ35RFszHyw8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712295322; c=relaxed/simple; bh=OBu0XPUtNujGfTv9FqY2iHyyiyKuVEz2ju3MZe/grPw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nbuIBm4GzT7GqxjC23zeExR2oqbgjqO1fXTB5bvLXEntpWuAjtTpnejhyJmt9ohzK4z7pqefYKuEx0qy1Hg6RwIO9c5XdaOVFhb0dYdb5jRPPQSHz6fu/7IGFF4n1PJnYhI1rt1/DvXSlujk0NkB7w1g2l1qVvJpbsiIl82LxM4= 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=K+8uXzf3; 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-dce775fa8adso3101494276.1 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=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=JztYBciZAboPFg0UR8cifQAY1ELGwu5QR/HCIVJgmmg=; b=K+8uXzf3WSy28rVAsNxg+4n9zzs/W8BjIMbOLUpH6fppU9dM5GMHQMO9sJ2cGBOI4J esVT0FXsbjojvrQXuUYk7ZE4jDDO0cFKMIgCUzcRd6B/d96S/A2aPRDDPqP1OytZ9+jJ LjAeX+0iV3iEWVir4P9Aa8QpMJlZT1zQJAPf4X2jA2mwxZhF5KEMJX2BoKdHsZeUQcAD dzyhoeFP/Cl7P2coj3Yg942u0UYh87FfzHdRvRNyCnNviwUBeFnzEgxlHWjgUdrWV4Gy HTfMP4Eb83ZYQrZCQlkZT7ADfKptlrMHY67hESpjV50+4V2CQcNuAk4x2VZ+2z4kSCVi 1ucg== 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=Fpoowfav/+BwiLpX3Cm/OZ+dI8sLrodwJbt9/NSlziA+NmEHeJB/WZZKMIbtYFgUYA cL2jBUpCsU5GEgHVMjwPGNAiQIg14D6Iy6pXEx5V5ciLZn2EBEIG8f350gvwFwfaZp15 N/07UXEBfFxPidppWK4VYM5KTN9QMYusEmHMDVpzViipJ4LbkwN4PS9jh+UVvdPdBdfV r4g+NdzA6Cu0kZHV3ZrsU9943C9mx/XAE4lRMiPX2gIWWXEFiVKyjj6VVOH4U0BMUgI9 DS2fu/wDgDodBY+ztAMSguTNaDFRNsYwVgI/LTyRmyeBSTJU7pSmRmcAOJ11ThRh/Vd3 lgwg== X-Forwarded-Encrypted: i=1; AJvYcCV+Xbj5kfaAjQQY2X46f/MeIcV8XN9Nw3Q8LgTgln+Q+YxgOv8YtPtlYElQ3OOv7BDFbTkjRH9fXUqwlWXsvtKQ92gAj83IRvVMH158 X-Gm-Message-State: AOJu0YxBjlSaEn79d8wTsmCQP6uccACPJxOemQbCA2K2AhRJ/QlJVXRE T6pmQlKbyaL3Q3/GSP1BBzDdyA4JW/4TiP/Ti2HbTVi2qmAzlPF71Td2avPW0Oa28CccHEJTlRD caJWbnirPHi5e3h3tyA== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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; -- 2.44.0.478.gd926399ef9-goog