diff mbox series

[net-next,5/6] tcp: Simplify the allocation of slab caches

Message ID 20240205072013.427639-6-chentao@kylinos.cn (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Use KMEM_CACHE instead of kmem_cache_create | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1050 this patch: 1050
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 1066 this patch: 1066
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1067 this patch: 1067
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-05--12-00 (tests: 721)

Commit Message

Kunwu Chan Feb. 5, 2024, 7:20 a.m. UTC
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(-)

Comments

Eric Dumazet Feb. 5, 2024, 12:29 p.m. UTC | #1
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
>
Kunwu Chan Feb. 19, 2024, 9:09 a.m. UTC | #2
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
>>
diff mbox series

Patch

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.