Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp417992lqp; Thu, 4 Apr 2024 18:36:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4DjNzK5PfKKqEv+DTTw7s4WcXJTso6EEOx5OygN5TXj1p/JvFe6vbFu0LF7TEpZbPr2eGOffLyPLoL5vjFjnM8lbtmRmhJpjlsmH1Cg== X-Google-Smtp-Source: AGHT+IHR+RWpU+5vGyul+sj9wZPzcaYRpRV03Da9uzRX9r5exxejXaW/GZuTteIcoTMaufx71AQQ X-Received: by 2002:a17:902:d386:b0:1e2:bf98:f1ce with SMTP id e6-20020a170902d38600b001e2bf98f1cemr113086pld.23.1712280973852; Thu, 04 Apr 2024 18:36:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712280973; cv=pass; d=google.com; s=arc-20160816; b=o/reaQRdDM7fFpHX4UfSE1dzcduLMASRoqCwJLoI9SSdfBhj5mMtSTyl1d5L8ZzehI /Fy7yGxvKUWXwO38LwpL6TciNeJwCiwA2yFsPYrM4E6kv/PotuOP0idmRhWna1Sxs8JS rZ+g7QODQpcyM3s/BR7qWpZOc1t9MD6cBUlbGZg67KoSp8D1/BOlrbKARa8u8WzxRPeo Mj8M7AiDqRm48TCICDLZ9CuJGcpql4xYkktKzwdk+T98JmJRVSGufh4GOcnMWv5r/5nG R3QxgrwrlCQ6q5SIbrZ89EiHyMyzkeVkfu7AVBq4oEnavrXIlvL/JCV8ZcLLxlWLhF00 +WZg== 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=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; fh=bRPWW51w5o45DkwWaRXYDSwvdsgpRNTrGFNG+ExOLDY=; b=F2gWkeGW4bXrJ5JRPgaEOiLTEUpBSKSBViFtR6AqUt9d4Ye3/YKa+Ru/a5F09lNkRu CEYY4EuiTU8bbczlXPt96QmqmIGimWSZ+OCi0jg708JXLYKcFY7XwjmakONi+m/vZkNY LJea1IpIL49wOgmjr6Gp+rrJriaL25+uLkmtQPFG/LFNhEMwbFWXtExRjk2N4ZZKeyU5 fKqq/GaHXvIU4S4+EDQBu4DOj669Remm5D+X+yI8OxslrDGM6gUusDx240K8xM2gSJZi kZ3JVi3K/ikVrvW3Nj8LB/ent1Zp9ffQtlVUbAhNODXvvBjhI3v8ILt821kb3tYUV09G 9knw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="X/IkkluX"; 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-132308-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132308-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l13-20020a170903004d00b001e230698a3dsi420060pla.33.2024.04.04.18.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 18:36:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132308-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="X/IkkluX"; 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-132308-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132308-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 00684B24AC8 for ; Fri, 5 Apr 2024 01:36:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F06F3107B3; Fri, 5 Apr 2024 01:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X/IkkluX" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 6F8C3B64B for ; Fri, 5 Apr 2024 01:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712280954; cv=none; b=VRRHK6nApzvosCKKmJXMLzCovB/dT1PzgpdxPjTz9VI6VMDnkwwNMrcO7BnoUimD644885GSc0ugUUH5X0pjswZ0d3opXYJ3cPx2wKTQbGlZ24FOmPa3KzcL3Xr2Sui5UKOhWOFsfCUxMCrWYjJ4U2hGrA5gN+vqb7bS4aheMm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712280954; c=relaxed/simple; bh=0EwsJFsFqxelfzk3PZ8b/+zJHvbghrn5+keHiziw9TE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tUU0Nz7B8Dmzq57QShiRqCQIG6401ww63lgn7fg2qNWPTe8SnF3GGn0gVw5HDs35BoGgFycGPDO6A9IMrFkHXQVqwaC3s7vs0jVE7QAF5D3f1sOUH2V5iAEma1+A6U4f4nRp+28vlRjPwQivBtkF4Yql9wp5aLGMB9gPeLNx2eo= 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=X/IkkluX; arc=none smtp.client-ip=209.85.128.202 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-yw1-f202.google.com with SMTP id 00721157ae682-610b96c8ca2so27492427b3.2 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=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=fbFnbwv9ZL9vnT6aD0Y4iZUVe+aMA3yOt75trlF6TiA=; b=X/IkkluXiEVJ5EKk7J0A8+yObqRNvDLo0ep30HXuSpU0+npT3vZt2uJypTJEfJGjJd 1SgVawoNeHogbJPS7AMmqdVcxlCg1yCLXpdqnC6uIlDI02bS8N9NfwphPROp9iFAp17g CL/Y4nZrSHQysvn3XQB9sS0CReeDHKJVWoqdK5FSATcH40Wx7rbiPKNradeXNsmTc5o8 kSUCA9nsMzw6l9pdrrH1M0dAM4ofoGFqluGil0aR+RG62cLEzc/u7/xbGYs5ogqv2/iR GBnucTFJyvVuMxobpuaxodiL9rPatwrCb34/+3d3Y20V0gLl5e7+uzg2Ej844PyAKNRq IxnQ== 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=qV7Hm82iwDxK78nGGsnxkK7z/S1rMWe4K23dO0smWXy1d4tX+mSCCp/5w10nHAQIhF WoT3VdWFIS5O0XweYnT6ETZN3FEH/fHSxgNdVPhc60OuWuovO5chu+K07Fu4btru/5Eh Gdhi99iDbrEdyLCjs0llSnkzFpMblsMM3LChKDJ0T9IUlGj4sqcMACwB8iFzORNZQK6V iA6F9RS7o8njTnhAV0IUzxlyZ/59f067x2jAbeFItjUCDlJ3rNCJ9h35JVavvd43l4Go MvmVw01aD4jg9b99HbAkrEB3sRu94ms4NHYsfuWsjAjRML7+ow9V7iAbeOk/dsUVqJYn NZCw== X-Forwarded-Encrypted: i=1; AJvYcCVYxi4ZO6MLB51+K+HzemvT0GuN2KAGmAYwIPUIxO++Yfm3JhDa/2qNdLr3mVOW/8wAxFc9oAfEK7Hbn1wasbiIZEN8jdOEFsiUskcD X-Gm-Message-State: AOJu0Yw0YQL1SWNyoArGTxGO3JYW1CR8VX1dokd4LOBz+JqScCaBTTLD T3DqFIdcQ28q8kos7YbZuHBw7AEndPfgaBPzj6vakht1y2+9HJDlyr4l6wORyEOcTeuObdz5Elw ere7HrxmlKQBfluHbcw== 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> 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-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 Content-Type: text/plain; charset="UTF-8" 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) -- 2.44.0.478.gd926399ef9-goog