Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp418221lqp; Thu, 4 Apr 2024 18:36:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBcIs347fV7yrwLlML9kbRxltxP4ycSTVVGWOoFe8dNyflQDkVz+eW0w+f8UuTcpueavPtSgz1FEDhX5y0+xx1SfBn1PT9oZpF+r+mtg== X-Google-Smtp-Source: AGHT+IHKHSbvsDb1cdxEwynHt0tT6o9qRzSrAeNzUoCa0mh75udczOVexpij/CWVFaFp1kCCPN/i X-Received: by 2002:a50:a419:0:b0:56b:e089:56ed with SMTP id u25-20020a50a419000000b0056be08956edmr8001edb.39.1712281017680; Thu, 04 Apr 2024 18:36:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712281017; cv=pass; d=google.com; s=arc-20160816; b=duc5YflM0D0naTHlBL1EZ+livkaiOEt3ULjAUdKvyRr1tL38k0+q1y8kvngsqSE59O qnehaq9GKk6c7CbPJafGD4n3Kl0Yitx4w08hCXwcMMlks3PImk5+fdcHoyFHQALvxuJV h8W763J/cZ061mkWgjfL1wg5YDdDb/UpZ2KpQNCgcdeEstHJSxXlLSCCYrpyREZpRPms q08TCrKJ3YLI3SAlupRRfg1clWRdMU6Z9p5d7zl7ZMAvYXIr9xiMBmIQ9Bg2PYgL+4OE tqiq2zu35BsyUCfrw5h3m2W8Xy01O2M1q/5Ibpr/zgP25UzxLP9YXWka3okjBJh1okv3 tXEw== 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=LZ1QXrjwhIal4gIkbl9SlMnvEbBP+lXyDn0RpoWpImY=; fh=xiqTHX2XJTopEIZT1SkmG/+Df+ZNMIYZl87Gr/eNlS4=; b=sKs5cVTqKXcAgZ1qrtEHeyb9E70X5xNRW5QV2PHm1Y2DMxA56R72DRqwbSrczZD2rh qc7SActN0lLxv9iDkSdR0TDTY3wZ3eaj4lkNvzNByI7lhAOjTQLuGcG7a9xPfa9M4EVo t9iERRkUnKe0u0jXav5MZxMAbRLmj1FJQmk7kKN6IP/Ua9rG8lYyBp955IrKYAkI6zTn HoX8Njhuyyq9fRprpUEgeUj7KoZO+NyQnUZfcvVJ71f6UL2tg6ZWhzEdHOs6gyqgG+r3 M3XXaSB2x0zlEroNmcKk650tMcWyD2NqcIUvEMj5cH70TSmrMwonkdP2UYdW6e+WOqjA fGjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cp6dUbSb; 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-132312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132312-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 r11-20020a05640251cb00b0056e0abadbe6si219385edd.594.2024.04.04.18.36.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 18:36:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132312-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=cp6dUbSb; 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-132312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132312-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 61CE51F2716A for ; Fri, 5 Apr 2024 01:36:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9D8F1CD35; Fri, 5 Apr 2024 01:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cp6dUbSb" 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 708C8DF5B for ; Fri, 5 Apr 2024 01:35:59 +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=1712280960; cv=none; b=kWPdSouTPAjaHnvOWxSHkrs7SyqPg5WH06YazpN8lAJ0ahQbjNLqyMm1teuqkYo0QGjNwZrpPoVYDfFDoVNzFEaZCoTTrDxKLVGBFKcfitWrF1OiNEtOJbTZiJRhK85kWXgutqc3UhMe5HV5+XmyB6erFADfx908NKqJQsxvm1k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712280960; c=relaxed/simple; bh=EKrGZSwVFwew2HMPiLb4JaHCc0fDKmV9LIy0S8SK7FM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oeSNJD6hZubvPqjMyAQIgBPt72W+lVt35J8UWTqimD28sxoLh5z1bGDWsewo0Wewwca509vOxt28VBy6ss3neh2c/Au4MPP/Ifnx0mak6u3lf6u73jF4VrSywBHpEjBOrQomGunU/Lu9sey0iuLQaTpheY63zMHHjDHzxqaimdc= 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=cp6dUbSb; 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-dcc58cddb50so2641502276.0 for ; Thu, 04 Apr 2024 18:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280958; x=1712885758; 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=LZ1QXrjwhIal4gIkbl9SlMnvEbBP+lXyDn0RpoWpImY=; b=cp6dUbSbSNHw7ZVlTrAfUK7741QJsSJ0N6uQVXswNL8uzz1QjPSHNn+2VTZT3hc//f Dhm5sdWjZko1pUmWRuVFHU/pFTOGnDzqfG2HlFz7dV+9jFYz/7KF0sNm9aYCwxmKuehj 8uFDScG+bFnMP0z0MUBKhqyRuykYzO6KNFe4AM6++Zupw2eXJQ8sH/x0HkQZ5SLSarnn RsTXI5r9Jczb4b/+7CvnPiaDJExwag6rFzU84Jm08yVm1jkzzcbUrP2OQsEgldhopoEn 9MW2mbrYiXjYk4Eo5aoUCfXsipvrUawefuTtXv0GDRqVfDdfG8QCuI2N//XdE4HJvJfp ThPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280958; x=1712885758; 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=LZ1QXrjwhIal4gIkbl9SlMnvEbBP+lXyDn0RpoWpImY=; b=jzYMbIQrKDqu3L346DkcqzwBxZoXScFg1kv4XkQV0pNhC1DyFtx1NY3xywbR1gDFx6 MVCYTwNtQ9yjOh7PqICGgEildVsqu1R6eWW69K5xh8+lUU9gQAjch2aawyNFG/UD0HT5 wrwD5wFTTJ2YLq56jRxN5KTC7GynnaLVSlY6w41aqpLhaNZY+igCV7UJPpdWsf0+xKMA ddElXGHYbNBb0CSxtpZQKenF2pcTFSUXtpVS+btGqXELqNz0xpMEZOIcjge75KcPIvA0 2/CFSGNcwfZjLGJV5dIyzz5dSBleujMoDiT+YYjnSmuO0gn7ggYpSYhcpTHXspYRpJs6 aV/w== X-Forwarded-Encrypted: i=1; AJvYcCW3iGopi/XKq5kT8dkTOp/hS/1I5FBh2Qz3IQU4VkQRqwKg7LXxZ2QzSgqR2i06ikFnt4zWnahS73f0ecgltSCQ60V21zcmS5k/nrPF X-Gm-Message-State: AOJu0YzcS+2aM5NnxrZCIijJMBvm6Tk+iyInsfX8dZ515lJk94UUEtKZ E4QEucwk7VtSloEGRKBeU/vRLU+unwbUG0GFGfTNsMex/JfaXMeoI/V9I3PoXD+810VQ3T86t89 w9uuk+NCqm/35aUKxvA== X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:2b05:b0:dc6:e1ed:bd1a with SMTP id fi5-20020a0569022b0500b00dc6e1edbd1amr351076ybb.2.1712280958518; Thu, 04 Apr 2024 18:35:58 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:47 +0000 In-Reply-To: <20240405013547.1859126-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: <20240405013547.1859126-1-yosryahmed@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405013547.1859126-6-yosryahmed@google.com> Subject: [PATCH v1 5/5] mm: zswap: do not check the global limit for same-filled pages 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" When storing same-filled pages, there is no point of checking the global zswap limit as storing them does not contribute toward the limit Move the limit checking after same-filled pages are handled. This avoids having same-filled pages skip zswap and go to disk swap if the limit is hit. It also avoids queueing the shrink worker, which may end up being unnecessary if the zswap usage goes down on its own before another store is attempted. Ignoring the memcg limits as well for same-filled pages is more controversial. Those limits are more a matter of per-workload policy. Some workloads disable zswap completely by setting memory.zswap.max = 0, and those workloads could start observing some zswap activity even after disabling zswap. Although harmless, this could cause confusion to userspace. Remain conservative and keep respecting those limits. Signed-off-by: Yosry Ahmed --- mm/zswap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index a85c9235d19d3..8763a1e938441 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1404,6 +1404,7 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; + bool same_filled = false; unsigned long value; VM_WARN_ON_ONCE(!folio_test_locked(folio)); @@ -1427,7 +1428,8 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - if (zswap_check_full()) + same_filled = zswap_is_folio_same_filled(folio, &value); + if (!same_filled && zswap_check_full()) goto reject; /* allocate entry */ @@ -1437,7 +1439,7 @@ bool zswap_store(struct folio *folio) goto reject; } - if (zswap_is_folio_same_filled(folio, &value)) { + if (same_filled) { entry->length = 0; entry->value = value; atomic_inc(&zswap_same_filled_pages); -- 2.44.0.478.gd926399ef9-goog