Skip to contentSkip to conversation

linux-next: build failure after merge of the bcachefs tree

PATCH Stephen Rothwell 4 participants 10 messages Sep 12, 2023 – Nov 1, 2023 Linux-next tree

lore
Share & tools
lore
#0 lore raw

Hi all,

After merging the bcachefs tree, today's linux-next build (x86_64 allmodconfig) failed like this:

fs/bcachefs/btree_cache.c: In function 'bch2_fs_btree_cache_exit':
fs/bcachefs/btree_cache.c:403:9: error: implicit declaration of function 'unregister_shrinker'; did you mean 'unregister_chrdev'? [-Werror=implicit-function-declaration]

  403 |         unregister_shrinker(&bc->shrink);
      |         ^~~~~~~~~~~~~~~~~~~
      |         unregister_chrdev
fs/bcachefs/btree_cache.c: In function 'bch2_fs_btree_cache_init':
fs/bcachefs/btree_cache.c:479:15: error: implicit declaration of function 'register_shrinker'; did you mean 'register_chrdev'? [-Werror=implicit-function-declaration]
  479 |         ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
      |               ^~~~~~~~~~~~~~~~~
      |               register_chrdev

cc1: all warnings being treated as errors

Caused by commits

5ec30115c066 ("bcachefs: Initial commit")

interacting with commit

eba045d9350d ("mm: shrinker: remove old APIs")

from v6.6-rc1.

I have applied the following merge resolution patch for today. More may be needed.

From 801ad185700d9a7abcf156233b9db6cf6d831581 Mon Sep 17 00:00:00 2001
From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

---
 fs/bcachefs/btree_cache.c     | 19 +++++++++++--------
 fs/bcachefs/btree_key_cache.c | 18 +++++++++++-------
 fs/bcachefs/btree_types.h     |  4 ++--
 fs/bcachefs/fs.c              |  2 +-
 fs/bcachefs/sysfs.c           |  2 +-
 5 files changed, 26 insertions(+), 19 deletions(-)
fs/bcachefs/btree_cache.c +11 -8
index 245ddd92b2d1..7f0eded6c296 100644
@@ -285,7 +285,7 @@ static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b)
 static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
 					   struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
 					btree_cache.shrink);
 	struct btree_cache *bc = &c->btree_cache;
 	struct btree *b, *t;
@@ -384,7 +384,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
 static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
 					    struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
 					btree_cache.shrink);
 	struct btree_cache *bc = &c->btree_cache;
 
@@ -400,7 +400,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
 	struct btree *b;
 	unsigned i, flags;
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
 	/* vfree() can allocate memory: */
 	flags = memalloc_nofs_save();
@@ -454,6 +454,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
 int bch2_fs_btree_cache_init(struct bch_fs *c)
 {
 	struct btree_cache *bc = &c->btree_cache;
+	struct shrinker *shrink;
 	unsigned i;
 	int ret = 0;
 
@@ -473,12 +474,14 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
 
 	mutex_init(&c->verify_lock);
 
-	bc->shrink.count_objects	= bch2_btree_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_cache_scan;
-	bc->shrink.seeks		= 4;
-	ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
-	if (ret)
+	shrink = shrinker_alloc(0, "%s/btree_cache", c->name);
+	if (!shrink)
 		goto err;
+	bc->shrink = shrink;
+	shrink->count_objects	= bch2_btree_cache_count;
+	shrink->scan_objects	= bch2_btree_cache_scan;
+	shrink->seeks		= 4;
+	shrinker_register(shrink);
 
 	return 0;
 err:
fs/bcachefs/btree_key_cache.c +11 -7
index 505e7c365ab7..88d33690233b 100644
@@ -838,7 +838,7 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
 static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
 					   struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
 					btree_key_cache.shrink);
 	struct btree_key_cache *bc = &c->btree_key_cache;
 	struct bucket_table *tbl;
@@ -936,7 +936,7 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
 static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink,
 					    struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
 					btree_key_cache.shrink);
 	struct btree_key_cache *bc = &c->btree_key_cache;
 	long nr = atomic_long_read(&bc->nr_keys) -
@@ -957,7 +957,7 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
 	int cpu;
 #endif
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
 	mutex_lock(&bc->lock);
 
@@ -1031,6 +1031,7 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c)
 int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
 {
 	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);
+	struct shrinker *shrink;
 
 #ifdef __KERNEL__
 	bc->pcpu_freed = alloc_percpu(struct btree_key_cache_freelist);
@@ -1043,11 +1044,14 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
 
 	bc->table_init_done = true;
 
-	bc->shrink.seeks		= 0;
-	bc->shrink.count_objects	= bch2_btree_key_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_key_cache_scan;
-	if (register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name))
+	shrink = shrinker_alloc(0, "%s/btree_key_cache", c->name);
+	if (!shrink)
 		return -BCH_ERR_ENOMEM_fs_btree_cache_init;
+	bc->shrink = shrink;
+	shrink->seeks		= 0;
+	shrink->count_objects	= bch2_btree_key_cache_count;
+	shrink->scan_objects	= bch2_btree_key_cache_scan;
+	shrinker_register(shrink);
 	return 0;
 }
 
