Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create
@ 2024-02-20  9:06 Kunwu Chan
  2024-02-20  9:06 ` [PATCH 1/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init Kunwu Chan
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-20  9:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kunwu Chan

As David Sterba said in 
https://lore.kernel.org/all/20240205160408.GI355@twin.jikos.cz/
I'm using a patchset to cleanup the same issues in the 'brtfs' module.

For where the cache name and the structure name match.
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.

Kunwu Chan (6):
  btrfs: Simplify the allocation of slab caches in
    btrfs_delayed_inode_init
  btrfs: Simplify the allocation of slab caches in ordered_data_init
  btrfs: Simplify the allocation of slab caches in
    btrfs_transaction_init
  btrfs: Simplify the allocation of slab caches in btrfs_ctree_init
  btrfs: Simplify the allocation of slab caches in
    btrfs_delayed_ref_init
  btrfs: Simplify the allocation of slab caches in btrfs_free_space_init

 fs/btrfs/ctree.c            |  4 +---
 fs/btrfs/delayed-inode.c    |  6 +-----
 fs/btrfs/delayed-ref.c      | 24 ++++++++----------------
 fs/btrfs/free-space-cache.c |  4 +---
 fs/btrfs/ordered-data.c     |  5 +----
 fs/btrfs/transaction.c      |  5 ++---
 6 files changed, 14 insertions(+), 34 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init
  2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
@ 2024-02-20  9:06 ` Kunwu Chan
  2024-02-20  9:06 ` [PATCH 2/6] btrfs: Simplify the allocation of slab caches in ordered_data_init Kunwu Chan
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-20  9:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kunwu Chan

Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.
Make the code cleaner and more readable.

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/6] btrfs: Simplify the allocation of slab caches in ordered_data_init
  2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
  2024-02-20  9:06 ` [PATCH 1/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init Kunwu Chan
@ 2024-02-20  9:06 ` Kunwu Chan
  2024-02-20  9:06 ` [PATCH 3/6] btrfs: Simplify the allocation of slab caches in btrfs_transaction_init Kunwu Chan
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-20  9:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kunwu Chan

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/ordered-data.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 59850dc17b22..f65d681f4c65 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -1236,10 +1236,7 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
 
 int __init ordered_data_init(void)
 {
-	btrfs_ordered_extent_cache = kmem_cache_create("btrfs_ordered_extent",
-				     sizeof(struct btrfs_ordered_extent), 0,
-				     SLAB_MEM_SPREAD,
-				     NULL);
+	btrfs_ordered_extent_cache = KMEM_CACHE(btrfs_ordered_extent, SLAB_MEM_SPREAD);
 	if (!btrfs_ordered_extent_cache)
 		return -ENOMEM;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/6] btrfs: Simplify the allocation of slab caches in btrfs_transaction_init
  2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
  2024-02-20  9:06 ` [PATCH 1/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init Kunwu Chan
  2024-02-20  9:06 ` [PATCH 2/6] btrfs: Simplify the allocation of slab caches in ordered_data_init Kunwu Chan
@ 2024-02-20  9:06 ` Kunwu Chan
  2024-02-20  9:06 ` [PATCH 4/6] btrfs: Simplify the allocation of slab caches in btrfs_ctree_init Kunwu Chan
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-20  9:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kunwu Chan

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/transaction.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 5b3333ceef04..0c069d44e77f 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -2720,9 +2720,8 @@ void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
 
 int __init btrfs_transaction_init(void)
 {
-	btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle",
-			sizeof(struct btrfs_trans_handle), 0,
-			SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL);
+	btrfs_trans_handle_cachep = KMEM_CACHE(btrfs_trans_handle,
+						 SLAB_TEMPORARY | SLAB_MEM_SPREAD);
 	if (!btrfs_trans_handle_cachep)
 		return -ENOMEM;
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/6] btrfs: Simplify the allocation of slab caches in btrfs_ctree_init
  2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
                   ` (2 preceding siblings ...)
  2024-02-20  9:06 ` [PATCH 3/6] btrfs: Simplify the allocation of slab caches in btrfs_transaction_init Kunwu Chan
