From patchwork Fri Apr 5 01:35:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13618348 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 8329ECD1292 for ; Fri, 5 Apr 2024 01:35:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEABE6B00AF; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D81626B00B1; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC1A6B00B0; Thu, 4 Apr 2024 21:35:55 -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 9E4956B00AD for ; Thu, 4 Apr 2024 21:35:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2FF1340653 for ; Fri, 5 Apr 2024 01:35:55 +0000 (UTC) X-FDA: 81973761870.13.95B7FFB Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf07.hostedemail.com (Postfix) with ESMTP id 6BD0F40006 for ; Fri, 5 Apr 2024 01:35:52 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R1tdHIiZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712280952; 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=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; b=jd/4hHdb0b9stwIVLoMZEBN1L4dz0gMNo21N2D01dq8D5xbojDekGm49fGb386Yx918VC7 iL/S00FLvSErs7I5/lOWiTjYRhaCOqXFzavgZ62u4wSvZIK3FuDrmsT+sGTHX82HILh1tg 0w5RJ70IcKn9/n4JY4P6QJx7KP0B0jU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R1tdHIiZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3d1UPZgoKCJYOEIHO07C436EE6B4.2ECB8DKN-CCAL02A.EH6@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712280952; a=rsa-sha256; cv=none; b=5m9fUadTypbZgbB1/nDPmVP34qPOD16IuNovu8YBLAPs39PIKfvXPN/XVOa4IDjNw8PzWm yAQ6ZlBduFipRoxnDuxgrMqDJMkYcXhOQcYVmJuCVQ6LdjbxSCA9mMamr2wxrMOMy9mk99 AkmP2CKvXhugA+qXhmssTwDKWG8E4Jo= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60cd041665bso28011287b3.0 for ; Thu, 04 Apr 2024 18:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712280951; x=1712885751; 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=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; b=R1tdHIiZDM5r5un85hSs9U8oMHN/Zh7H5tzEUmpEg2IMdh8N/SiucDfc2uonWR874c uax5ybYFxXxdMzvPySrIRentNWfxV9NslEVMiRZyFPhPi5vdfxQOJPtNyEA+hR5m0ZRQ XLbuhnag04WmKie3Bb1a/0Ml23FYgnC3z2eaYPN7VTWz6pB4XU1VDWVVXuukcs4Ygj8Z bnwH8ie0Lz57cvO+Kv8Xil6EzGshBicaMdFelUacEJEtFDYzy5yBUB0ndm184XVJkL4O uh5qVbiezv1Pp7/xVG+0v8QVBoyedMYxRR0PD+H8+8fzhYowM3/V1gDoUGwDg4vPfdwt rdhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712280951; x=1712885751; 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=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; b=p8BzSEdGr1q7tZfCqIDF/QU/sdTTHe76nwxVrX4jY30lV8jtcn2bw7MBrHydpWZ65B 1W8cv5DRsluIMVMwcHS5nikzQ0Ndgcvwyv9eIl8GaVemM5mOMOtSpVv1anEoenk+p2fZ i8N0FiS46ZzCO0mkl2uxsUvwqF4BwLwPElWCI/hcaVXuPLujwGhGq/5v/6S2bsVR6wos ZyapTYDeR2AOPntbPtZqeS8bb2nUmSSBpjJZOH7nGMsSCPlfMgvJ2rPX8qrZzo6g1PGv u4Vk2/fsRwUq9TdAo3yvQ8SXxPuZjd4iwSd8D8R7Qn9zYg8yXwfN7RCEQdePlvYqHA7T op2Q== X-Forwarded-Encrypted: i=1; AJvYcCWIrRCrJIpj6WQjXQAjnzldGWzldar2wS5bWJfSmvOSALQTKU9JK0LPcQtuDMPd+wPa2CEeE4SSQftC0ScKXomECzg= X-Gm-Message-State: AOJu0Yy8g0hUhu9ahzEZaTRlnf8vs2KjmMi6BdX6Js82j9Rv1mcAcNbA xQkIdUD+11oex3eb/HpM3EkcKhB5cQdovBizskGisU+9XD8cbwuHoMiUEICKmSqV6UEKJrACLQT Xzh6jNywABNTMpN3jEg== X-Google-Smtp-Source: AGHT+IGJTA/i85YTUBVw2cs8xuSEjY+bqpz8Alc8JIdeIpUrh1LGBbhlTI/u/mBkLRKZfoJj4MNZLvSP1tmwvTZh X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:690c:dc4:b0:615:102e:7d3b with SMTP id db4-20020a05690c0dc400b00615102e7d3bmr343711ywb.1.1712280951511; Thu, 04 Apr 2024 18:35:51 -0700 (PDT) Date: Fri, 5 Apr 2024 01:35:43 +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-2-yosryahmed@google.com> Subject: [PATCH v1 1/5] 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: 6BD0F40006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jz96p71zkdc38e466x8wspjtn1m9fdnc X-HE-Tag: 1712280952-639919 X-HE-Meta: U2FsdGVkX1/xEquZmKvGsYSiCg+HdmiXFh2JKowF+s8VTcf2Bq4AZckqyPYW8EaqOSBEY+YkeQBi4OsbAE9NkbSdic3Drmher7+tmvzTQqU4NzSA71OSZAJdtHzliXbj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Lefr0ZtuVRRPMSk/DR/AvLA/HGUyhsHksgiDI61g/JGzBA3Q4KfECsstFfDXYk4HS7AZfSveq+FTQ+Wdjvb/dqjF11ujWoKNQWuXnrEFQuXFi0aK72xuVzovFkGz/dh5ark/yuexBKoQrECVmSQFKjxio5LuYMtNGvuuZN/C+yMJ5KO0/2Ut6HfNr8a9IYENLpR2ycaoRUvyYeZLnAF+kgkSRGjJTMIbrfcIZrN4JcSLclo1hsy1NDnoqRI2hEkVs3KLMMsfoj2jSQ3Pai+fu5QjTPaxG1PrhM2tSt1aXoZy/iQlvpuc1CwFb0aL4UbHltNiGoQz8TXEIGG+/7xVa0SVApWQta6j93SGHZ8MVuzYrddM03yLlRDpueMc3dcPfr1ehAzbs9qM+YaMoNCznlOJndiJKW/OgIXnD4+asF4rPG331cafasJYkebXWtIMQf7OodnaLEJgQ9EvVsj8ROgaZJQqmcxyNVozMmridDidBYVFKCSdVGYysRkAOK9vQq/nlcZ9PcjpADAOhltS0qmAXJDgMqOYpYtx/fzToRqFQc/z7g5tU0glvuzs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.010529, 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)