From mboxrd@z Thu Jan 1 00:00:00 1970 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 C2141C48BC1 for ; Wed, 14 Feb 2024 19:20:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51D548D0014; Wed, 14 Feb 2024 14:20:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CAAB8D000E; Wed, 14 Feb 2024 14:20:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36C6F8D0014; Wed, 14 Feb 2024 14:20:47 -0500 (EST) 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 1FDDD8D000E for ; Wed, 14 Feb 2024 14:20:47 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E4C251605C7 for ; Wed, 14 Feb 2024 19:20:46 +0000 (UTC) X-FDA: 81791376492.30.B047084 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf03.hostedemail.com (Postfix) with ESMTP id 24B5820003 for ; Wed, 14 Feb 2024 19:20:44 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cWrvPhzt; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3jBLNZQoKCBsPFJIP18D547FF7C5.3FDC9ELO-DDBM13B.FI7@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3jBLNZQoKCBsPFJIP18D547FF7C5.3FDC9ELO-DDBM13B.FI7@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707938445; 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=sAjX6cjzXezxso5mboiYm7K+A2aJaJqFnNgHNs+0SmU=; b=nNBnXARF4YJv4ziXCz9c0hWQztLV3+rCfzpiOyQFH18E2DYrTrIJrZLuE77UyCJ74+9sgo navEWwsTl/rt9XdmKXWxnzIjkfPLpnec6qP6AeiBCA+nUBBN5SymcD4o9KnNmQLfMeWPDr AxkRz8I0uQHkUhCnE9TK7x3pueUaCkM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cWrvPhzt; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3jBLNZQoKCBsPFJIP18D547FF7C5.3FDC9ELO-DDBM13B.FI7@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3jBLNZQoKCBsPFJIP18D547FF7C5.3FDC9ELO-DDBM13B.FI7@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707938445; a=rsa-sha256; cv=none; b=ZJuxFxQf1yH+yKY/U1HWYRb3gymBzB1bmtCijm9Yuf5GrCHuGNiCQgwO2wpWL/Z2TSYUBt TsVoUgczJxlj/GyleDKJB69bROvFnTS8py2rTqE+r3luQ2UuRX1+CL9ybv01ij3dreceqG J8kUFoByglVUYkhC1i2GvhwO0UtCM5I= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc3645a6790so57619276.0 for ; Wed, 14 Feb 2024 11:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707938444; x=1708543244; 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=sAjX6cjzXezxso5mboiYm7K+A2aJaJqFnNgHNs+0SmU=; b=cWrvPhztz7lpajLXXpZ8X7Rf6ZYIPLL3qhUW11duGYnKsqod8zCool72OAJoYdAWGM rKzGxU67S+Tltov7gpqKcrzhrl9aLEFXQV16pBgcesfDl9sqAU0bzTtqrtIHQhu+74Sc VwqXYPnbqe3SMhd86dBp3cxCS84Ktzeg8u42U4ZmllHEUzrKJa8cR09RVDKPv0VGyLRA eaQundDJVhni1H8hQfbSmlyaa2TKN2fFokacVMfc80SA4EzhZwDftv5kAVEZ9mTsnhth 3AvGbXaAnUh7SX/yJKzzpXdSUzGy3CsNK2IhlliOLPZ0uvf6FXvxxLCX63EbtbkweuFB CxjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707938444; x=1708543244; 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=sAjX6cjzXezxso5mboiYm7K+A2aJaJqFnNgHNs+0SmU=; b=EXrLtjUXPug4hUs+JiNOxl64GuafsuEWCiewWZZoETQUPijlAA0lhgb4F1wD6NtLq5 IFRCudGqLwwBYpYCD3a7FInepqNUL0djmHMW3sMeD2TkpFcSIaj2rPiX5dDcL/HjJu0u 8mBksgXSCiddBA+67/J30T3eHPhm8O4HWTO11HAe4zpbBAwpCIawM7OGgGKfNyDteOjQ QFLg3klAuPEM4bCR8pdhxftX1fYOMu5GQWpjgkcArO3q08pn7q/aZyqSiKBE3OA+mZCQ cTEhUyHF6uxVf5BBtn+WQlA7NzFryBLDMuvtICZpZhyp+k7iPvjZvf0CgzBw9txZu8DJ Opqw== X-Forwarded-Encrypted: i=1; AJvYcCVlJ2K/BX5DDUXF/1syO1I7eyk0VVQMYpZDJelcDO2i6ZIBhBWAI1+HjCiWWWd19ck4MG/pY6Z8lsFFDuAO5V5C/9w= X-Gm-Message-State: AOJu0YwHwtUiDxK+rgYVU3az/A2dzWqVYsMuBhSioYBo0pYaf6fA2iFo kqNeBaKI3uvPZYfUHyGAiKljcKA2nLjcPbOEbFgciVGptOXrDKJqrywOUlnnzvOtjjW9smqGNrN fhytfa5hAfgefnOLlYQ== X-Google-Smtp-Source: AGHT+IG4cf16vGGDe/S2yO28fy0rp6cQJ+6K4Ey93242LRfpUYLtWyDQrpE/+vrDqxsVt0h8q4aXCwbewraQ2c04 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:1894:b0:dc6:d233:ffdd with SMTP id cj20-20020a056902189400b00dc6d233ffddmr751295ybb.0.1707938444372; Wed, 14 Feb 2024 11:20:44 -0800 (PST) Date: Wed, 14 Feb 2024 19:20:42 +0000 In-Reply-To: <20240210-zswap-global-lru-v2-1-fbee3b11a62e@bytedance.com> Mime-Version: 1.0 References: <20240210-zswap-global-lru-v2-0-fbee3b11a62e@bytedance.com> <20240210-zswap-global-lru-v2-1-fbee3b11a62e@bytedance.com> Message-ID: Subject: Re: [PATCH v2 1/2] mm/zswap: global lru and shrinker shared by all zswap_pools From: Yosry Ahmed To: Chengming Zhou Cc: Johannes Weiner , Andrew Morton , Nhat Pham , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" X-Rspamd-Queue-Id: 24B5820003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: m3oc7uuj75xzqiitgf99j47wydtyrx7u X-HE-Tag: 1707938444-38834 X-HE-Meta: U2FsdGVkX1/uMmBgFNBwVi39cICyr0zSSPLdHbx+LzSOomtkgJDJnKKDBhGWKvrxydbhtVEQvZIM246YNP2bGlVUXWnEe5FF9dCg8jbNM0U4DruO0tU+B1qXShGYJza1m+ARpsOklu0WBEswKVaXjGPMiedl07zMUepQWeGQSKELm12pnP67UDTS/Rp+sPr4yjJLdxi9y0+1INkfQaSHt+aMtbKGf7yiOagkrsD1uk+3SJn+D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N4cyji+1I4eE23KcJdfycIIrEfF6qy+BQGI9P0IXUBQTAyo7BR+2+AWYFVysdWeTpU/9NKZkcSR28jBnyH38ursxmBYwVqNeFI4yPtAnwFqyXf67dO0iuGOujQSy13oQz7CAq3LowuueRvE4vbbQGYGny4Q+ymIEJ69wExPu2IppfLFVinKCtGyh0WNY9j/QX23MYYBlT/TatsBR6NxZK0qm2Qu1VLpcJmxzipxYj3c+Aaq+oeEU9z0UUpWdJdAiq0m+G3M1pX2ciZFdLIkLNQSBnMWqNX5CG70jXmQJctB3wTZZfrMiWEjLmwoKuinVTkzgjyHJ6gMdc3Yqw9zeSvpBSz9ucdiEb72pLkBUJLKPcftcINwbt3i6V1fvkGt8O9XwZSyXk64SBTQ1IIW3P2PmPeYZFJ4XdvuRa5ajKVERuS6HM2pqqKGZffXsrw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Feb 14, 2024 at 08:54:37AM +0000, Chengming Zhou wrote: > Dynamic zswap_pool creation may create/reuse to have multiple > zswap_pools in a list, only the first will be current used. > > Each zswap_pool has its own lru and shrinker, which is not > necessary and has its problem: > > 1. When memory has pressure, all shrinker of zswap_pools will > try to shrink its own lru, there is no order between them. > > 2. When zswap limit hit, only the last zswap_pool's shrink_work > will try to shrink its lru, which is inefficient. I think the rationale here was to try and empty the old pool first so that we can completely drop it. However, since we only support exclusive loads now, the LRU ordering should be entirely decided by the order of stores, so I think the oldest entries on the LRU will naturally be the from the oldest pool, right? Probably worth stating this. > > Anyway, having a global lru and shrinker shared by all zswap_pools > is better and efficient. > > Signed-off-by: Chengming Zhou LGTM with a few comments, with those: Acked-by: Yosry Ahmed > --- > mm/zswap.c | 170 +++++++++++++++++++++++-------------------------------------- > 1 file changed, 65 insertions(+), 105 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index 62fe307521c9..dbff67d7e1c7 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -176,14 +176,18 @@ struct zswap_pool { > struct kref kref; > struct list_head list; > struct work_struct release_work; > - struct work_struct shrink_work; > struct hlist_node node; > char tfm_name[CRYPTO_MAX_ALG_NAME]; > +}; > + > +static struct { > struct list_lru list_lru; > - struct mem_cgroup *next_shrink; > - struct shrinker *shrinker; > atomic_t nr_stored; > -}; > + struct shrinker *shrinker; > + struct work_struct shrink_work; > + struct mem_cgroup *next_shrink; > + spinlock_t shrink_lock; The lock is exclusively protecting next_shrink, right? Perhaps we should rename it to next_shrink_lock or at least document this. > +} zswap; > > /* > * struct zswap_entry > @@ -301,9 +305,6 @@ static void zswap_update_total_size(void) > * pool functions > **********************************/ > > -static void zswap_alloc_shrinker(struct zswap_pool *pool); > -static void shrink_worker(struct work_struct *w); > - > static struct zswap_pool *zswap_pool_create(char *type, char *compressor) > { > int i; > @@ -353,30 +354,16 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor) > if (ret) > goto error; > > - zswap_alloc_shrinker(pool); > - if (!pool->shrinker) > - goto error; > - > - pr_debug("using %s compressor\n", pool->tfm_name); nit: the next patch introduces a new failure case between this debug print and zswap_pool_debug() below, so it will become possible again that we get one and not the other. Not a big deal though. > - > /* being the current pool takes 1 ref; this func expects the > * caller to always add the new pool as the current pool > */ > kref_init(&pool->kref); > INIT_LIST_HEAD(&pool->list); > - if (list_lru_init_memcg(&pool->list_lru, pool->shrinker)) > - goto lru_fail; > - shrinker_register(pool->shrinker); > - INIT_WORK(&pool->shrink_work, shrink_worker); > - atomic_set(&pool->nr_stored, 0); > > zswap_pool_debug("created", pool); > > return pool; > > -lru_fail: > - list_lru_destroy(&pool->list_lru); > - shrinker_free(pool->shrinker); > error: > if (pool->acomp_ctx) > free_percpu(pool->acomp_ctx);