fs/bcachefs/btree_types.h +2 -2
index 70398aaa095e..fac0abdaf167 100644
@@ -163,7 +163,7 @@ struct btree_cache {
 	unsigned		used;
 	unsigned		reserve;
 	atomic_t		dirty;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
 
 	/*
 	 * If we need to allocate memory for a new btree node and that
@@ -321,7 +321,7 @@ struct btree_key_cache {
 	bool			table_init_done;
 	struct list_head	freed_pcpu;
 	struct list_head	freed_nonpcpu;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
 	unsigned		shrink_iter;
 	struct btree_key_cache_freelist __percpu *pcpu_freed;
 
fs/bcachefs/fs.c +1 -1
index 48431700b83e..bdc8573631bd 100644
@@ -1885,7 +1885,7 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
 		sb->s_flags	|= SB_POSIXACL;
 #endif
 
-	sb->s_shrink.seeks = 0;
+	sb->s_shrink->seeks = 0;
 
 	vinode = bch2_vfs_inode_get(c, BCACHEFS_ROOT_SUBVOL_INUM);
 	ret = PTR_ERR_OR_ZERO(vinode);
fs/bcachefs/sysfs.c +1 -1
index 41c6900c34c1..a9f480c26bb4 100644
@@ -522,7 +522,7 @@ STORE(bch2_fs)
 
 		sc.gfp_mask = GFP_KERNEL;
 		sc.nr_to_scan = strtoul_or_return(buf);
-		c->btree_cache.shrink.scan_objects(&c->btree_cache.shrink, &sc);
+		c->btree_cache.shrink->scan_objects(c->btree_cache.shrink, &sc);
 	}
 
 	if (attr == &sysfs_btree_wakeup)
Signature · 5 lines
2.40.1

-- 
Cheers,
Stephen Rothwell
#1 lore raw

Hi Stephen,

Quoted 21 lines · Stephen Rothwell

Hi all,

After merging the bcachefs tree, today's linux-next build (x86_64 allmodconfig) failed like this:

fs/bcachefs/btree_cache.c: In function 'bch2_fs_btree_cache_exit':
fs/bcachefs/btree_cache.c:403:9: error: implicit declaration of function 'unregister_shrinker'; did you mean 'unregister_chrdev'? [-Werror=implicit-function-declaration]

   403 |         unregister_shrinker(&bc->shrink);
       |         ^~~~~~~~~~~~~~~~~~~
       |         unregister_chrdev
fs/bcachefs/btree_cache.c: In function 'bch2_fs_btree_cache_init':
fs/bcachefs/btree_cache.c:479:15: error: implicit declaration of function 'register_shrinker'; did you mean 'register_chrdev'? [-Werror=implicit-function-declaration]
   479 |         ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
       |               ^~~~~~~~~~~~~~~~~
       |               register_chrdev

cc1: all warnings being treated as errors

Caused by commits

   5ec30115c066 ("bcachefs: Initial commit")
Quoted 8 lines

interacting with commit

eba045d9350d ("mm: shrinker: remove old APIs")

from v6.6-rc1.

I have applied the following merge resolution patch for today. More may be needed.

Thanks for doing this! Some needed fixes below.

Quoted 20 lines

From 801ad185700d9a7abcf156233b9db6cf6d831581 Mon Sep 17 00:00:00 2001
From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

---
  fs/bcachefs/btree_cache.c     | 19 +++++++++++--------
  fs/bcachefs/btree_key_cache.c | 18 +++++++++++-------
  fs/bcachefs/btree_types.h     |  4 ++--
  fs/bcachefs/fs.c              |  2 +-
  fs/bcachefs/sysfs.c           |  2 +-
  5 files changed, 26 insertions(+), 19 deletions(-)
fs/bcachefs/btree_cache.c +0 -0
index 245ddd92b2d1..7f0eded6c296 100644

fs/bcachefs/btree_cache.c static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b) · line 289

Quoted 6 lines
fs/bcachefs/btree_cache.c +1 -1
@@ -285,7 +285,7 @@ static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b)
  static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
  					   struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_cache.shrink);

The shrink passed in here will be a local variable, so its address can not be used directly. So need to be modified as follows:

	struct bch_fs *c = shrink->private_data;

fs/bcachefs/btree_cache.c static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, · line 388

Quoted 9 lines
fs/bcachefs/btree_cache.c +1 -1
  	struct btree_cache *bc = &c->btree_cache;
  	struct btree *b, *t;
@@ -384,7 +384,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
  static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
  					    struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_cache.shrink);

Ditto.

Quoted 21 lines
fs/bcachefs/btree_cache.c +2 -1
  	struct btree_cache *bc = &c->btree_cache;
 
@@ -400,7 +400,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
  	struct btree *b;
  	unsigned i, flags;
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
  	/* vfree() can allocate memory: */
  	flags = memalloc_nofs_save();
@@ -454,6 +454,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
  int bch2_fs_btree_cache_init(struct bch_fs *c)
  {
  	struct btree_cache *bc = &c->btree_cache;
+	struct shrinker *shrink;
  	unsigned i;
  	int ret = 0;
 
@@ -473,12 +474,14 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
 

fs/bcachefs/btree_cache.c int bch2_fs_btree_cache_init(struct bch_fs *c) · line 479

Quoted 10 lines
fs/bcachefs/btree_cache.c +2 -5
  	mutex_init(&c->verify_lock);
 
-	bc->shrink.count_objects	= bch2_btree_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_cache_scan;
-	bc->shrink.seeks		= 4;
-	ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
-	if (ret)
+	shrink = shrinker_alloc(0, "%s/btree_cache", c->name);
+	if (!shrink)
  		goto err;

Here the 'ret' needs to be set to -ENOMEM.

	if (!shrink) {
		ret = -ENOMEM;
		goto err;
	}

fs/bcachefs/btree_cache.c int bch2_fs_btree_cache_init(struct bch_fs *c) · line 483

Quoted 4 lines
fs/bcachefs/btree_cache.c +4 -0
+	bc->shrink = shrink;
+	shrink->count_objects	= bch2_btree_cache_count;
+	shrink->scan_objects	= bch2_btree_cache_scan;
+	shrink->seeks		= 4;
	shrink->private_data = c;
Quoted 9 lines
fs/bcachefs/btree_cache.c +1 -0
+	shrinker_register(shrink);
 
  	return 0;
  err:
fs/bcachefs/btree_key_cache.c +0 -0
index 505e7c365ab7..88d33690233b 100644

fs/bcachefs/btree_key_cache.c void bch2_btree_key_cache_drop(struct btree_trans *trans, · line 842

Quoted 6 lines
fs/bcachefs/btree_key_cache.c +1 -1
@@ -838,7 +838,7 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
  static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
  					   struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_key_cache.shrink);
	struct bch_fs *c = shrink->private_data;

fs/bcachefs/btree_key_cache.c static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink, · line 940

Quoted 9 lines
fs/bcachefs/btree_key_cache.c +1 -1
  	struct btree_key_cache *bc = &c->btree_key_cache;
  	struct bucket_table *tbl;
@@ -936,7 +936,7 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
  static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink,
  					    struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_key_cache.shrink);

Ditto.

fs/bcachefs/btree_key_cache.c int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)

