From patchwork Wed Dec 6 19:44:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 174714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4338622vqy; Wed, 6 Dec 2023 11:45:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLPQ+kUtTQ6KHjdpdTH4wiLoKucOI65Il0Nou7/RmMVVN9QUGwzfVCvF9MDk6tANw45uZQ X-Received: by 2002:a17:902:6b41:b0:1ce:9a59:da29 with SMTP id g1-20020a1709026b4100b001ce9a59da29mr1165774plt.5.1701891903137; Wed, 06 Dec 2023 11:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701891903; cv=none; d=google.com; s=arc-20160816; b=J0wK95a5fSwRexyJN01jIMufbIzuo5yNZ2ua2dlgAbAe+oVinPLtACGsclRUaMvWGb SK2FDfTWB0n4BELzqwZFmxZTQmZFx73nzBTkU9JcI3Ix3MFZ2IIf8C57APdEmP0dexkI aa9RCCBpUOpM7IY0cIgCvcq5TOJ9ltgGNiAuYTTMvFV/MRZLRRGBnE+sMdLhFd7BFB22 cV3y2y8jE2Mk8uU/dN/jaMvLm45L3GXYrb5+DjvZbK/nxPIihhBx0ohK+BH7VV/ydija nd+pe1pfLObtnFiHn6vRwaKHXCuF8lQARAIw1iC1D4SNlC6bLNEccZ/YwyexAgCizEpC oQMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=34Cie9O+2NEe6JD/tiGhw5O8IQAQcami9IqZS5J2OMw=; fh=5ynFD2G6LA0fdRuAOSZxbBxHoIIG4U3xrwbnkupZs28=; b=Nqj69XfGslddoJ0qRhexW3nkpySVw844Joj3i+DhdY2yqdJm7vSAtZphxcC9yAF47u h0tzD6jRwF5Fft72f6h1Bv8V1R7Tps7JmH6T8MU1t0k+97UpLb8h2akoi43UpSq6mQG3 QLef85e8mrGgCIJNUX/iNsazS9AXmczgyiJtBqFduHHSnLL3dmAyYNATb1guwNg1UINp hYl7D00WtUPZqolFJxIvymw8Cm5N7DsMZk3ik0BjNwV+euYz5Xtp5VSIHiSOME1cuvNn 43Kqxiqo2AK+kc8shdO0mQzNQuMLG0wKZ4yfo+I57lElLxZGRjLEJp5za1IRzwkS1Yrb g7OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=azE5hY6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id jo3-20020a170903054300b001cf5cae80e5si278564plb.114.2023.12.06.11.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 11:45:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=azE5hY6d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2B7118025B4B; Wed, 6 Dec 2023 11:45:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379392AbjLFTox (ORCPT + 99 others); Wed, 6 Dec 2023 14:44:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379386AbjLFTow (ORCPT ); Wed, 6 Dec 2023 14:44:52 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB2E122; Wed, 6 Dec 2023 11:44:58 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5c2066accc5so81343a12.3; Wed, 06 Dec 2023 11:44:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701891898; x=1702496698; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=34Cie9O+2NEe6JD/tiGhw5O8IQAQcami9IqZS5J2OMw=; b=azE5hY6d7qYMc/I6yrPGUYSzyNOOxlobk2q2ie4iTlSPZ1WDvH4UcWU1GRaQsfBtUY d0E9GlSiIPA7dOYk/vZpL5E6HMyguWGZIDejbbqc83k6bNpK4OwRAZ+PZpTEa17ftw5s 0I8ooyKPPJYz0jaXKAPPvs/5Ntp+jyoE7oZoV0AGlcBjeGLEDZR7jL98O2jIWFqhs9rE IWswcenJovCTh2PjtWXt9/VfkDHY2QDAzbXgPyp3YHrO3MBLco3O6vdTBdvwKjcUvxW7 UhN9N8ULSidqvAiUSpv4AuHla/qBuWGbosvKfqCjSkAdnDdNYTNCBUswQgPnCE0NxtZp ALDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701891898; x=1702496698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=34Cie9O+2NEe6JD/tiGhw5O8IQAQcami9IqZS5J2OMw=; b=uf2Fo+nZC8uKlLesKJ7ILXBwWq3hQOzN6n5BXarnEjBkqqjkTIe/xoaVs5UpIH1wfv g2MDLsDcw9yaxx++77b0LmvuL2fCmYSEmtX8k/xwkRT8da2bn7h2yMf5fTFY7pHsWPic iNVyywFrtNNVHYZ0PUTyWzuZgU9owH1iagjKQWbqtPQjm/YnSG20YdHpNok2/4XEhFgN c2PUm1pVqG68SsLItBYJvTF8qW42FJ6RAHqfJ8Irr95YOJMg8F8rc4zok9OXo5x5Xfgo g5AeG5DwCJpn1Ed7kYlkJj3vIItfyUkpgp380oz9vXbStavT1SSZJYeYc8E9BzenZvC3 /1Lg== X-Gm-Message-State: AOJu0YywqzfiHQfukLAXcoESHKKcdv820cJhGX7/7rRbVOkul5FXSJqs Nzlr/IaDnX14xVM5IZ30VQU= X-Received: by 2002:a05:6a20:be9e:b0:18f:97c:4f58 with SMTP id gf30-20020a056a20be9e00b0018f097c4f58mr993500pzb.100.1701891898163; Wed, 06 Dec 2023 11:44:58 -0800 (PST) Received: from localhost (fwdproxy-prn-001.fbsv.net. [2a03:2880:ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id s9-20020a056a00178900b006ce91d27c72sm344920pfg.175.2023.12.06.11.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 11:44:57 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com, yosryahmed@google.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, chrisl@kernel.org, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: [PATCH v8 6/6] zswap: shrinks zswap pool based on memory pressure (fix) Date: Wed, 6 Dec 2023 11:44:56 -0800 Message-Id: <20231206194456.3234203-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130194023.4102148-7-nphamcs@gmail.com> References: <20231130194023.4102148-7-nphamcs@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 11:45:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784563004485443601 X-GMAIL-MSGID: 1784563004485443601 Check shrinker enablement early, and use a less costly stat flushing. Suggested-by: Yosry Ahmed Suggested-by: Chengming Zhou Signed-off-by: Nhat Pham --- mm/zswap.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 27c749f6c1ba..d8ecd79120f3 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -596,13 +596,17 @@ static unsigned long zswap_shrinker_scan(struct shrinker *shrinker, struct zswap_pool *pool = shrinker->private_data; bool encountered_page_in_swapcache = false; + if (!zswap_shrinker_enabled) { + sc->nr_scanned = 0; + return SHRINK_STOP; + } + nr_protected = atomic_long_read(&lruvec->zswap_lruvec_state.nr_zswap_protected); lru_size = list_lru_shrink_count(&pool->list_lru, sc); /* - * Abort if the shrinker is disabled or if we are shrinking into the - * protected region. + * Abort if we are shrinking into the protected region. * * This short-circuiting is necessary because if we have too many multiple * concurrent reclaimers getting the freeable zswap object counts at the @@ -611,7 +615,7 @@ static unsigned long zswap_shrinker_scan(struct shrinker *shrinker, * objects (i.e the reclaimers will reclaim into the protected area of the * zswap LRU). */ - if (!zswap_shrinker_enabled || nr_protected >= lru_size - sc->nr_to_scan) { + if (nr_protected >= lru_size - sc->nr_to_scan) { sc->nr_scanned = 0; return SHRINK_STOP; } @@ -633,8 +637,11 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker, struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(sc->nid)); unsigned long nr_backing, nr_stored, nr_freeable, nr_protected; + if (!zswap_shrinker_enabled) + return 0; + #ifdef CONFIG_MEMCG_KMEM - cgroup_rstat_flush(memcg->css.cgroup); + mem_cgroup_flush_stats(); nr_backing = memcg_page_state(memcg, MEMCG_ZSWAP_B) >> PAGE_SHIFT; nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED); #else @@ -643,7 +650,7 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker, nr_stored = atomic_read(&pool->nr_stored); #endif - if (!zswap_shrinker_enabled || !nr_stored) + if (!nr_stored) return 0; nr_protected =