[net-next] net: ipv4: Simplify the allocation of slab caches in inet_initpeers

Message ID 20240130092255.73078-1-chentao@kylinos.cn
State New
Headers
Series [net-next] net: ipv4: Simplify the allocation of slab caches in inet_initpeers |

Commit Message

Kunwu Chan Jan. 30, 2024, 9:22 a.m. UTC
  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>
---
 net/ipv4/inetpeer.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
  

Comments

Jiri Pirko Jan. 30, 2024, 10:05 a.m. UTC | #1
Tue, Jan 30, 2024 at 10:22:55AM CET, chentao@kylinos.cn 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
>to simplify the creation of SLAB caches.
>
>Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>---
> net/ipv4/inetpeer.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
>diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
>index e9fed83e9b3c..5bd759963451 100644
>--- a/net/ipv4/inetpeer.c
>+++ b/net/ipv4/inetpeer.c
>@@ -81,10 +81,7 @@ void __init inet_initpeers(void)
> 
> 	inet_peer_threshold = clamp_val(nr_entries, 4096, 65536 + 128);
> 
>-	peer_cachep = kmem_cache_create("inet_peer_cache",
>-			sizeof(struct inet_peer),
>-			0, SLAB_HWCACHE_ALIGN | SLAB_PANIC,
>-			NULL);
>+	peer_cachep = KMEM_CACHE(inet_peer, SLAB_HWCACHE_ALIGN | SLAB_PANIC);

The name is going to be different. Could it be a source of some issue?
My guess is not, just want to make sure.



> }
> 
> /* Called with rcu_read_lock() or base->lock held */
>-- 
>2.39.2
>
>
  
Kunwu Chan Jan. 31, 2024, 7:56 a.m. UTC | #2
Thanks for your reply.

As the code say, the name is only for human beings and to identify a 
cache, so it's ok.

"A string which is used in /proc/slabinfo to identify this cache."
  
Jiri Pirko Jan. 31, 2024, 9:26 a.m. UTC | #3
Tue, Jan 30, 2024 at 10:22:55AM CET, chentao@kylinos.cn 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
>to simplify the creation of SLAB caches.
>
>Signed-off-by: Kunwu Chan <chentao@kylinos.cn>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
  
patchwork-bot+netdevbpf@kernel.org Feb. 1, 2024, 12:50 a.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 30 Jan 2024 17:22:55 +0800 you 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
> to simplify the creation of SLAB caches.
> 
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> 
> [...]

Here is the summary with links:
  - [net-next] net: ipv4: Simplify the allocation of slab caches in inet_initpeers
    https://git.kernel.org/netdev/net-next/c/57f2c6350f2d

You are awesome, thank you!
  

Patch

diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index e9fed83e9b3c..5bd759963451 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -81,10 +81,7 @@  void __init inet_initpeers(void)
 
 	inet_peer_threshold = clamp_val(nr_entries, 4096, 65536 + 128);
 
-	peer_cachep = kmem_cache_create("inet_peer_cache",
-			sizeof(struct inet_peer),
-			0, SLAB_HWCACHE_ALIGN | SLAB_PANIC,
-			NULL);
+	peer_cachep = KMEM_CACHE(inet_peer, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
 }
 
 /* Called with rcu_read_lock() or base->lock held */