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

Message ID 20240201084406.202446-1-chentao@kylinos.cn
State New
Headers
Series [v2] btrfs: Simplify the allocation of slab caches in btrfs_delayed_inode_init |

Commit Message

Kunwu Chan Feb. 1, 2024, 8:44 a.m. UTC
  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>
---
Changes in v2:
    - Update commit msg only, no functional changes
---
 fs/btrfs/delayed-inode.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
  

Comments

Markus Elfring Feb. 1, 2024, 1:28 p.m. UTC | #1
> 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.

* Please replace the word “new” by a reference to the commit 8eb8284b412906181357c2b0110d879d5af95e52
  ("usercopy: Prepare for usercopy whitelisting").

  See also related background information from 2017-06-10.

* How does your response fit to the repetition of improvable change descriptions?

  Example:
  [PATCH] btrfs: Simplify the allocation of slab caches in btrfs_transaction_init
  https://lore.kernel.org/lkml/20240201093554.208092-1-chentao@kylinos.cn/
  https://lkml.org/lkml/2024/2/1/387

* Would you like to group similar source code transformations
  into patch series?


Regards,
Markus
  
David Sterba Feb. 5, 2024, 4:04 p.m. UTC | #2
On Thu, Feb 01, 2024 at 04:44:06PM +0800, Kunwu Chan wrote:
> 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>
> ---
> Changes in v2:
>     - Update commit msg only, no functional changes

Please convert all kmem_cache_create calls where the KMEM_CACHE macro is
suitable, ie the cache name and the structure name match.
  
Kunwu Chan Feb. 19, 2024, 9 a.m. UTC | #3
Thanks for your reply.

On 2024/2/6 00:04, David Sterba wrote:
> On Thu, Feb 01, 2024 at 04:44:06PM +0800, Kunwu Chan wrote:
>> 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>
>> ---
>> Changes in v2:
>>      - Update commit msg only, no functional changes
> 
> Please convert all kmem_cache_create calls where the KMEM_CACHE macro is
> suitable, ie the cache name and the structure name match.
I'll do this by a patch series.
  

Patch

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;