Quoted 20 lines
fs/bcachefs/btree_key_cache.c +2 -1
  	struct btree_key_cache *bc = &c->btree_key_cache;
  	long nr = atomic_long_read(&bc->nr_keys) -
@@ -957,7 +957,7 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
  	int cpu;
  #endif
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
  	mutex_lock(&bc->lock);
 
@@ -1031,6 +1031,7 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c)
  int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
  {
  	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);
+	struct shrinker *shrink;
 
  #ifdef __KERNEL__
  	bc->pcpu_freed = alloc_percpu(struct btree_key_cache_freelist);
@@ -1043,11 +1044,14 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);
Quoted 4 lines
fs/bcachefs/btree_key_cache.c +0 -1
  	bc->table_init_done = true;
 
-	bc->shrink.seeks		= 0;

fs/bcachefs/btree_key_cache.c int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc) · line 1053

Quoted 10 lines
fs/bcachefs/btree_key_cache.c +6 -3
-	bc->shrink.count_objects	= bch2_btree_key_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_key_cache_scan;
-	if (register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name))
+	shrink = shrinker_alloc(0, "%s/btree_key_cache", c->name);
+	if (!shrink)
  		return -BCH_ERR_ENOMEM_fs_btree_cache_init;
+	bc->shrink = shrink;
+	shrink->seeks		= 0;
+	shrink->count_objects	= bch2_btree_key_cache_count;
+	shrink->scan_objects	= bch2_btree_key_cache_scan;
	shrink->private_data = c;
Quoted 52 lines
fs/bcachefs/btree_key_cache.c +1 -0
+	shrinker_register(shrink);
  	return 0;
  }
 
fs/bcachefs/btree_types.h +2 -2
index 70398aaa095e..fac0abdaf167 100644
@@ -163,7 +163,7 @@ struct btree_cache {
  	unsigned		used;
  	unsigned		reserve;
  	atomic_t		dirty;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
 
  	/*
  	 * If we need to allocate memory for a new btree node and that
@@ -321,7 +321,7 @@ struct btree_key_cache {
  	bool			table_init_done;
  	struct list_head	freed_pcpu;
  	struct list_head	freed_nonpcpu;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
  	unsigned		shrink_iter;
  	struct btree_key_cache_freelist __percpu *pcpu_freed;
 
fs/bcachefs/fs.c +1 -1
index 48431700b83e..bdc8573631bd 100644
@@ -1885,7 +1885,7 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
  		sb->s_flags	|= SB_POSIXACL;
  #endif
 
-	sb->s_shrink.seeks = 0;
+	sb->s_shrink->seeks = 0;
 
  	vinode = bch2_vfs_inode_get(c, BCACHEFS_ROOT_SUBVOL_INUM);
  	ret = PTR_ERR_OR_ZERO(vinode);
fs/bcachefs/sysfs.c +1 -1
index 41c6900c34c1..a9f480c26bb4 100644
@@ -522,7 +522,7 @@ STORE(bch2_fs)
 
  		sc.gfp_mask = GFP_KERNEL;
  		sc.nr_to_scan = strtoul_or_return(buf);
-		c->btree_cache.shrink.scan_objects(&c->btree_cache.shrink, &sc);
+		c->btree_cache.shrink->scan_objects(c->btree_cache.shrink, &sc);
  	}
 
  	if (attr == &sysfs_btree_wakeup)
#2 lore raw

Hi Qi,

Thanks for the corrections. See below.

Quoted 16 lines · On Tue, 12 Sep 2023 10:47:14 +0800 Qi Zheng <[email protected]> wrote:

fs/bcachefs/btree_cache.c static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b) · line 289

Quoted 12 lines
fs/bcachefs/btree_cache.c +1 -1
index 245ddd92b2d1..7f0eded6c296 100644
@@ -285,7 +285,7 @@ static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b)
  static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
  					   struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_cache.shrink);  

The shrink passed in here will be a local variable, so its address can not be used directly. So need to be modified as follows:

Quoted 1 line
	struct bch_fs *c = shrink->private_data;

OK.

Quoted 9 lines

fs/bcachefs/btree_cache.c static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, · line 388

Quoted 7 lines
fs/bcachefs/btree_cache.c +1 -1
@@ -384,7 +384,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
  static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
  					    struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_cache.shrink);  

Ditto.

OK

Quoted 13 lines

fs/bcachefs/btree_cache.c

Quoted 10 lines
fs/bcachefs/btree_cache.c +0 -0
  > @@ -473,12 +474,14 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
  >   	mutex_init(&c->verify_lock);
Quoted 1 line
(quoted diff) +0 -1
-	bc->shrink.count_objects	= bch2_btree_cache_count;  
fs/bcachefs/btree_cache.c +2 -4
-	bc->shrink.scan_objects		= bch2_btree_cache_scan;
-	bc->shrink.seeks		= 4;
-	ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
-	if (ret)
+	shrink = shrinker_alloc(0, "%s/btree_cache", c->name);
+	if (!shrink)
  		goto err;  

Here the 'ret' needs to be set to -ENOMEM.

Quoted 4 lines
	if (!shrink) {
		ret = -ENOMEM;
		goto err;
	}

Except err: does this:

    return -BCH_ERR_ENOMEM_fs_btree_cache_init;

so ret does not need to be set.

Quoted 6 lines

fs/bcachefs/btree_cache.c

Quoted 4 lines
fs/bcachefs/btree_cache.c +4 -0
+	bc->shrink = shrink;
+	shrink->count_objects	= bch2_btree_cache_count;
+	shrink->scan_objects	= bch2_btree_cache_scan;
+	shrink->seeks		= 4;  
	shrink->private_data = c;

OK

Quoted 5 lines
Quoted 5 lines
fs/bcachefs/btree_key_cache.c +0 -0
index 505e7c365ab7..88d33690233b 100644
@@ -838,7 +838,7 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
Quoted 9 lines

fs/bcachefs/btree_key_cache.c void bch2_btree_key_cache_drop(struct btree_trans *trans, · line 842

Quoted 6 lines
fs/bcachefs/btree_key_cache.c +1 -1
  static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
  					   struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_key_cache.shrink);  
	struct bch_fs *c = shrink->private_data;

OK

Quoted 9 lines

fs/bcachefs/btree_key_cache.c static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink, · line 940

Quoted 7 lines
fs/bcachefs/btree_key_cache.c +1 -1
@@ -936,7 +936,7 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
  static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink,
  					    struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
  					btree_key_cache.shrink);  

Ditto.

OK

Quoted 8 lines
Quoted 8 lines
fs/bcachefs/btree_key_cache.c +1 -0
@@ -957,7 +957,7 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
  	int cpu;
  #endif  
  > -	unregister_shrinker(&bc->shrink);  
+	shrinker_free(bc->shrink);  
  >   	mutex_lock(&bc->lock);
  > @@ -1031,6 +1031,7 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c)  
  int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
Quoted 8 lines

fs/bcachefs/btree_key_cache.c int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)

Quoted 6 lines
fs/bcachefs/btree_key_cache.c +1 -0
  {
  	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);
+	struct shrinker *shrink;  
  >   #ifdef __KERNEL__  
  	bc->pcpu_freed = alloc_percpu(struct btree_key_cache_freelist);
@@ -1043,11 +1044,14 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)  
	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);

Already done n this function.

Quoted 6 lines
Quoted 6 lines
fs/bcachefs/btree_key_cache.c +1 -3
  >   	bc->table_init_done = true;
  > -	bc->shrink.seeks		= 0;  
-	bc->shrink.count_objects	= bch2_btree_key_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_key_cache_scan;
-	if (register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name))
+	shrink = shrinker_alloc(0, "%s/btree_key_cache", c->name);
Quoted 8 lines

fs/bcachefs/btree_key_cache.c int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc) · line 1052

Quoted 6 lines
fs/bcachefs/btree_key_cache.c +5 -0
+	if (!shrink)
  		return -BCH_ERR_ENOMEM_fs_btree_cache_init;
+	bc->shrink = shrink;
+	shrink->seeks		= 0;
+	shrink->count_objects	= bch2_btree_key_cache_count;
+	shrink->scan_objects	= bch2_btree_key_cache_scan;  
	shrink->private_data = c;

OK

So the merge resolution patch now looks like this:

From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

---
 fs/bcachefs/btree_cache.c     | 22 ++++++++++++----------
 fs/bcachefs/btree_key_cache.c | 21 ++++++++++++---------
 fs/bcachefs/btree_types.h     |  4 ++--
 fs/bcachefs/fs.c              |  2 +-
 fs/bcachefs/sysfs.c           |  2 +-
 5 files changed, 28 insertions(+), 23 deletions(-)
fs/bcachefs/btree_cache.c +12 -10
index 245ddd92b2d1..d8cd0bbc33cc 100644
@@ -285,8 +285,7 @@ static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b)
 static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
 					   struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
 	struct btree_cache *bc = &c->btree_cache;
 	struct btree *b, *t;
 	unsigned long nr = sc->nr_to_scan;
@@ -384,8 +383,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
 static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
 					    struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
 	struct btree_cache *bc = &c->btree_cache;
 
 	if (bch2_btree_shrinker_disabled)
@@ -400,7 +398,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
 	struct btree *b;
 	unsigned i, flags;
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
 	/* vfree() can allocate memory: */
 	flags = memalloc_nofs_save();
@@ -454,6 +452,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
 int bch2_fs_btree_cache_init(struct bch_fs *c)
 {
 	struct btree_cache *bc = &c->btree_cache;
+	struct shrinker *shrink;
 	unsigned i;
 	int ret = 0;
 
@@ -473,12 +472,15 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
 
 	mutex_init(&c->verify_lock);
 
-	bc->shrink.count_objects	= bch2_btree_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_cache_scan;
-	bc->shrink.seeks		= 4;
-	ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
-	if (ret)
+	shrink = shrinker_alloc(0, "%s/btree_cache", c->name);
+	if (!shrink)
 		goto err;
+	bc->shrink = shrink;
+	shrink->count_objects	= bch2_btree_cache_count;
+	shrink->scan_objects	= bch2_btree_cache_scan;
+	shrink->seeks		= 4;
+	shrink->private_data	= c;
+	shrinker_register(shrink);
 
 	return 0;
 err:
fs/bcachefs/btree_key_cache.c +12 -9
index 505e7c365ab7..ed387eb915c3 100644
@@ -838,8 +838,7 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
 static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
 					   struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_key_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
 	struct btree_key_cache *bc = &c->btree_key_cache;
 	struct bucket_table *tbl;
 	struct bkey_cached *ck, *t;
@@ -936,8 +935,7 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
 static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink,
 					    struct shrink_control *sc)
 {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_key_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
 	struct btree_key_cache *bc = &c->btree_key_cache;
 	long nr = atomic_long_read(&bc->nr_keys) -
 		atomic_long_read(&bc->nr_dirty);
@@ -957,7 +955,7 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
 	int cpu;
 #endif
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
 	mutex_lock(&bc->lock);
 
@@ -1031,6 +1029,7 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c)
 int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
 {
 	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);
+	struct shrinker *shrink;
 
 #ifdef __KERNEL__
 	bc->pcpu_freed = alloc_percpu(struct btree_key_cache_freelist);
@@ -1043,11 +1042,15 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
 
 	bc->table_init_done = true;
 
-	bc->shrink.seeks		= 0;
-	bc->shrink.count_objects	= bch2_btree_key_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_key_cache_scan;
-	if (register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name))
+	shrink = shrinker_alloc(0, "%s/btree_key_cache", c->name);
+	if (!shrink)
 		return -BCH_ERR_ENOMEM_fs_btree_cache_init;
