tcp_metrics: hash table allocation cleanup

After commit 098a697b49 ("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>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20230803135417.2716879-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Eric Dumazet 2023-08-03 13:54:16 +00:00 committed by Jakub Kicinski
parent faa9039161
commit c4a6b2da4b

View File

@ -990,7 +990,7 @@ static struct genl_family tcp_metrics_nl_family __ro_after_init = {
.resv_start_op = TCP_METRICS_CMD_DEL + 1, .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) static int __init set_tcpmhash_entries(char *str)
{ {
ssize_t ret; ssize_t ret;
@ -1006,15 +1006,11 @@ static int __init set_tcpmhash_entries(char *str)
} }
__setup("tcpmhash_entries=", set_tcpmhash_entries); __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; size_t size;
unsigned int slots;
if (!net_eq(net, &init_net))
return 0;
slots = tcpmhash_entries;
if (!slots) { if (!slots) {
if (totalram_pages() >= 128 * 1024) if (totalram_pages() >= 128 * 1024)
slots = 16 * 1024; slots = 16 * 1024;
@ -1027,9 +1023,7 @@ static int __net_init tcp_net_metrics_init(struct net *net)
tcp_metrics_hash = kvzalloc(size, GFP_KERNEL); tcp_metrics_hash = kvzalloc(size, GFP_KERNEL);
if (!tcp_metrics_hash) if (!tcp_metrics_hash)
return -ENOMEM; panic("Could not allocate the tcp_metrics hash table\n");
return 0;
} }
static void __net_exit tcp_net_metrics_exit_batch(struct list_head *net_exit_list) static void __net_exit tcp_net_metrics_exit_batch(struct list_head *net_exit_list)
@ -1038,7 +1032,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 = { static __net_initdata struct pernet_operations tcp_net_metrics_ops = {
.init = tcp_net_metrics_init,
.exit_batch = tcp_net_metrics_exit_batch, .exit_batch = tcp_net_metrics_exit_batch,
}; };
@ -1046,9 +1039,11 @@ void __init tcp_metrics_init(void)
{ {
int ret; int ret;
tcp_metrics_hash_alloc();
ret = register_pernet_subsys(&tcp_net_metrics_ops); ret = register_pernet_subsys(&tcp_net_metrics_ops);
if (ret < 0) 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); ret = genl_register_family(&tcp_metrics_nl_family);
if (ret < 0) if (ret < 0)