History

tcp: handle tcp_net_metrics_init() order-5 memory allocation failures

order-5 allocations can fail with current kernels, we should try vmalloc() as well.

Eric Dumazet committed 14 years ago

Commit 976a7021 parent 6fc4adc1 file · +9 −3Browse files

Unified · Split

net/ipv4/tcp_metrics.c+9−3
@@ -1,7 +1,6 @@
11 #include <linux/rcupdate.h>
22 #include <linux/spinlock.h>
33 #include <linux/jiffies.h>
4−#include <linux/bootmem.h>
54 #include <linux/module.h>
65 #include <linux/cache.h>
76 #include <linux/slab.h>
@@ -9,6 +8,7 @@ · 1 unmodified line
98 #include <linux/tcp.h>
109 #include <linux/hash.h>
1110 #include <linux/tcp_metrics.h>
11+#include <linux/vmalloc.h>
1212
1313 #include <net/inet_connection_sock.h>
1414 #include <net/net_namespace.h>
@@ -1034,7 +1034,10 @@ static int __net_init tcp_net_metrics_init(struct net *net) · 1019 unmodified lines
10341034 net->ipv4.tcp_metrics_hash_log = order_base_2(slots);
10351035 size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log;
10361036
1037− net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL);
1037+ net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
1038+ if (!net->ipv4.tcp_metrics_hash)
1039+ net->ipv4.tcp_metrics_hash = vzalloc(size);
1040+
10381041 if (!net->ipv4.tcp_metrics_hash)
10391042 return -ENOMEM;
10401043
@@ -1055,7 +1058,10 @@ static void __net_exit tcp_net_metrics_exit(struct net *net) · 14 unmodified lines
10551058 tm = next;
10561059 }
10571060 }
1058− kfree(net->ipv4.tcp_metrics_hash);
1061+ if (is_vmalloc_addr(net->ipv4.tcp_metrics_hash))
1062+ vfree(net->ipv4.tcp_metrics_hash);
1063+ else
1064+ kfree(net->ipv4.tcp_metrics_hash);
10591065 }
10601066
10611067 static __net_initdata struct pernet_operations tcp_net_metrics_ops = {