From patchwork Mon Mar 25 23:50:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13603182 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 4EE2CC54E64 for ; Mon, 25 Mar 2024 23:50:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C209B6B0083; Mon, 25 Mar 2024 19:50:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA9CA6B0087; Mon, 25 Mar 2024 19:50:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 961906B0085; Mon, 25 Mar 2024 19:50:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 827AC6B0082 for ; Mon, 25 Mar 2024 19:50:25 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 485C21401F6 for ; Mon, 25 Mar 2024 23:50:25 +0000 (UTC) X-FDA: 81937208010.25.564209B Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf26.hostedemail.com (Postfix) with ESMTP id AB8C0140009 for ; Mon, 25 Mar 2024 23:50:22 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mojwaJjZ; spf=pass (imf26.hostedemail.com: domain of 3vQ0CZgoKCBgMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3vQ0CZgoKCBgMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711410622; 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=u9fvbqW1pLtPErlE8l2YKQeiKLLE5wFNh7avewbFYWs=; b=d4NECfLax4oQGq4phswaj2RnYanYsHVPjdGHZG2vZ+rGGmFbSJOm4SsFpTHCrmq9UL/04v rFokEu7lksPsqY9V0PefClVDtYcnOVMN6dmVTIVD4v93votUqw9GHejnc8ye1VlbJjD1MK MH0VbVspNwDoM53YpmsNl/k3tqzgysA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mojwaJjZ; spf=pass (imf26.hostedemail.com: domain of 3vQ0CZgoKCBgMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3vQ0CZgoKCBgMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711410622; a=rsa-sha256; cv=none; b=solxQS1W7E8+3hJyv8xJtmBnPNYcPNuCOYIi2si7bCwFtdddzbwc2P9UhLrcdoitnhgIzO hAT8y1Csj0SjR6coLdxV8ygoEoh2yYslt9Fq69KN+8mwfoDaBs2i3MKgBXKMHeO858hPOH eO+xS/lUvGqwJXxp3uXrklRMPHwhebg= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26ce0bbso10012761276.1 for ; Mon, 25 Mar 2024 16:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711410622; x=1712015422; 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=u9fvbqW1pLtPErlE8l2YKQeiKLLE5wFNh7avewbFYWs=; b=mojwaJjZYrglg3ygnQOqVg8JsZFM5R6TJKdA8wrySVT9K28BdWAy72KbTaeMmVg43r NzrE/el2niauCzMoIbthxyguIF9AwPD5rObsV4yCbwJeIQIDXNEvvivu6a35wTkyBAjn iFOMKjMb1AgGjEZ9QWyPfbO6Wfu7a/SVydr5YXUm+qJeUlSiuUksvYkltppQ2AFvpwht +yn2wOrHyvJ+ha1FHO3v0gfVHG02R7eJwG0d/9RhyNvma3IPH1VJGldozzpI+OcX17iZ QXx3g1SLYotsAAu54GUr13NkyQE7Kq5obTQxwbY7GZHPav3cG2omPkDhsjpBWa1AaAga Q+/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711410622; x=1712015422; 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=u9fvbqW1pLtPErlE8l2YKQeiKLLE5wFNh7avewbFYWs=; b=spEE5uqSjXw1SqbKnDL1e+NKH9sOJIsNCaj1OEe12Tui79FajkrYmJMcgDpBJzSPsj lKbiAJfHSOg7DpSE7s8YyeibbTdT28k1Kr8otMzzwAFMwcudSeETvi4gtAAsDg6GkBhl Xj9N7il8jO4aJRHsoVCKdkmznDMeX8x0TotcNYYTRjXeAM8CUwccjhNEQS0XCOIhUbWf Wp/f5QDBzcPYSHvgJMbT0lKNZN5mPAX5V2p/a04B+FbS9nmpSmRIygAm1cz/duiIlh1S wBIUg3SWpD2kP0IAqFIxlF8mzSzBA56DEgmi7yiG6zV+7tmQgcgrWfSkcrhr3BXX5B+5 BvOw== X-Forwarded-Encrypted: i=1; AJvYcCUWfFL5k5G+fMeDryrLp60fh35GUsdKJrK3CGecFRwqFs/Srs5UB8vJVxfBVI/WG9dUuXFjc+4xkkqBNaKEPZpRbBo= X-Gm-Message-State: AOJu0YwkOs4apyb0yVNPmFTPJXAJhxBItTEJMs9fUSubMSQOePy1c6i+ +AUakKEVsjwrVvngOP8JcZ9M9FREhGarox0EMtOQ4gYFiVy9fp8iqNPeAxzs3y55F6t588Xqiz3 WH/c/DoiqbI6ZmCBbrQ== X-Google-Smtp-Source: AGHT+IH+DXWV+vX4OULsfH+Uyq0gzOaLllxrZEK/FYDaAYjBCM9JZ11SOX35Q3oKMnkT3VL0MGvjY9eZ8pU6LA5R X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:2491:b0:dcb:e982:4e40 with SMTP id ds17-20020a056902249100b00dcbe9824e40mr2590953ybb.12.1711410621894; Mon, 25 Mar 2024 16:50:21 -0700 (PDT) Date: Mon, 25 Mar 2024 23:50:09 +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-2-yosryahmed@google.com> Subject: [RFC PATCH 1/9] mm: zswap: always shrink in zswap_store() if zswap_pool_reached_full 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: AB8C0140009 X-Rspam-User: X-Stat-Signature: msfzyii39afs7bmgai4hrma4ez5p7nt7 X-Rspamd-Server: rspam01 X-HE-Tag: 1711410622-4350 X-HE-Meta: U2FsdGVkX1+wDq4+IMvddYGPpiC+r6JYSicxwlX0aBExE5QDjMBJj1HZffIRim+0v49riyEsCHCzn3ksz/2hjQsixVjiBo+Zj8pIUTXmiRXeshBRCm/23qPFP/kQOMSWuYyiX/FuxgiHyY3J1GSbu23sQxEy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biwuoaaAGnifWh9Iuog6wdQm3NRY4TuCjaZ1Ee9rNsU1AULixmBXEQX3fNlXvl3BccUSyATjnSFp8Lz9xc4lhq3Zazkmtl5DVyY+kq2GGxksf4c6L0Ok4SeO7Skvg4aDKnnFVDqpPTejDdN4KfEI2iaLlF3QGwiQ36eBwd924/sMf0GmNtBNU7UyFyU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The cleanup code in zswap_store() is not pretty, particularly the 'shrink' label at the bottom that ends up jumping between cleanup labels. Instead of having a dedicated label to shrink the pool, just use zswap_pool_reached_full directly to figure out if the pool needs shrinking. zswap_pool_reached_full should be true if and only if the pool needs shrinking. The only caveat is that the value of zswap_pool_reached_full may be changed by concurrent zswap_store() calls between checking the limit and testing zswap_pool_reached_full in the cleanup code. This is fine because: - If zswap_pool_reached_full was true during limit checking then became false during the cleanup code, then someone else already took care of shrinking the pool and there is no need to queue the worker. That would be a good change. - If zswap_pool_reached_full was false during limit checking then became true during the cleanup code, then someone else hit the limit meanwhile. In this case, both threads will try to queue the worker, but it never gets queued more than once anyway. Also, calling queue_work() multiple times when the limit is hit could already happen today, so this isn't a significant change in any way. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou Acked-by: Johannes Weiner --- mm/zswap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index c4979c76d58e3..1cf3ab4b22e64 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1429,12 +1429,12 @@ bool zswap_store(struct folio *folio) if (cur_pages >= max_pages) { zswap_pool_limit_hit++; zswap_pool_reached_full = true; - goto shrink; + goto reject; } if (zswap_pool_reached_full) { if (cur_pages > zswap_accept_thr_pages()) - goto shrink; + goto reject; else zswap_pool_reached_full = false; } @@ -1540,6 +1540,8 @@ bool zswap_store(struct folio *folio) zswap_entry_cache_free(entry); reject: obj_cgroup_put(objcg); + if (zswap_pool_reached_full) + queue_work(shrink_wq, &zswap_shrink_work); check_old: /* * If the zswap store fails or zswap is disabled, we must invalidate the @@ -1550,10 +1552,6 @@ bool zswap_store(struct folio *folio) if (entry) zswap_entry_free(entry); return false; - -shrink: - queue_work(shrink_wq, &zswap_shrink_work); - goto reject; } bool zswap_load(struct folio *folio)