* [PATCH net-next 1/6] net: kcm: Simplify the allocation of slab caches
2024-02-05 7:20 [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
@ 2024-02-05 7:20 ` Kunwu Chan
2024-02-05 7:20 ` [PATCH net-next 2/6] ip6mr: Simplify the allocation of slab caches in ip6_mr_init Kunwu Chan
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Kunwu Chan @ 2024-02-05 7:20 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, jiri
Cc: netdev, linux-kernel, Kunwu Chan
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.
And change cache name from 'kcm_mux_cache' to 'kcm_mux',
'kcm_psock_cache' to 'kcm_psock'.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
net/kcm/kcmsock.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
index 1184d40167b8..bdc3e58a9b2b 100644
--- a/net/kcm/kcmsock.c
+++ b/net/kcm/kcmsock.c
@@ -1877,15 +1877,11 @@ static int __init kcm_init(void)
{
int err = -ENOMEM;
- kcm_muxp = kmem_cache_create("kcm_mux_cache",
- sizeof(struct kcm_mux), 0,
- SLAB_HWCACHE_ALIGN, NULL);
+ kcm_muxp = KMEM_CACHE(kcm_mux, SLAB_HWCACHE_ALIGN);
if (!kcm_muxp)
goto fail;
- kcm_psockp = kmem_cache_create("kcm_psock_cache",
- sizeof(struct kcm_psock), 0,
- SLAB_HWCACHE_ALIGN, NULL);
+ kcm_psockp = KMEM_CACHE(kcm_psock, SLAB_HWCACHE_ALIGN);
if (!kcm_psockp)
goto fail;
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 2/6] ip6mr: Simplify the allocation of slab caches in ip6_mr_init
2024-02-05 7:20 [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
2024-02-05 7:20 ` [PATCH net-next 1/6] net: kcm: Simplify the allocation of slab caches Kunwu Chan
@ 2024-02-05 7:20 ` Kunwu Chan
2024-02-05 7:20 ` [PATCH net-next 3/6] ipmr: Simplify the allocation of slab caches Kunwu Chan
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Kunwu Chan @ 2024-02-05 7:20 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, jiri
Cc: netdev, linux-kernel, Kunwu Chan
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.
And change cache name from 'ip6_mrt_cache' to 'mfc6_cache'.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
net/ipv6/ip6mr.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 9782c180fee6..1f19743f2540 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1373,10 +1373,7 @@ int __init ip6_mr_init(void)
{
int err;
- mrt_cachep = kmem_cache_create("ip6_mrt_cache",
- sizeof(struct mfc6_cache),
- 0, SLAB_HWCACHE_ALIGN,
- NULL);
+ mrt_cachep = KMEM_CACHE(mfc6_cache, SLAB_HWCACHE_ALIGN);
if (!mrt_cachep)
return -ENOMEM;
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 3/6] ipmr: Simplify the allocation of slab caches
2024-02-05 7:20 [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
2024-02-05 7:20 ` [PATCH net-next 1/6] net: kcm: Simplify the allocation of slab caches Kunwu Chan
2024-02-05 7:20 ` [PATCH net-next 2/6] ip6mr: Simplify the allocation of slab caches in ip6_mr_init Kunwu Chan
@ 2024-02-05 7:20 ` Kunwu Chan
2024-02-05 7:20 ` [PATCH net-next 4/6] ipv4: Simplify the allocation of slab caches in ip_rt_init Kunwu Chan
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Kunwu Chan @ 2024-02-05 7:20 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, jiri
Cc: netdev, linux-kernel, Kunwu Chan
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.
And change cache name from 'ip_mrt_cache' to 'mfc_cache'.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
net/ipv4/ipmr.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 9d6f59531b3a..820c95bee6bb 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -3139,10 +3139,7 @@ int __init ip_mr_init(void)
{
int err;
- mrt_cachep = kmem_cache_create("ip_mrt_cache",
- sizeof(struct mfc_cache),
- 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC,
- NULL);
+ mrt_cachep = KMEM_CACHE(mfc_cache, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
err = register_pernet_subsys(&ipmr_net_ops);
if (err)
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 4/6] ipv4: Simplify the allocation of slab caches in ip_rt_init
2024-02-05 7:20 [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
` (2 preceding siblings ...)
2024-02-05 7:20 ` [PATCH net-next 3/6] ipmr: Simplify the allocation of slab caches Kunwu Chan
@ 2024-02-05 7:20 ` Kunwu Chan
2024-02-05 7:20 ` [PATCH net-next 5/6] tcp: Simplify the allocation of slab caches Kunwu Chan
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Kunwu Chan @ 2024-02-05 7:20 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, jiri
Cc: netdev, linux-kernel, Kunwu Chan
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.
And change cache name from 'ip_dst_cache' to 'rtable'.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
net/ipv4/route.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 16615d107cf0..b512288d6fcc 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -3693,9 +3693,8 @@ int __init ip_rt_init(void)
panic("IP: failed to allocate ip_rt_acct\n");
#endif
- ipv4_dst_ops.kmem_cachep =
- kmem_cache_create("ip_dst_cache", sizeof(struct rtable), 0,
- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
+ ipv4_dst_ops.kmem_cachep = KMEM_CACHE(rtable,
+ SLAB_HWCACHE_ALIGN | SLAB_PANIC);
ipv4_dst_blackhole_ops.kmem_cachep = ipv4_dst_ops.kmem_cachep;
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 5/6] tcp: Simplify the allocation of slab caches
2024-02-05 7:20 [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
` (3 preceding siblings ...)
2024-02-05 7:20 ` [PATCH net-next 4/6] ipv4: Simplify the allocation of slab caches in ip_rt_init Kunwu Chan
@ 2024-02-05 7:20 ` Kunwu Chan
2024-02-05 12:29 ` Eric Dumazet
2024-02-05 7:20 ` [PATCH net-next 6/6] ipv6: " Kunwu Chan
2024-02-05 7:37 ` [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Michal Swiatkowski
6 siblings, 1 reply; 10+ messages in thread
From: Kunwu Chan @ 2024-02-05 7:20 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, jiri
Cc: netdev, linux-kernel, Kunwu Chan
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
to simplify the creation of SLAB caches.
And change cache name from 'tcp_bind_bucket' to 'inet_bind_bucket',
'tcp_bind2_bucket' to 'inet_bind2_bucket'.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
net/ipv4/tcp.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index a1c6de385cce..2dc3dd4323c2 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4697,17 +4697,11 @@ void __init tcp_init(void)
thash_entries, 21, /* one slot per 2 MB*/
0, 64 * 1024);
tcp_hashinfo.bind_bucket_cachep =
- kmem_cache_create("tcp_bind_bucket",
- sizeof(struct inet_bind_bucket), 0,
- SLAB_HWCACHE_ALIGN | SLAB_PANIC |
- SLAB_ACCOUNT,
- NULL);
+ KMEM_CACHE(inet_bind_bucket,
+ SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
tcp_hashinfo.bind2_bucket_cachep =
- kmem_cache_create("tcp_bind2_bucket",
- sizeof(struct inet_bind2_bucket), 0,
- SLAB_HWCACHE_ALIGN | SLAB_PANIC |
- SLAB_ACCOUNT,
- NULL);
+ KMEM_CACHE(inet_bind2_bucket,
+ SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
/* Size and allocate the main established and bind bucket
* hash tables.
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next 5/6] tcp: Simplify the allocation of slab caches
2024-02-05 7:20 ` [PATCH net-next 5/6] tcp: Simplify the allocation of slab caches Kunwu Chan
@ 2024-02-05 12:29 ` Eric Dumazet
2024-02-19 9:09 ` Kunwu Chan
0 siblings, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2024-02-05 12:29 UTC (permalink / raw)
To: Kunwu Chan; +Cc: davem, dsahern, kuba, pabeni, jiri, netdev, linux-kernel
On Mon, Feb 5, 2024 at 8:23 AM Kunwu Chan <chentao@kylinos.cn> wrote:
>
> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
> to simplify the creation of SLAB caches.
> And change cache name from 'tcp_bind_bucket' to 'inet_bind_bucket',
> 'tcp_bind2_bucket' to 'inet_bind2_bucket'.
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
> net/ipv4/tcp.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index a1c6de385cce..2dc3dd4323c2 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -4697,17 +4697,11 @@ void __init tcp_init(void)
> thash_entries, 21, /* one slot per 2 MB*/
> 0, 64 * 1024);
> tcp_hashinfo.bind_bucket_cachep =
> - kmem_cache_create("tcp_bind_bucket",
> - sizeof(struct inet_bind_bucket), 0,
> - SLAB_HWCACHE_ALIGN | SLAB_PANIC |
> - SLAB_ACCOUNT,
> - NULL);
> + KMEM_CACHE(inet_bind_bucket,
> + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
I would prefer we do not do this.
dccp is also using a kmem_cache_create() of "struct inet_bind_bucket"
We want different caches for TCP and DCCP.
> tcp_hashinfo.bind2_bucket_cachep =
> - kmem_cache_create("tcp_bind2_bucket",
> - sizeof(struct inet_bind2_bucket), 0,
> - SLAB_HWCACHE_ALIGN | SLAB_PANIC |
> - SLAB_ACCOUNT,
> - NULL);
> + KMEM_CACHE(inet_bind2_bucket,
> + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
Same here.
>
> /* Size and allocate the main established and bind bucket
> * hash tables.
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH net-next 5/6] tcp: Simplify the allocation of slab caches
2024-02-05 12:29 ` Eric Dumazet
@ 2024-02-19 9:09 ` Kunwu Chan
0 siblings, 0 replies; 10+ messages in thread
From: Kunwu Chan @ 2024-02-19 9:09 UTC (permalink / raw)
To: Eric Dumazet; +Cc: davem, dsahern, kuba, pabeni, jiri, netdev, linux-kernel
Thanks for your reply.
On 2024/2/5 20:29, Eric Dumazet wrote:
> On Mon, Feb 5, 2024 at 8:23 AM Kunwu Chan <chentao@kylinos.cn> wrote:
>>
>> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
>> to simplify the creation of SLAB caches.
>> And change cache name from 'tcp_bind_bucket' to 'inet_bind_bucket',
>> 'tcp_bind2_bucket' to 'inet_bind2_bucket'.
>>
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>> ---
>> net/ipv4/tcp.c | 14 ++++----------
>> 1 file changed, 4 insertions(+), 10 deletions(-)
>>
>> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
>> index a1c6de385cce..2dc3dd4323c2 100644
>> --- a/net/ipv4/tcp.c
>> +++ b/net/ipv4/tcp.c
>> @@ -4697,17 +4697,11 @@ void __init tcp_init(void)
>> thash_entries, 21, /* one slot per 2 MB*/
>> 0, 64 * 1024);
>> tcp_hashinfo.bind_bucket_cachep =
>> - kmem_cache_create("tcp_bind_bucket",
>> - sizeof(struct inet_bind_bucket), 0,
>> - SLAB_HWCACHE_ALIGN | SLAB_PANIC |
>> - SLAB_ACCOUNT,
>> - NULL);
>> + KMEM_CACHE(inet_bind_bucket,
>> + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
>
> I would prefer we do not do this.
>
> dccp is also using a kmem_cache_create() of "struct inet_bind_bucket"
When i do my work, i found this too, so i just change the cache name in tcp.
>
> We want different caches for TCP and DCCP.
For distinguishment, I'll delete this patch in next patch series.
>
>
>> tcp_hashinfo.bind2_bucket_cachep =
>> - kmem_cache_create("tcp_bind2_bucket",
>> - sizeof(struct inet_bind2_bucket), 0,
>> - SLAB_HWCACHE_ALIGN | SLAB_PANIC |
>> - SLAB_ACCOUNT,
>> - NULL);
>> + KMEM_CACHE(inet_bind2_bucket,
>> + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
>
> Same here.
>
>>
>> /* Size and allocate the main established and bind bucket
>> * hash tables.
>> --
>> 2.39.2
>>
--
Thanks,
Kunwu
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next 6/6] ipv6: Simplify the allocation of slab caches
2024-02-05 7:20 [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
` (4 preceding siblings ...)
2024-02-05 7:20 ` [PATCH net-next 5/6] tcp: Simplify the allocation of slab caches Kunwu Chan
@ 2024-02-05 7:20 ` Kunwu Chan
2024-02-05 7:37 ` [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Michal Swiatkowski
6 siblings, 0 replies; 10+ messages in thread
From: Kunwu Chan @ 2024-02-05 7:20 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, jiri
Cc: netdev, 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>
---
net/ipv6/ip6_fib.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 4fc2cae0d116..25d7e6d45e6a 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -2444,10 +2444,8 @@ int __init fib6_init(void)
{
int ret = -ENOMEM;
- fib6_node_kmem = kmem_cache_create("fib6_nodes",
- sizeof(struct fib6_node), 0,
- SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT,
- NULL);
+ fib6_node_kmem = KMEM_CACHE(fib6_node,
+ SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT);
if (!fib6_node_kmem)
goto out;
--
2.39.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create
2024-02-05 7:20 [PATCH net-next 0/6] Use KMEM_CACHE instead of kmem_cache_create Kunwu Chan
` (5 preceding siblings ...)
2024-02-05 7:20 ` [PATCH net-next 6/6] ipv6: " Kunwu Chan
@ 2024-02-05 7:37 ` Michal Swiatkowski
6 siblings, 0 replies; 10+ messages in thread
From: Michal Swiatkowski @ 2024-02-05 7:37 UTC (permalink / raw)
To: Kunwu Chan
Cc: davem, dsahern, edumazet, kuba, pabeni, jiri, netdev,
linux-kernel
On Mon, Feb 05, 2024 at 03:20:07PM +0800, Kunwu Chan wrote:
> As Jiri Pirko suggests,
You can add a suggested-by tag.
> I'm using a patchset to cleanup the same issues in the 'net' module.
> Use the new KMEM_CACHE() macro instead of direct kmem_cache_create
> to simplify the creation of SLAB caches.
>
What about rest of the kmem_cache_create in net folder? (ex. fib_trie)
> Some cache names are changed to be the same as struct names.
> This change is recorded in the changelog for easy reference.
> It's harmless cause it's used in /proc/slabinfo to identify this cache.
>
> Kunwu Chan (6):
> net: kcm: Simplify the allocation of slab caches
> ip6mr: Simplify the allocation of slab caches in ip6_mr_init
> ipmr: Simplify the allocation of slab caches
> ipv4: Simplify the allocation of slab caches in ip_rt_init
> tcp: Simplify the allocation of slab caches
> ipv6: Simplify the allocation of slab caches
>
> net/ipv4/ipmr.c | 5 +----
> net/ipv4/route.c | 5 ++---
> net/ipv4/tcp.c | 14 ++++----------
> net/ipv6/ip6_fib.c | 6 ++----
> net/ipv6/ip6mr.c | 5 +----
> net/kcm/kcmsock.c | 8 ++------
> 6 files changed, 12 insertions(+), 31 deletions(-)
>
> --
> 2.39.2
Changes looks fines, thanks
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
for whole series.
Thanks,
Michal
^ permalink raw reply [flat|nested] 10+ messages in thread