From patchwork Mon Mar 25 23:50:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13603189 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 C5335CD11BF for ; Mon, 25 Mar 2024 23:50:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B38F66B0098; Mon, 25 Mar 2024 19:50:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC35B6B0099; Mon, 25 Mar 2024 19:50:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9158B6B009A; Mon, 25 Mar 2024 19:50:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 797276B0098 for ; Mon, 25 Mar 2024 19:50:36 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1BB9AA0A08 for ; Mon, 25 Mar 2024 23:50:36 +0000 (UTC) X-FDA: 81937208472.30.2DD47DF Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf10.hostedemail.com (Postfix) with ESMTP id 49322C0002 for ; Mon, 25 Mar 2024 23:50:34 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Q2lfIGdj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3yQ0CZgoKCCQYOSRYAHMEDGOOGLE.COMLINUX-MMKVACK.ORG@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3yQ0CZgoKCCQYOSRYAHMEDGOOGLE.COMLINUX-MMKVACK.ORG@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711410634; 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=KO2q76LvMLcDayey/RN5wyIAuuRCIUh2utVXFGvhTms=; b=u0v5K9wXVGuULG9uhTs984iJZXwFm5gXv2EQ6+9cYRjMHucwd6Z+U56KPCXPe9AaMdSl3a BIbBQol3xi9lav7DQn5bWpbxOhxxClYqHfnkOCMwjT7/O4+KR0klGPu3aFJwGpEVN7nj6x k/iRrmRhKCw5MG+vrnYqI8dUAcGlpw8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Q2lfIGdj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3yQ0CZgoKCCQYOSRYAHMEDGOOGLE.COMLINUX-MMKVACK.ORG@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3yQ0CZgoKCCQYOSRYAHMEDGOOGLE.COMLINUX-MMKVACK.ORG@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711410634; a=rsa-sha256; cv=none; b=SvGNNqD96tRvV6feKc6+iSNYQS6Q5+tKglrutwqCDw8GyClk0/yL2xGHXNfin8LzbEubLf FQwEGJpVh0Tw+n1in5lxAzrmpomTs0x+/Y8THyL61/Fq5uXixYhOnI0tDho+SInxt8X4fs /nXv81olaZtZi009b9nKISbp5Tw2P2I= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a0815e3f9so75221607b3.2 for ; Mon, 25 Mar 2024 16:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711410633; x=1712015433; 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=KO2q76LvMLcDayey/RN5wyIAuuRCIUh2utVXFGvhTms=; b=Q2lfIGdjr+xdTnmwbi5d/3bsHWP+q6oPx90yaOAzKd0YpQ97893muEXb6IhakQ9dUY bBGmcPFlTlCBSI1xE1Nmht2gYEpI3TO0hlTr5h3s0cvqMv5NMqsu0KuwzOirDVKbdFrn OfCArANEYmXC8iEIxgOq3LFXk5KUns3KFgEv7mLJRdtUtU6R8aqX/7zCwuxuXOi7lb1g Jc8NrToqKMlfFc6Mqb5++Guz5vYbc/R4b8Fxyiyst8Vz4XddExfPGwkIcARa/Cpx3Q0B lSeVbAV/cjmz5HCewcLJiEW2jMgq5KKV4ISH8fielCYfSKx/dREDKYMlmSjVhDf6L24t LaUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711410633; x=1712015433; 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=KO2q76LvMLcDayey/RN5wyIAuuRCIUh2utVXFGvhTms=; b=PvzD6liIbPattBTQLIS3iQ7grXI9uYONDUA5osh/GaZ0KNzAQtOC/+EcB4qYR4Z8vp uP9Dm7ijfWBf9EPfOWIyXZ7qV5UyyU4+1FQyCO5M6o84g6k+bQqlCdjbS/1jHNbVKlxR co2UGzWvT3VSXsnwFaanQdjKPqH9+LerBy389e4IFpfGBzrtfUoCwETlOOhQcT3PegHc 9yBbO6WdiR60at2y8ENeWZvS13DwrvOkYRD7lZWQmAw6agkA843KK0S60KfhnLo1n9ue TyZSXkVYleEleYJiSH5hVO58KDj4fgDTFtwG1AowkgsmiwxEI/ai0ICtoH4q7i5LFFrR 2xmw== X-Forwarded-Encrypted: i=1; AJvYcCXRJO05mQQLCjoladDIxeHEselyZAFXZkhxqMhWIufpfubjuqeOstugNaP5yjJrc8ttscVM7qDzPfC//Jf17i2vvKA= X-Gm-Message-State: AOJu0Ywg3J4OgQzxj8crljk3wi4Zx9cKxX9gQcZSC7Bs5cMEYh5+FfHp mCmBVtjwOCxasinJ8vXj0Dx5o75zyv3rnJE9uEHmgDUv3TLES3PAilF7b9IhMESPXLtuVd5Xdwv pMh9WB1gG2LpixGEX+Q== X-Google-Smtp-Source: AGHT+IGsngKICRKq/pDsaMChol7XL6fK76guiT9EmRwqzuuG62psC+Y/KoJk23mBwa/MlcuS5UwOswLoFZ1CnMT3 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1241:b0:dcc:4785:b51e with SMTP id t1-20020a056902124100b00dcc4785b51emr370308ybu.12.1711410633551; Mon, 25 Mar 2024 16:50:33 -0700 (PDT) Date: Mon, 25 Mar 2024 23:50:16 +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-9-yosryahmed@google.com> Subject: [RFC PATCH 8/9] mm: zswap: do not check the global limit for zero-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 X-Rspam-User: X-Stat-Signature: fpont1q9b85gzkco1ngpthckbhumd57d X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 49322C0002 X-HE-Tag: 1711410634-345662 X-HE-Meta: U2FsdGVkX1+4fnTffUI5k3Y5ZJMYyQIJCknYzMAPeKm8QwFBNW7kwW6dhf9h0fkUV7t236aValu1djKQd+n0AqJ+rP67catIGwgXjl8vrj24wHhB4e6ZMQZBmQuXrssDeB8z6BaRGtjhe1HpWgM4qY2fnH8AasqHNf//us47VFI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lFVTkA0UFX29L1tFG6pgQIxlDNWgLxXlVIKbXzFTscXFz85MK9spm9K0ctIP4DwmEoaWHznm2MQTc0HqdgvqcrfIss6SyHXPSLteWkeu4OTtDQPP0ukXICzUvyKyHoGJJdhMcI1L6+LO0EVuzvRNRZJTMXUa9cDnz2GWNmJ3bcRHoU2EzHMop/7F+qt7jtbmMAqrmHHIzIQVEgDcvTLTfIhcKrLwz0Cb1WSoTAGvRFwAMAccG0r332bmIMsl9nY+qzMqycmXcPpjBLvhQqQ+eWT6wKXhHzM+c9LOApuEOk6foKLyCXAPgc28TzNNVCDwY23UhncpspfOBGlXsN8SwzOFjgxvXAHSh06/i/9EEeHUbZM0VP0dnE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000122, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When storing zero-filled pages, there is no point of checking the global zswap limit. These pages do not consume any memory that contributes toward the limit. Move the limit checking after zero-filled pages are handled. This avoids having zero-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 zero-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 Reviewed-by: Chengming Zhou --- mm/zswap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index efc323bab2f22..9357328d940af 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1460,9 +1460,6 @@ bool zswap_store(struct folio *folio) mem_cgroup_put(memcg); } - if (!zswap_check_limit()) - goto reject; - if (zswap_is_folio_zero_filled(folio)) { if (zswap_store_zero_filled(tree, offset, objcg)) goto reject; @@ -1472,6 +1469,9 @@ bool zswap_store(struct folio *folio) if (!zswap_non_zero_filled_pages_enabled) goto reject; + if (!zswap_check_limit()) + goto reject; + entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio)); if (!entry) { zswap_reject_kmemcache_fail++;