From: Chengming Zhou <zhouchengming@bytedance.com>
To: Nhat Pham <nphamcs@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Yosry Ahmed <yosryahmed@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] mm/zswap: change zswap_pool kref to percpu_ref
Date: Tue, 13 Feb 2024 22:22:40 +0800 [thread overview]
Message-ID: <e4f3acd9-88a4-428a-8f66-1486037c35f9@bytedance.com> (raw)
In-Reply-To: <CAKEwX=PtOWJ3=dur30sPBmhrAemPcoEQqJkOXCo8=XQLqO1Fvw@mail.gmail.com>
On 2024/2/13 02:53, Nhat Pham wrote:
> On Mon, Feb 12, 2024 at 5:29 AM Chengming Zhou
> <zhouchengming@bytedance.com> wrote:
>>
>> On 2024/2/12 05:21, Nhat Pham wrote:
>>> On Sun, Feb 11, 2024 at 5:58 AM Chengming Zhou
>>> <zhouchengming@bytedance.com> wrote:
>>>>
>>>> All zswap entries will take a reference of zswap_pool when
>>>> zswap_store(), and drop it when free. Change it to use the
>>>> percpu_ref is better for scalability performance.
>>>>
>>>> Testing kernel build in tmpfs with memory.max=2GB
>>>> (zswap shrinker and writeback enabled with one 50GB swapfile).
>>>>
>>>> mm-unstable zswap-global-lru
>>>> real 63.20 63.12
>>>> user 1061.75 1062.95
>>>> sys 268.74 264.44
>>>>
>>>> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
>>>> ---
>>>> mm/zswap.c | 30 +++++++++++++++++++++---------
>>>> 1 file changed, 21 insertions(+), 9 deletions(-)
>>>>
>>>> diff --git a/mm/zswap.c b/mm/zswap.c
>>>> index 7668db8c10e3..afb31904fb08 100644
>>>> --- a/mm/zswap.c
>>>> +++ b/mm/zswap.c
>>>> @@ -173,7 +173,7 @@ struct crypto_acomp_ctx {
>>>> struct zswap_pool {
>>>> struct zpool *zpools[ZSWAP_NR_ZPOOLS];
>>>> struct crypto_acomp_ctx __percpu *acomp_ctx;
>>>> - struct kref kref;
>>>> + struct percpu_ref ref;
>>>> struct list_head list;
>>>> struct work_struct release_work;
>>>> struct hlist_node node;
>>>> @@ -303,6 +303,7 @@ static void zswap_update_total_size(void)
>>>> /*********************************
>>>> * pool functions
>>>> **********************************/
>>>> +static void __zswap_pool_empty(struct percpu_ref *ref);
>>>>
>>>> static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
>>>> {
>>>> @@ -356,13 +357,18 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
>>>> /* 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);
>>>> + ret = percpu_ref_init(&pool->ref, __zswap_pool_empty,
>>>> + PERCPU_REF_ALLOW_REINIT, GFP_KERNEL);
>>>> + if (ret)
>>>> + goto ref_fail;
>>>> INIT_LIST_HEAD(&pool->list);
>>>>
>>>> zswap_pool_debug("created", pool);
>>>>
>>>> return pool;
>>>>
>>>> +ref_fail:
>>>> + cpuhp_state_remove_instance(CPUHP_MM_ZSWP_POOL_PREPARE, &pool->node);
>>>> error:
>>>> if (pool->acomp_ctx)
>>>> free_percpu(pool->acomp_ctx);
>>>> @@ -435,8 +441,8 @@ static void __zswap_pool_release(struct work_struct *work)
>>>>
>>>> synchronize_rcu();
>>>>
>>>> - /* nobody should have been able to get a kref... */
>>>> - WARN_ON(kref_get_unless_zero(&pool->kref));
>>>
>>> Do we no longer care about this WARN? IIUC, this is to catch someone
>>> still holding a reference to the pool at release time, which sounds
>>> like a bug. I think we can simulate the similar behavior with:
>>
>> Ok, I thought it has already been put to 0 when we're here, so any tryget
>> will fail. But keeping this WARN_ON() is also fine to me, will keep it.
>
> Yup - it should fail, if the code is not buggy. But that's a pretty big if :)
>
> Jokes aside, we can remove it if folks think the benefit is not worth
> the cost/overhead. However, I'm a bit hesitant to remove checks in
> zswap, especially given how buggy it has been (some of which are
> refcnt bugs as well, IIRC).
Yes, agree. It looks clearer to keep it, which should be no cost at all.
Thanks!
next prev parent reply other threads:[~2024-02-13 14:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-11 13:57 [PATCH 0/2] mm/zswap: optimize for dynamic zswap_pools Chengming Zhou
2024-02-11 13:57 ` [PATCH 1/2] mm/zswap: global lru and shrinker shared by all zswap_pools Chengming Zhou
2024-02-11 19:01 ` kernel test robot
2024-02-12 13:17 ` Chengming Zhou
2024-02-11 21:04 ` Nhat Pham
2024-02-12 13:20 ` Chengming Zhou
2024-02-11 22:05 ` kernel test robot
2024-02-13 12:57 ` Yosry Ahmed
2024-02-13 14:20 ` Chengming Zhou
2024-02-13 17:43 ` Yosry Ahmed
2024-02-11 13:57 ` [PATCH 2/2] mm/zswap: change zswap_pool kref to percpu_ref Chengming Zhou
2024-02-11 21:21 ` Nhat Pham
2024-02-12 13:29 ` Chengming Zhou
2024-02-12 18:53 ` Nhat Pham
2024-02-13 14:22 ` Chengming Zhou [this message]
2024-02-12 22:42 ` Yosry Ahmed
2024-02-13 14:31 ` Chengming Zhou
2024-02-13 17:45 ` Yosry Ahmed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e4f3acd9-88a4-428a-8f66-1486037c35f9@bytedance.com \
--to=zhouchengming@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox