[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0f12022e-5dd2-fb1c-f018-05f8ff0303ae@bytedance.com>
Date: Wed, 26 Jul 2023 17:33:36 +0800
From: Qi Zheng <zhengqi.arch@...edance.com>
To: Muchun Song <muchun.song@...ux.dev>
Cc: linux-kernel@...r.kernel.org, linux-mm@...ck.org, x86@...nel.org,
kvm@...r.kernel.org, xen-devel@...ts.xenproject.org,
linux-erofs@...ts.ozlabs.org,
linux-f2fs-devel@...ts.sourceforge.net, cluster-devel@...hat.com,
linux-nfs@...r.kernel.org, linux-mtd@...ts.infradead.org,
rcu@...r.kernel.org, netdev@...r.kernel.org,
dri-devel@...ts.freedesktop.org, linux-arm-msm@...r.kernel.org,
dm-devel@...hat.com, linux-raid@...r.kernel.org,
linux-bcache@...r.kernel.org,
virtualization@...ts.linux-foundation.org,
linux-fsdevel@...r.kernel.org, linux-ext4@...r.kernel.org,
linux-xfs@...r.kernel.org, linux-btrfs@...r.kernel.org,
akpm@...ux-foundation.org, david@...morbit.com, tkhai@...ru,
vbabka@...e.cz, roman.gushchin@...ux.dev, djwong@...nel.org,
brauner@...nel.org, paulmck@...nel.org, tytso@....edu,
steven.price@....com, cel@...nel.org, senozhatsky@...omium.org,
yujie.liu@...el.com, gregkh@...uxfoundation.org
Subject: Re: [PATCH v2 28/47] bcache: dynamically allocate the md-bcache
shrinker
On 2023/7/26 15:32, Muchun Song wrote:
>
>
> On 2023/7/24 17:43, Qi Zheng wrote:
>> In preparation for implementing lockless slab shrink, use new APIs to
>> dynamically allocate the md-bcache shrinker, so that it can be freed
>> asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU
>> read-side critical section when releasing the struct cache_set.
>>
>> Signed-off-by: Qi Zheng <zhengqi.arch@...edance.com>
>> ---
>> drivers/md/bcache/bcache.h | 2 +-
>> drivers/md/bcache/btree.c | 27 ++++++++++++++++-----------
>> drivers/md/bcache/sysfs.c | 3 ++-
>> 3 files changed, 19 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
>> index 5a79bb3c272f..c622bc50f81b 100644
>> --- a/drivers/md/bcache/bcache.h
>> +++ b/drivers/md/bcache/bcache.h
>> @@ -541,7 +541,7 @@ struct cache_set {
>> struct bio_set bio_split;
>> /* For the btree cache */
>> - struct shrinker shrink;
>> + struct shrinker *shrink;
>> /* For the btree cache and anything allocation related */
>> struct mutex bucket_lock;
>> diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
>> index fd121a61f17c..c176c7fc77d9 100644
>> --- a/drivers/md/bcache/btree.c
>> +++ b/drivers/md/bcache/btree.c
>> @@ -667,7 +667,7 @@ static int mca_reap(struct btree *b, unsigned int
>> min_order, bool flush)
>> static unsigned long bch_mca_scan(struct shrinker *shrink,
>> struct shrink_control *sc)
>> {
>> - struct cache_set *c = container_of(shrink, struct cache_set,
>> shrink);
>> + struct cache_set *c = shrink->private_data;
>> struct btree *b, *t;
>> unsigned long i, nr = sc->nr_to_scan;
>> unsigned long freed = 0;
>> @@ -734,7 +734,7 @@ static unsigned long bch_mca_scan(struct shrinker
>> *shrink,
>> static unsigned long bch_mca_count(struct shrinker *shrink,
>> struct shrink_control *sc)
>> {
>> - struct cache_set *c = container_of(shrink, struct cache_set,
>> shrink);
>> + struct cache_set *c = shrink->private_data;
>> if (c->shrinker_disabled)
>> return 0;
>> @@ -752,8 +752,8 @@ void bch_btree_cache_free(struct cache_set *c)
>> closure_init_stack(&cl);
>> - if (c->shrink.list.next)
>> - unregister_shrinker(&c->shrink);
>> + if (c->shrink)
>> + shrinker_unregister(c->shrink);
>> mutex_lock(&c->bucket_lock);
>> @@ -828,14 +828,19 @@ int bch_btree_cache_alloc(struct cache_set *c)
>> c->verify_data = NULL;
>> #endif
>> - c->shrink.count_objects = bch_mca_count;
>> - c->shrink.scan_objects = bch_mca_scan;
>> - c->shrink.seeks = 4;
>> - c->shrink.batch = c->btree_pages * 2;
>> + c->shrink = shrinker_alloc(0, "md-bcache:%pU", c->set_uuid);
>> + if (!c->shrink) {
>> + pr_warn("bcache: %s: could not allocate shrinker\n", __func__);
>> + return -ENOMEM;
>
> Seems you have cheanged the semantic of this. In the past,
> it is better to have a shrinker, but now it becomes a mandatory.
> Right? I don't know if it is acceptable. From my point of view,
> just do the cleanup, don't change any behaviour.
Oh, should return 0 here, will do.
>
>> + }
>> +
>> + c->shrink->count_objects = bch_mca_count;
>> + c->shrink->scan_objects = bch_mca_scan;
>> + c->shrink->seeks = 4;
>> + c->shrink->batch = c->btree_pages * 2;
>> + c->shrink->private_data = c;
>> - if (register_shrinker(&c->shrink, "md-bcache:%pU", c->set_uuid))
>> - pr_warn("bcache: %s: could not register shrinker\n",
>> - __func__);
>> + shrinker_register(c->shrink);
>> return 0;
>> }
>> diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
>> index 0e2c1880f60b..45d8af755de6 100644
>> --- a/drivers/md/bcache/sysfs.c
>> +++ b/drivers/md/bcache/sysfs.c
>> @@ -866,7 +866,8 @@ STORE(__bch_cache_set)
>> sc.gfp_mask = GFP_KERNEL;
>> sc.nr_to_scan = strtoul_or_return(buf);
>> - c->shrink.scan_objects(&c->shrink, &sc);
>> + if (c->shrink)
>> + c->shrink->scan_objects(c->shrink, &sc);
>> }
>> sysfs_strtoul_clamp(congested_read_threshold_us,
>
Powered by blists - more mailing lists