* [PATCH net-next] tcp_metrics: hash table allocation cleanup
@ 2023-08-03 13:54 Eric Dumazet
2023-08-03 20:17 ` Simon Horman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2023-08-03 13:54 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, netdev, eric.dumazet, Eric Dumazet
After commit 098a697b497e ("tcp_metrics: Use a single hash table
for all network namespaces.") we can avoid calling tcp_net_metrics_init()
for each new netns.
Instead, rename tcp_net_metrics_init() to tcp_metrics_hash_alloc(),
and move it to __init section.
Also move tcpmhash_entries to __initdata section.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv4/tcp_metrics.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index 82f4575f9cd90049a5ad4c7329ad1ddc28fc1aa0..96ab455063c57fd04c8d754ee623929d009ee716 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -972,7 +972,7 @@ static struct genl_family tcp_metrics_nl_family __ro_after_init = {
.resv_start_op = TCP_METRICS_CMD_DEL + 1,
};
-static unsigned int tcpmhash_entries;
+static unsigned int tcpmhash_entries __initdata;
static int __init set_tcpmhash_entries(char *str)
{
ssize_t ret;
@@ -988,15 +988,11 @@ static int __init set_tcpmhash_entries(char *str)
}
__setup("tcpmhash_entries=", set_tcpmhash_entries);
-static int __net_init tcp_net_metrics_init(struct net *net)
+static void __init tcp_metrics_hash_alloc(void)
{
+ unsigned int slots = tcpmhash_entries;
size_t size;
- unsigned int slots;
- if (!net_eq(net, &init_net))
- return 0;
-
- slots = tcpmhash_entries;
if (!slots) {
if (totalram_pages() >= 128 * 1024)
slots = 16 * 1024;
@@ -1009,9 +1005,7 @@ static int __net_init tcp_net_metrics_init(struct net *net)
tcp_metrics_hash = kvzalloc(size, GFP_KERNEL);
if (!tcp_metrics_hash)
- return -ENOMEM;
-
- return 0;
+ panic("Could not allocate the tcp_metrics hash table\n");
}
static void __net_exit tcp_net_metrics_exit_batch(struct list_head *net_exit_list)
@@ -1020,7 +1014,6 @@ static void __net_exit tcp_net_metrics_exit_batch(struct list_head *net_exit_lis
}
static __net_initdata struct pernet_operations tcp_net_metrics_ops = {
- .init = tcp_net_metrics_init,
.exit_batch = tcp_net_metrics_exit_batch,
};
@@ -1028,9 +1021,11 @@ void __init tcp_metrics_init(void)
{
int ret;
+ tcp_metrics_hash_alloc();
+
ret = register_pernet_subsys(&tcp_net_metrics_ops);
if (ret < 0)
- panic("Could not allocate the tcp_metrics hash table\n");
+ panic("Could not register tcp_net_metrics_ops\n");
ret = genl_register_family(&tcp_metrics_nl_family);
if (ret < 0)
--
2.41.0.640.ga95def55d0-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] tcp_metrics: hash table allocation cleanup
2023-08-03 13:54 [PATCH net-next] tcp_metrics: hash table allocation cleanup Eric Dumazet
@ 2023-08-03 20:17 ` Simon Horman
2023-08-03 22:50 ` Kuniyuki Iwashima
2023-08-04 22:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2023-08-03 20:17 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Kuniyuki Iwashima,
netdev, eric.dumazet
On Thu, Aug 03, 2023 at 01:54:16PM +0000, Eric Dumazet wrote:
> After commit 098a697b497e ("tcp_metrics: Use a single hash table
> for all network namespaces.") we can avoid calling tcp_net_metrics_init()
> for each new netns.
>
> Instead, rename tcp_net_metrics_init() to tcp_metrics_hash_alloc(),
> and move it to __init section.
>
> Also move tcpmhash_entries to __initdata section.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] tcp_metrics: hash table allocation cleanup
2023-08-03 13:54 [PATCH net-next] tcp_metrics: hash table allocation cleanup Eric Dumazet
2023-08-03 20:17 ` Simon Horman
@ 2023-08-03 22:50 ` Kuniyuki Iwashima
2023-08-04 22:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2023-08-03 22:50 UTC (permalink / raw)
To: edumazet; +Cc: davem, eric.dumazet, kuba, kuniyu, netdev, pabeni
From: Eric Dumazet <edumazet@google.com>
Date: Thu, 3 Aug 2023 13:54:16 +0000
> After commit 098a697b497e ("tcp_metrics: Use a single hash table
> for all network namespaces.") we can avoid calling tcp_net_metrics_init()
> for each new netns.
>
> Instead, rename tcp_net_metrics_init() to tcp_metrics_hash_alloc(),
> and move it to __init section.
>
> Also move tcpmhash_entries to __initdata section.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> net/ipv4/tcp_metrics.c | 19 +++++++------------
> 1 file changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
> index 82f4575f9cd90049a5ad4c7329ad1ddc28fc1aa0..96ab455063c57fd04c8d754ee623929d009ee716 100644
> --- a/net/ipv4/tcp_metrics.c
> +++ b/net/ipv4/tcp_metrics.c
> @@ -972,7 +972,7 @@ static struct genl_family tcp_metrics_nl_family __ro_after_init = {
> .resv_start_op = TCP_METRICS_CMD_DEL + 1,
> };
>
> -static unsigned int tcpmhash_entries;
> +static unsigned int tcpmhash_entries __initdata;
> static int __init set_tcpmhash_entries(char *str)
> {
> ssize_t ret;
> @@ -988,15 +988,11 @@ static int __init set_tcpmhash_entries(char *str)
> }
> __setup("tcpmhash_entries=", set_tcpmhash_entries);
>
> -static int __net_init tcp_net_metrics_init(struct net *net)
> +static void __init tcp_metrics_hash_alloc(void)
> {
> + unsigned int slots = tcpmhash_entries;
> size_t size;
> - unsigned int slots;
>
> - if (!net_eq(net, &init_net))
> - return 0;
> -
> - slots = tcpmhash_entries;
> if (!slots) {
> if (totalram_pages() >= 128 * 1024)
> slots = 16 * 1024;
> @@ -1009,9 +1005,7 @@ static int __net_init tcp_net_metrics_init(struct net *net)
>
> tcp_metrics_hash = kvzalloc(size, GFP_KERNEL);
> if (!tcp_metrics_hash)
> - return -ENOMEM;
> -
> - return 0;
> + panic("Could not allocate the tcp_metrics hash table\n");
> }
>
> static void __net_exit tcp_net_metrics_exit_batch(struct list_head *net_exit_list)
> @@ -1020,7 +1014,6 @@ static void __net_exit tcp_net_metrics_exit_batch(struct list_head *net_exit_lis
> }
>
> static __net_initdata struct pernet_operations tcp_net_metrics_ops = {
> - .init = tcp_net_metrics_init,
> .exit_batch = tcp_net_metrics_exit_batch,
> };
>
> @@ -1028,9 +1021,11 @@ void __init tcp_metrics_init(void)
> {
> int ret;
>
> + tcp_metrics_hash_alloc();
> +
> ret = register_pernet_subsys(&tcp_net_metrics_ops);
> if (ret < 0)
> - panic("Could not allocate the tcp_metrics hash table\n");
> + panic("Could not register tcp_net_metrics_ops\n");
>
> ret = genl_register_family(&tcp_metrics_nl_family);
> if (ret < 0)
> --
> 2.41.0.640.ga95def55d0-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] tcp_metrics: hash table allocation cleanup
2023-08-03 13:54 [PATCH net-next] tcp_metrics: hash table allocation cleanup Eric Dumazet
2023-08-03 20:17 ` Simon Horman
2023-08-03 22:50 ` Kuniyuki Iwashima
@ 2023-08-04 22:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-04 22:40 UTC (permalink / raw)
To: Eric Dumazet; +Cc: davem, kuba, pabeni, kuniyu, netdev, eric.dumazet
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 3 Aug 2023 13:54:16 +0000 you wrote:
> After commit 098a697b497e ("tcp_metrics: Use a single hash table
> for all network namespaces.") we can avoid calling tcp_net_metrics_init()
> for each new netns.
>
> Instead, rename tcp_net_metrics_init() to tcp_metrics_hash_alloc(),
> and move it to __init section.
>
> [...]
Here is the summary with links:
- [net-next] tcp_metrics: hash table allocation cleanup
https://git.kernel.org/netdev/net-next/c/c4a6b2da4b59
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-04 22:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-03 13:54 [PATCH net-next] tcp_metrics: hash table allocation cleanup Eric Dumazet
2023-08-03 20:17 ` Simon Horman
2023-08-03 22:50 ` Kuniyuki Iwashima
2023-08-04 22:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).