Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp33795lqe; Tue, 26 Mar 2024 19:21:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXHb1Zh2vC2mkLI58i7yGJV68wVELWm5pjJ4clwgGyE6NhvTSlAq9zB35yAIrZ+cpRR4cLRAA7LtAmSF+seDw76mznRbTLb6IgHgQXNKA== X-Google-Smtp-Source: AGHT+IFz7EA5EzArFumplVRQImK159C4vLi3gD2NNyEDHJQKmWFZil1e5jJUZkuuC1eJBDmTsDyk X-Received: by 2002:a50:955b:0:b0:568:d143:dab2 with SMTP id v27-20020a50955b000000b00568d143dab2mr2940947eda.19.1711506094611; Tue, 26 Mar 2024 19:21:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711506094; cv=pass; d=google.com; s=arc-20160816; b=Y/Vz9is9EwkFxlwdvxV/ChScuWtgIwZw430XB/2mSkxKh2zzG9xJ5YDOqUTy4429t/ ZMDKDjFU3PhyPImHWQ5qhgFkcaO0wewGSHkQKLz2c6pLeTTe6L4JRcD8kv9MjgZmVbE7 4pxyk2z9rikJmEzoU1ZGkFEA5bl2zDk8fItnJjXuBZtSd+0mTXwI414RKQiX6UiXW/3K ifQJO6zhFQGTxVZXjre2vk7YCY3kpJoRc6+YYgsZxLh65ON+cG6TKJU4uGyaBqD3C4DI Uch8QbXI++FQENfy6avvHDw4oqMcZVs7667rJMM7cK3ih9xfsVtWYDPhhJrydgWmhyVy XO2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=r7kH22AwCzuZEuUkefxu0LWRPDiK+9VavfBLe/z9g4I=; fh=+6tuBzjp2pMpjT9dj+vXx1AyjiCreJh73RbziTYZDRw=; b=maJYoJefjSZJFOdqoLQkU/uwAS8SVjeZIactxV1MHzT8xf/a+e1Df4uHAvcRPKXWhj BmXgPGF1iuPSE93581ESWMJDapC3zg/xmsd0IuLdqCFvZtQoEndgm2SFbHhJHqeVnRkI aNIZ7zV0q0jZOJeg1mTCTqqSKadEboEG0goe3ESmDx3OK2UtZuieVZCGNaoCyXy5GOcz yj4m5yPV3RiCDCH+ak8KwkoA78XHIubJXMQ/icfXgaitXesfZsTnVRP44AOjyNGubn6a YznzNvvop47/ux67xU32z93fjIoIVxOBjOyUnYkTbdd29KaHC+OTumsPOeW+9YC/qucK YJyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vpehwpH0; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-120210-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120210-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h6-20020a056402280600b0056c2aa2abb9si1185054ede.129.2024.03.26.19.21.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 19:21:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120210-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vpehwpH0; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-120210-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120210-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 576A81F2F38B for ; Wed, 27 Mar 2024 02:21:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEF23208CA; Wed, 27 Mar 2024 02:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="vpehwpH0" Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BAAB1D52B for ; Wed, 27 Mar 2024 02:21:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711506087; cv=none; b=txhGPmCH4KZzGjjIVnMh1UPT9P13L/BoMUvPviXtw/WKrrEGEVAyMvRoCb/HGOD16lCdjHAhyAN+7Geq+k63PTLf/48b0DQzoUCdHYwVe8rc8DxYr6Rx47A8Rtz3icGfl34oYRwIpDJt3jvXMT6CuFvozQgC4rzEf/uWP7/9jkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711506087; c=relaxed/simple; bh=v4x0Y7hSnISohPJpBvBc+/MOVgZqjd1Hsd5OKcuSH0k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HyuhSaL1S1JkZfdVqM9WMvn32bazAvwH8Bi1WvYDdWTb5FJp7wOy1gkgjwRfduMA6DyKQraJ4HQ7facHX7tE/Rktlxz6FP6hi0kfRd/JJdcWhjWIOU2+sUcg0VbtihAT93ltiQe1joGKyFkQ9FQNfEXO1gDDAiWnSWfcasvITLw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=vpehwpH0; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <3e041120-cffb-42cd-8373-b254590f0e93@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711506083; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r7kH22AwCzuZEuUkefxu0LWRPDiK+9VavfBLe/z9g4I=; b=vpehwpH0I+B9Vh7ynhlAvoaKoW0ELRndHaNhnJO6ezsgVlbZjiOXPomg9s5Lg+bdAF1lkD jWgTLTUVsXXqIRrXxyIBS4Zz9QyvrpjLIM/qpR3uBUrInSbuFqXi7tHjVCYUQyjBpkgd3O sTNregWkPZfKr9A4leNs7l5c9P8ysZ4= Date: Wed, 27 Mar 2024 10:21:08 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC PATCH 1/9] mm: zswap: always shrink in zswap_store() if zswap_pool_reached_full Content-Language: en-US To: Yosry Ahmed , Andrew Morton Cc: Johannes Weiner , Nhat Pham , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240325235018.2028408-1-yosryahmed@google.com> <20240325235018.2028408-2-yosryahmed@google.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: <20240325235018.2028408-2-yosryahmed@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2024/3/26 07:50, Yosry Ahmed wrote: > 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 Looks good to me. Reviewed-by: Chengming Zhou Thanks. > --- > 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)