@ 2024-02-20  9:06 ` Kunwu Chan
  2024-02-20  9:06 ` [PATCH 5/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_ref_init Kunwu Chan
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-20  9:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kunwu Chan

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/ctree.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 33145da449cc..cb9e79eb6140 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -5082,9 +5082,7 @@ int btrfs_previous_extent_item(struct btrfs_root *root,
 
 int __init btrfs_ctree_init(void)
 {
-	btrfs_path_cachep = kmem_cache_create("btrfs_path",
-			sizeof(struct btrfs_path), 0,
-			SLAB_MEM_SPREAD, NULL);
+	btrfs_path_cachep = KMEM_CACHE(btrfs_path, SLAB_MEM_SPREAD);
 	if (!btrfs_path_cachep)
 		return -ENOMEM;
 	return 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_ref_init
  2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
                   ` (3 preceding siblings ...)
  2024-02-20  9:06 ` [PATCH 4/6] btrfs: Simplify the allocation of slab caches in btrfs_ctree_init Kunwu Chan
@ 2024-02-20  9:06 ` Kunwu Chan
  2024-02-20  9:06 ` [PATCH 6/6] btrfs: Simplify the allocation of slab caches in btrfs_free_space_init Kunwu Chan
  2024-02-21 12:00 ` [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-20  9:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kunwu Chan

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-ref.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 891ea2fa263c..4a352e00ffde 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -1242,31 +1242,23 @@ void __cold btrfs_delayed_ref_exit(void)
 
 int __init btrfs_delayed_ref_init(void)
 {
-	btrfs_delayed_ref_head_cachep = kmem_cache_create(
-				"btrfs_delayed_ref_head",
-				sizeof(struct btrfs_delayed_ref_head), 0,
-				SLAB_MEM_SPREAD, NULL);
+	btrfs_delayed_ref_head_cachep = KMEM_CACHE(btrfs_delayed_ref_head,
+				SLAB_MEM_SPREAD);
 	if (!btrfs_delayed_ref_head_cachep)
 		goto fail;
 
-	btrfs_delayed_tree_ref_cachep = kmem_cache_create(
-				"btrfs_delayed_tree_ref",
-				sizeof(struct btrfs_delayed_tree_ref), 0,
-				SLAB_MEM_SPREAD, NULL);
+	btrfs_delayed_tree_ref_cachep = KMEM_CACHE(btrfs_delayed_tree_ref,
+				SLAB_MEM_SPREAD);
 	if (!btrfs_delayed_tree_ref_cachep)
 		goto fail;
 
-	btrfs_delayed_data_ref_cachep = kmem_cache_create(
-				"btrfs_delayed_data_ref",
-				sizeof(struct btrfs_delayed_data_ref), 0,
-				SLAB_MEM_SPREAD, NULL);
+	btrfs_delayed_data_ref_cachep = KMEM_CACHE(btrfs_delayed_data_ref,
+				SLAB_MEM_SPREAD);
 	if (!btrfs_delayed_data_ref_cachep)
 		goto fail;
 
-	btrfs_delayed_extent_op_cachep = kmem_cache_create(
-				"btrfs_delayed_extent_op",
-				sizeof(struct btrfs_delayed_extent_op), 0,
-				SLAB_MEM_SPREAD, NULL);
+	btrfs_delayed_extent_op_cachep = KMEM_CACHE(btrfs_delayed_extent_op,
+				SLAB_MEM_SPREAD);
 	if (!btrfs_delayed_extent_op_cachep)
 		goto fail;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/6] btrfs: Simplify the allocation of slab caches in btrfs_free_space_init
  2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
                   ` (4 preceding siblings ...)
  2024-02-20  9:06 ` [PATCH 5/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_ref_init Kunwu Chan
@ 2024-02-20  9:06 ` Kunwu Chan
  2024-02-21 12:00 ` [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-20  9:06 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Kunwu Chan

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/free-space-cache.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index d372c7ce0e6b..f62f5c339e18 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -4156,9 +4156,7 @@ int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, bool act
 
 int __init btrfs_free_space_init(void)
 {
-	btrfs_free_space_cachep = kmem_cache_create("btrfs_free_space",
-			sizeof(struct btrfs_free_space), 0,
-			SLAB_MEM_SPREAD, NULL);
+	btrfs_free_space_cachep = KMEM_CACHE(btrfs_free_space, SLAB_MEM_SPREAD);
 	if (!btrfs_free_space_cachep)
 		return -ENOMEM;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create
  2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
                   ` (5 preceding siblings ...)
  2024-02-20  9:06 ` [PATCH 6/6] btrfs: Simplify the allocation of slab caches in btrfs_free_space_init Kunwu Chan
@ 2024-02-21 12:00 ` David Sterba
  2024-02-22  3:10   ` Kunwu Chan
  6 siblings, 1 reply; 9+ messages in thread
From: David Sterba @ 2024-02-21 12:00 UTC (permalink / raw)
  To: Kunwu Chan; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel

On Tue, Feb 20, 2024 at 05:06:39PM +0800, Kunwu Chan wrote:
> As David Sterba said in 
> https://lore.kernel.org/all/20240205160408.GI355@twin.jikos.cz/
> I'm using a patchset to cleanup the same issues in the 'brtfs' module.
> 
> For where the cache name and the structure name match.
> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
> to simplify the creation of SLAB caches.
> 
> Kunwu Chan (6):
>   btrfs: Simplify the allocation of slab caches in
>     btrfs_delayed_inode_init
>   btrfs: Simplify the allocation of slab caches in ordered_data_init
>   btrfs: Simplify the allocation of slab caches in
>     btrfs_transaction_init
>   btrfs: Simplify the allocation of slab caches in btrfs_ctree_init
>   btrfs: Simplify the allocation of slab caches in
>     btrfs_delayed_ref_init
>   btrfs: Simplify the allocation of slab caches in btrfs_free_space_init

Added to for-next, thanks. I've edited the changels so the name of the
structure is mentioned rather than the function where it happens, and
did some minor formatting adjustments.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create
  2024-02-21 12:00 ` [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create David Sterba
@ 2024-02-22  3:10   ` Kunwu Chan
  0 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2024-02-22  3:10 UTC (permalink / raw)
  To: dsterba; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel

On 2024/2/21 20:00, David Sterba wrote:
> On Tue, Feb 20, 2024 at 05:06:39PM +0800, Kunwu Chan wrote:
>> As David Sterba said in
>> https://lore.kernel.org/all/20240205160408.GI355@twin.jikos.cz/
>> I'm using a patchset to cleanup the same issues in the 'brtfs' module.
>>
>> For where the cache name and the structure name match.
>> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
>> to simplify the creation of SLAB caches.
>>
>> Kunwu Chan (6):
>>    btrfs: Simplify the allocation of slab caches in
>>      btrfs_delayed_inode_init
>>    btrfs: Simplify the allocation of slab caches in ordered_data_init
>>    btrfs: Simplify the allocation of slab caches in
>>      btrfs_transaction_init
>>    btrfs: Simplify the allocation of slab caches in btrfs_ctree_init
>>    btrfs: Simplify the allocation of slab caches in
>>      btrfs_delayed_ref_init
>>    btrfs: Simplify the allocation of slab caches in btrfs_free_space_init
> 
> Added to for-next, thanks. I've edited the changels so the name of the
> structure is mentioned rather than the function where it happens, and
> did some minor formatting adjustments.
It's ok, thanks for your adjustments.
-- 
Thanks,
   Kunwu


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-02-22  3:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-20  9:06 [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
2024-02-20  9:06 ` [PATCH 1/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init Kunwu Chan
2024-02-20  9:06 ` [PATCH 2/6] btrfs: Simplify the allocation of slab caches in ordered_data_init Kunwu Chan
2024-02-20  9:06 ` [PATCH 3/6] btrfs: Simplify the allocation of slab caches in btrfs_transaction_init Kunwu Chan
2024-02-20  9:06 ` [PATCH 4/6] btrfs: Simplify the allocation of slab caches in btrfs_ctree_init Kunwu Chan
2024-02-20  9:06 ` [PATCH 5/6] btrfs: Simplify the allocation of slab caches in btrfs_delayed_ref_init Kunwu Chan
2024-02-20  9:06 ` [PATCH 6/6] btrfs: Simplify the allocation of slab caches in btrfs_free_space_init Kunwu Chan
2024-02-21 12:00 ` [PATCH 0/6] btrfs: Use KMEM_CACHE instead of kmem_cache_create David Sterba
2024-02-22  3:10   ` Kunwu Chan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox