[PATCH] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init

Kunwu Chan posted 1 patch 1 year, 10 months ago
There is a newer version of this series
fs/btrfs/delayed-inode.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
[PATCH] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init
Posted by Kunwu Chan 1 year, 10 months ago
commit 0a31bd5f2bbb ("KMEM_CACHE(): simplify slab cache creation")
introduces a new macro.
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 fs/btrfs/delayed-inode.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 08102883f560..8c748c6cdf6d 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -28,11 +28,7 @@ static struct kmem_cache *delayed_node_cache;
 
 int __init btrfs_delayed_inode_init(void)
 {
-	delayed_node_cache = kmem_cache_create("btrfs_delayed_node",
-					sizeof(struct btrfs_delayed_node),
-					0,
-					SLAB_MEM_SPREAD,
-					NULL);
+	delayed_node_cache = KMEM_CACHE(btrfs_delayed_node, SLAB_MEM_SPREAD);
 	if (!delayed_node_cache)
 		return -ENOMEM;
 	return 0;
-- 
2.39.2
Re: [PATCH] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init
Posted by Johannes Thumshirn 1 year, 10 months ago
On 31.01.24 07:20, Kunwu Chan wrote:
> commit 0a31bd5f2bbb ("KMEM_CACHE(): simplify slab cache creation")
> introduces a new macro.
> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create

That commit is 17 years old. Why should we switch to it _now_? I 
wouldn't call it a new macro.

Don't get me wrong, I don't oppose the patch, but I'd prefer a better 
explanation why now and not 17 years ago when the macro got introduced.

> to simplify the creation of SLAB caches.
> 
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
>   fs/btrfs/delayed-inode.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
> index 08102883f560..8c748c6cdf6d 100644
> --- a/fs/btrfs/delayed-inode.c
> +++ b/fs/btrfs/delayed-inode.c
> @@ -28,11 +28,7 @@ static struct kmem_cache *delayed_node_cache;
>   
>   int __init btrfs_delayed_inode_init(void)
>   {
> -	delayed_node_cache = kmem_cache_create("btrfs_delayed_node",
> -					sizeof(struct btrfs_delayed_node),
> -					0,
> -					SLAB_MEM_SPREAD,
> -					NULL);
> +	delayed_node_cache = KMEM_CACHE(btrfs_delayed_node, SLAB_MEM_SPREAD);
>   	if (!delayed_node_cache)
>   		return -ENOMEM;
>   	return 0;

Re: [PATCH] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init
Posted by David Sterba 1 year, 10 months ago
On Wed, Jan 31, 2024 at 10:20:35AM +0000, Johannes Thumshirn wrote:
> On 31.01.24 07:20, Kunwu Chan wrote:
> > commit 0a31bd5f2bbb ("KMEM_CACHE(): simplify slab cache creation")
> > introduces a new macro.
> > Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
> 
> That commit is 17 years old. Why should we switch to it _now_? I 
> wouldn't call it a new macro.

I had the same reaction after checking the commit that added it.
> 
> Don't get me wrong, I don't oppose the patch, but I'd prefer a better 
> explanation why now and not 17 years ago when the macro got introduced.

We can add the macros where possible, at least it hides all the 0 or
NULL parameters, but yeah with a better changelog.