+	bc->shrink = shrink;
+	shrink->seeks		= 0;
+	shrink->count_objects	= bch2_btree_key_cache_count;
+	shrink->scan_objects	= bch2_btree_key_cache_scan;
+	shrink->private_data	= c;
+	shrinker_register(shrink);
 	return 0;
 }
 
fs/bcachefs/btree_types.h +2 -2
index 70398aaa095e..fac0abdaf167 100644
@@ -163,7 +163,7 @@ struct btree_cache {
 	unsigned		used;
 	unsigned		reserve;
 	atomic_t		dirty;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
 
 	/*
 	 * If we need to allocate memory for a new btree node and that
@@ -321,7 +321,7 @@ struct btree_key_cache {
 	bool			table_init_done;
 	struct list_head	freed_pcpu;
 	struct list_head	freed_nonpcpu;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
 	unsigned		shrink_iter;
 	struct btree_key_cache_freelist __percpu *pcpu_freed;
 
fs/bcachefs/fs.c +1 -1
index 48431700b83e..bdc8573631bd 100644
@@ -1885,7 +1885,7 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
 		sb->s_flags	|= SB_POSIXACL;
 #endif
 
-	sb->s_shrink.seeks = 0;
+	sb->s_shrink->seeks = 0;
 
 	vinode = bch2_vfs_inode_get(c, BCACHEFS_ROOT_SUBVOL_INUM);
 	ret = PTR_ERR_OR_ZERO(vinode);
fs/bcachefs/sysfs.c +1 -1
index 41c6900c34c1..a9f480c26bb4 100644
@@ -522,7 +522,7 @@ STORE(bch2_fs)
 
 		sc.gfp_mask = GFP_KERNEL;
 		sc.nr_to_scan = strtoul_or_return(buf);
-		c->btree_cache.shrink.scan_objects(&c->btree_cache.shrink, &sc);
+		c->btree_cache.shrink->scan_objects(c->btree_cache.shrink, &sc);
 	}
 
 	if (attr == &sysfs_btree_wakeup)
Signature · 5 lines
2.40.1

-- 
Cheers,
Stephen Rothwell
Reviewed-by
#3 lore raw

Hi Stephen,

Quoted 141 lines · Stephen Rothwell

Hi Qi,

Thanks for the corrections. See below.

Quoted 16 lines · On Tue, 12 Sep 2023 10:47:14 +0800 Qi Zheng <[email protected]> wrote:

fs/bcachefs/btree_cache.c static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b) · line 289

Quoted 12 lines
fs/bcachefs/btree_cache.c +1 -1
index 245ddd92b2d1..7f0eded6c296 100644
@@ -285,7 +285,7 @@ static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b)
   static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
   					   struct shrink_control *sc)
   {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
   					btree_cache.shrink);

The shrink passed in here will be a local variable, so its address can not be used directly. So need to be modified as follows:

Quoted 1 line
	struct bch_fs *c = shrink->private_data;

OK.

Quoted 9 lines

fs/bcachefs/btree_cache.c static unsigned long bch2_btree_cache_scan(struct shrinker *shrink, · line 388

Quoted 7 lines
fs/bcachefs/btree_cache.c +1 -1
@@ -384,7 +384,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
   static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
   					    struct shrink_control *sc)
   {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
   					btree_cache.shrink);

Ditto.

OK

Quoted 13 lines

fs/bcachefs/btree_cache.c int bch2_fs_btree_cache_init(struct bch_fs *c) · line 477

Quoted 10 lines
fs/bcachefs/btree_cache.c +0 -0
   > @@ -473,12 +474,14 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
   >   	mutex_init(&c->verify_lock);
Quoted 1 line
fs/bcachefs/btree_cache.c +0 -1
-	bc->shrink.count_objects	= bch2_btree_cache_count;
fs/bcachefs/btree_cache.c +2 -4
-	bc->shrink.scan_objects		= bch2_btree_cache_scan;
-	bc->shrink.seeks		= 4;
-	ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
-	if (ret)
+	shrink = shrinker_alloc(0, "%s/btree_cache", c->name);
+	if (!shrink)
   		goto err;

Here the 'ret' needs to be set to -ENOMEM.

Quoted 4 lines
	if (!shrink) {
		ret = -ENOMEM;
		goto err;
	}

Except err: does this:

     return -BCH_ERR_ENOMEM_fs_btree_cache_init;

so ret does not need to be set.

Quoted 6 lines

fs/bcachefs/btree_cache.c int bch2_fs_btree_cache_init(struct bch_fs *c) · line 481

Quoted 4 lines
fs/bcachefs/btree_cache.c +4 -0
+	bc->shrink = shrink;
+	shrink->count_objects	= bch2_btree_cache_count;
+	shrink->scan_objects	= bch2_btree_cache_scan;
+	shrink->seeks		= 4;
	shrink->private_data = c;

OK

Quoted 5 lines
Quoted 5 lines
fs/bcachefs/btree_key_cache.c +0 -0
index 505e7c365ab7..88d33690233b 100644
@@ -838,7 +838,7 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
Quoted 9 lines

fs/bcachefs/btree_key_cache.c void bch2_btree_key_cache_drop(struct btree_trans *trans,

Quoted 6 lines
fs/bcachefs/btree_key_cache.c +1 -1
   static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
   					   struct shrink_control *sc)
   {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
   					btree_key_cache.shrink);
	struct bch_fs *c = shrink->private_data;

OK

Quoted 9 lines

fs/bcachefs/btree_key_cache.c static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink, · line 940

Quoted 7 lines
fs/bcachefs/btree_key_cache.c +1 -1
@@ -936,7 +936,7 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
   static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink,
   					    struct shrink_control *sc)
   {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
+	struct bch_fs *c = container_of(&shrink, struct bch_fs,
   					btree_key_cache.shrink);

Ditto.

OK

Quoted 8 lines
Quoted 8 lines
fs/bcachefs/btree_key_cache.c +1 -0
@@ -957,7 +957,7 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
   	int cpu;
   #endif
   > -	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
   >   	mutex_lock(&bc->lock);
   > @@ -1031,6 +1031,7 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c)
   int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
Quoted 8 lines

fs/bcachefs/btree_key_cache.c int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)

Quoted 6 lines
fs/bcachefs/btree_key_cache.c +1 -0
   {
   	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);
+	struct shrinker *shrink;
   >   #ifdef __KERNEL__
   	bc->pcpu_freed = alloc_percpu(struct btree_key_cache_freelist);
@@ -1043,11 +1044,14 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);

Already done n this function.

Quoted 6 lines
Quoted 6 lines
fs/bcachefs/btree_key_cache.c +1 -3
   >   	bc->table_init_done = true;
   > -	bc->shrink.seeks		= 0;
-	bc->shrink.count_objects	= bch2_btree_key_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_key_cache_scan;
-	if (register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name))
+	shrink = shrinker_alloc(0, "%s/btree_key_cache", c->name);
Quoted 8 lines

fs/bcachefs/btree_key_cache.c int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc) · line 1051

Quoted 6 lines
fs/bcachefs/btree_key_cache.c +5 -0
+	if (!shrink)
   		return -BCH_ERR_ENOMEM_fs_btree_cache_init;
+	bc->shrink = shrink;
+	shrink->seeks		= 0;
+	shrink->count_objects	= bch2_btree_key_cache_count;
+	shrink->scan_objects	= bch2_btree_key_cache_scan;
	shrink->private_data = c;

OK

So the merge resolution patch now looks like this:

From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

Quoted 8 lines
---
  fs/bcachefs/btree_cache.c     | 22 ++++++++++++----------
  fs/bcachefs/btree_key_cache.c | 21 ++++++++++++---------
  fs/bcachefs/btree_types.h     |  4 ++--
  fs/bcachefs/fs.c              |  2 +-
  fs/bcachefs/sysfs.c           |  2 +-
  5 files changed, 28 insertions(+), 23 deletions(-)

This version looks good to me.

Thanks,
Qi

Quoted 172 lines
fs/bcachefs/btree_cache.c +12 -10
index 245ddd92b2d1..d8cd0bbc33cc 100644
@@ -285,8 +285,7 @@ static int btree_node_write_and_reclaim(struct bch_fs *c, struct btree *b)
  static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
  					   struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
  	struct btree_cache *bc = &c->btree_cache;
  	struct btree *b, *t;
  	unsigned long nr = sc->nr_to_scan;
@@ -384,8 +383,7 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
  static unsigned long bch2_btree_cache_count(struct shrinker *shrink,
  					    struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
  	struct btree_cache *bc = &c->btree_cache;
 
  	if (bch2_btree_shrinker_disabled)
@@ -400,7 +398,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
  	struct btree *b;
  	unsigned i, flags;
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
  	/* vfree() can allocate memory: */
  	flags = memalloc_nofs_save();
@@ -454,6 +452,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
  int bch2_fs_btree_cache_init(struct bch_fs *c)
  {
  	struct btree_cache *bc = &c->btree_cache;
+	struct shrinker *shrink;
  	unsigned i;
  	int ret = 0;
 
@@ -473,12 +472,15 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
 
  	mutex_init(&c->verify_lock);
 
-	bc->shrink.count_objects	= bch2_btree_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_cache_scan;
-	bc->shrink.seeks		= 4;
-	ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
-	if (ret)
+	shrink = shrinker_alloc(0, "%s/btree_cache", c->name);
+	if (!shrink)
  		goto err;
+	bc->shrink = shrink;
+	shrink->count_objects	= bch2_btree_cache_count;
+	shrink->scan_objects	= bch2_btree_cache_scan;
+	shrink->seeks		= 4;
+	shrink->private_data	= c;
+	shrinker_register(shrink);
 
  	return 0;
  err:
fs/bcachefs/btree_key_cache.c +12 -9
index 505e7c365ab7..ed387eb915c3 100644
@@ -838,8 +838,7 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
  static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
  					   struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_key_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
  	struct btree_key_cache *bc = &c->btree_key_cache;
  	struct bucket_table *tbl;
  	struct bkey_cached *ck, *t;
@@ -936,8 +935,7 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
  static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink,
  					    struct shrink_control *sc)
  {
-	struct bch_fs *c = container_of(shrink, struct bch_fs,
-					btree_key_cache.shrink);
+	struct bch_fs *c = shrink->private_data;
  	struct btree_key_cache *bc = &c->btree_key_cache;
  	long nr = atomic_long_read(&bc->nr_keys) -
  		atomic_long_read(&bc->nr_dirty);
@@ -957,7 +955,7 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
  	int cpu;
  #endif
 
-	unregister_shrinker(&bc->shrink);
+	shrinker_free(bc->shrink);
 
  	mutex_lock(&bc->lock);
 
@@ -1031,6 +1029,7 @@ void bch2_fs_btree_key_cache_init_early(struct btree_key_cache *c)
  int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
  {
  	struct bch_fs *c = container_of(bc, struct bch_fs, btree_key_cache);
+	struct shrinker *shrink;
 
  #ifdef __KERNEL__
  	bc->pcpu_freed = alloc_percpu(struct btree_key_cache_freelist);
@@ -1043,11 +1042,15 @@ int bch2_fs_btree_key_cache_init(struct btree_key_cache *bc)
 
  	bc->table_init_done = true;
 
-	bc->shrink.seeks		= 0;
-	bc->shrink.count_objects	= bch2_btree_key_cache_count;
-	bc->shrink.scan_objects		= bch2_btree_key_cache_scan;
-	if (register_shrinker(&bc->shrink, "%s/btree_key_cache", c->name))
+	shrink = shrinker_alloc(0, "%s/btree_key_cache", c->name);
+	if (!shrink)
  		return -BCH_ERR_ENOMEM_fs_btree_cache_init;
+	bc->shrink = shrink;
+	shrink->seeks		= 0;
+	shrink->count_objects	= bch2_btree_key_cache_count;
+	shrink->scan_objects	= bch2_btree_key_cache_scan;
+	shrink->private_data	= c;
+	shrinker_register(shrink);
  	return 0;
  }
 
fs/bcachefs/btree_types.h +2 -2
index 70398aaa095e..fac0abdaf167 100644
@@ -163,7 +163,7 @@ struct btree_cache {
  	unsigned		used;
  	unsigned		reserve;
  	atomic_t		dirty;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
 
  	/*
  	 * If we need to allocate memory for a new btree node and that
@@ -321,7 +321,7 @@ struct btree_key_cache {
  	bool			table_init_done;
  	struct list_head	freed_pcpu;
  	struct list_head	freed_nonpcpu;
-	struct shrinker		shrink;
+	struct shrinker		*shrink;
  	unsigned		shrink_iter;
  	struct btree_key_cache_freelist __percpu *pcpu_freed;
 
fs/bcachefs/fs.c +1 -1
index 48431700b83e..bdc8573631bd 100644
@@ -1885,7 +1885,7 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
  		sb->s_flags	|= SB_POSIXACL;
  #endif
 
-	sb->s_shrink.seeks = 0;
+	sb->s_shrink->seeks = 0;
 
  	vinode = bch2_vfs_inode_get(c, BCACHEFS_ROOT_SUBVOL_INUM);
  	ret = PTR_ERR_OR_ZERO(vinode);
fs/bcachefs/sysfs.c +1 -1
index 41c6900c34c1..a9f480c26bb4 100644
@@ -522,7 +522,7 @@ STORE(bch2_fs)
 
  		sc.gfp_mask = GFP_KERNEL;
  		sc.nr_to_scan = strtoul_or_return(buf);
-		c->btree_cache.shrink.scan_objects(&c->btree_cache.shrink, &sc);
+		c->btree_cache.shrink->scan_objects(c->btree_cache.shrink, &sc);
  	}
 
  	if (attr == &sysfs_btree_wakeup)
#4 lore raw
Quoted 13 lines · On Wed, 13 Sep 2023 09:10:11 +0800 Qi Zheng <[email protected]> wrote:
Quoted 4 lines

From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

Quoted 8 lines
---
  fs/bcachefs/btree_cache.c     | 22 ++++++++++++----------
  fs/bcachefs/btree_key_cache.c | 21 ++++++++++++---------
  fs/bcachefs/btree_types.h     |  4 ++--
  fs/bcachefs/fs.c              |  2 +-
  fs/bcachefs/sysfs.c           |  2 +-
  5 files changed, 28 insertions(+), 23 deletions(-)
Quoted 3 lines

This version looks good to me.

I not longer carry a post-linux-next patch queue, so there's nothing I can do with this patch. I'll assume that either Kent or I will merge it later, depending upon whose stuff goes into mainline first.

#5 lore raw

Hi Andrew,

Quoted 16 lines · On Wed, 13 Sep 2023 13:23:30 -0700 Andrew Morton <[email protected]>…
Quoted 13 lines · On Wed, 13 Sep 2023 09:10:11 +0800 Qi Zheng <[email protected]> wrote:
Quoted 12 lines

From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

---
  fs/bcachefs/btree_cache.c     | 22 ++++++++++++----------
  fs/bcachefs/btree_key_cache.c | 21 ++++++++++++---------
  fs/bcachefs/btree_types.h     |  4 ++--
  fs/bcachefs/fs.c              |  2 +-
  fs/bcachefs/sysfs.c           |  2 +-
  5 files changed, 28 insertions(+), 23 deletions(-)  
Quoted 7 lines
Quoted 3 lines

This version looks good to me.

I not longer carry a post-linux-next patch queue, so there's nothing I can do with this patch. I'll assume that either Kent or I will merge it later, depending upon whose stuff goes into mainline first.

Actually the correct plan is for you and Kent to inform Linus of the need for this patch as part of the merge resolution when he merges the latter of your trees (unless you want to stabilise the shrinker changes into a separate branch that is never rewritten and is merged into your tree and the bcachefs tree).

Signature · 2 lines
Cheers,
Stephen Rothwell
#6 lore raw

Hi Andrew,

Quoted 26 lines · On Thu, 14 Sep 2023 08:31:45 +1000 Stephen Rothwell <[email protected]>…
Quoted 16 lines · On Wed, 13 Sep 2023 13:23:30 -0700 Andrew Morton <[email protected]>…
Quoted 13 lines · On Wed, 13 Sep 2023 09:10:11 +0800 Qi Zheng <[email protected]> wrote:
Quoted 12 lines

From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

---
  fs/bcachefs/btree_cache.c     | 22 ++++++++++++----------
  fs/bcachefs/btree_key_cache.c | 21 ++++++++++++---------
  fs/bcachefs/btree_types.h     |  4 ++--
  fs/bcachefs/fs.c              |  2 +-
  fs/bcachefs/sysfs.c           |  2 +-
  5 files changed, 28 insertions(+), 23 deletions(-)    
Quoted 7 lines
Quoted 3 lines

This version looks good to me.

I not longer carry a post-linux-next patch queue, so there's nothing I can do with this patch. I'll assume that either Kent or I will merge it later, depending upon whose stuff goes into mainline first.

Quoted 5 lines

Actually the correct plan is for you and Kent to inform Linus of the need for this patch as part of the merge resolution when he merges the latter of your trees (unless you want to stabilise the shrinker changes into a separate branch that is never rewritten and is merged into your tree and the bcachefs tree).

This is now a conflict between the mm-stable tree and Linus' tree.

Signature · 2 lines
Cheers,
Stephen Rothwell
#7 lore raw
Quoted 29 lines · Stephen Rothwell

Hi Andrew,

Quoted 26 lines · On Thu, 14 Sep 2023 08:31:45 +1000 Stephen Rothwell <[email protected]>…
Quoted 23 lines · On Wed, 13 Sep 2023 13:23:30 -0700 Andrew Morton <[email protected]>…
Quoted 13 lines · On Wed, 13 Sep 2023 09:10:11 +0800 Qi Zheng <[email protected]> wrote:
Quoted 4 lines

From: Stephen Rothwell <[email protected]>
Date: Tue, 12 Sep 2023 11:27:22 +1000
Subject: [PATCH] bcachefs: convert to dynamically allocated shrinkers

Quoted 8 lines
---
  fs/bcachefs/btree_cache.c     | 22 ++++++++++++----------
  fs/bcachefs/btree_key_cache.c | 21 ++++++++++++---------
  fs/bcachefs/btree_types.h     |  4 ++--
  fs/bcachefs/fs.c              |  2 +-
  fs/bcachefs/sysfs.c           |  2 +-
  5 files changed, 28 insertions(+), 23 deletions(-)    
Quoted 3 lines

This version looks good to me.

I not longer carry a post-linux-next patch queue, so there's nothing I can do with this patch. I'll assume that either Kent or I will merge it later, depending upon whose stuff goes into mainline first.

Quoted 7 lines
Quoted 5 lines

Actually the correct plan is for you and Kent to inform Linus of the need for this patch as part of the merge resolution when he merges the latter of your trees (unless you want to stabilise the shrinker changes into a separate branch that is never rewritten and is merged into your tree and the bcachefs tree).

This is now a conflict between the mm-stable tree and Linus' tree.

Is/was there a procedure for me here?

#8 lore raw

Hi Kent,

Quoted 2 lines · On Tue, 31 Oct 2023 20:53:07 -0400 Kent Overstreet <[email protected]>…

Is/was there a procedure for me here?

You should have mentioned it in your pull request to Linus (in case he merged Andrew's tree first (I don't know if you did). And presumably Andrew will mention it in his pull request to Linus.

Signature · 2 lines
Cheers,
Stephen Rothwell
#9 lore raw
In reply to Stephen Rothwell

Hi all,

Quoted 18 lines · On Tue, 12 Sep 2023 12:04:29 +1000 Stephen Rothwell <[email protected]>…

After merging the bcachefs tree, today's linux-next build (x86_64 allmodconfig) failed like this:

fs/bcachefs/btree_cache.c: In function 'bch2_fs_btree_cache_exit':
fs/bcachefs/btree_cache.c:403:9: error: implicit declaration of function 'unregister_shrinker'; did you mean 'unregister_chrdev'? [-Werror=implicit-function-declaration]

  403 |         unregister_shrinker(&bc->shrink);
      |         ^~~~~~~~~~~~~~~~~~~
      |         unregister_chrdev
fs/bcachefs/btree_cache.c: In function 'bch2_fs_btree_cache_init':
fs/bcachefs/btree_cache.c:479:15: error: implicit declaration of function 'register_shrinker'; did you mean 'register_chrdev'? [-Werror=implicit-function-declaration]
  479 |         ret = register_shrinker(&bc->shrink, "%s/btree_cache", c->name);
      |               ^~~~~~~~~~~~~~~~~
      |               register_chrdev

cc1: all warnings being treated as errors

Caused by commits

Quoted 7 lines

5ec30115c066 ("bcachefs: Initial commit")

interacting with commit

eba045d9350d ("mm: shrinker: remove old APIs")

from v6.6-rc1.

This latter commit is actually in the mm tree and is now commit

d3ed57149dec ("mm: shrinker: remove old APIs")

Signature · 2 lines
Cheers,
Stephen Rothwell