aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2011-11-08 08:04:43 -0500
committerDavid S. Miller <davem@davemloft.net>2011-11-09 16:04:20 -0500
commitacb32ba3dee66d58704caeeb8c6ff95f60efdc66 (patch)
treeb5c1d6d5575a7b75c7c816e0809690f58401715c /net
parente56c57d0d3fdbbdf583d3af96bfb803b8dfa713e (diff)
ipv4: reduce percpu needs for icmpmsg mibs
Reading /proc/net/snmp on a machine with a lot of cpus is very expensive (can be ~88000 us). This is because ICMPMSG MIB uses 4096 bytes per cpu, and folding values for all possible cpus can read 16 Mbytes of memory. ICMP messages are not considered as fast path on a typical server, and eventually few cpus handle them anyway. We can afford an atomic operation instead of using percpu data. This saves 4096 bytes per cpu and per network namespace. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/af_inet.c8
-rw-r--r--net/ipv4/proc.c9
2 files changed, 8 insertions, 9 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 1b5096a9875a..b2bbcd0ebd19 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1572,9 +1572,9 @@ static __net_init int ipv4_mib_init_net(struct net *net)
1572 sizeof(struct icmp_mib), 1572 sizeof(struct icmp_mib),
1573 __alignof__(struct icmp_mib)) < 0) 1573 __alignof__(struct icmp_mib)) < 0)
1574 goto err_icmp_mib; 1574 goto err_icmp_mib;
1575 if (snmp_mib_init((void __percpu **)net->mib.icmpmsg_statistics, 1575 net->mib.icmpmsg_statistics = kzalloc(sizeof(struct icmpmsg_mib),
1576 sizeof(struct icmpmsg_mib), 1576 GFP_KERNEL);
1577 __alignof__(struct icmpmsg_mib)) < 0) 1577 if (!net->mib.icmpmsg_statistics)
1578 goto err_icmpmsg_mib; 1578 goto err_icmpmsg_mib;
1579 1579
1580 tcp_mib_init(net); 1580 tcp_mib_init(net);
@@ -1598,7 +1598,7 @@ err_tcp_mib:
1598 1598
1599static __net_exit void ipv4_mib_exit_net(struct net *net) 1599static __net_exit void ipv4_mib_exit_net(struct net *net)
1600{ 1600{
1601 snmp_mib_free((void __percpu **)net->mib.icmpmsg_statistics); 1601 kfree(net->mib.icmpmsg_statistics);
1602 snmp_mib_free((void __percpu **)net->mib.icmp_statistics); 1602 snmp_mib_free((void __percpu **)net->mib.icmp_statistics);
1603 snmp_mib_free((void __percpu **)net->mib.udplite_statistics); 1603 snmp_mib_free((void __percpu **)net->mib.udplite_statistics);
1604 snmp_mib_free((void __percpu **)net->mib.udp_statistics); 1604 snmp_mib_free((void __percpu **)net->mib.udp_statistics);
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index 466ea8bb7a4d..961eed4f510a 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -288,7 +288,7 @@ static void icmpmsg_put(struct seq_file *seq)
288 288
289 count = 0; 289 count = 0;
290 for (i = 0; i < ICMPMSG_MIB_MAX; i++) { 290 for (i = 0; i < ICMPMSG_MIB_MAX; i++) {
291 val = snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, i); 291 val = atomic_long_read(&net->mib.icmpmsg_statistics->mibs[i]);
292 if (val) { 292 if (val) {
293 type[count] = i; 293 type[count] = i;
294 vals[count++] = val; 294 vals[count++] = val;
@@ -307,6 +307,7 @@ static void icmp_put(struct seq_file *seq)
307{ 307{
308 int i; 308 int i;
309 struct net *net = seq->private; 309 struct net *net = seq->private;
310 atomic_long_t *ptr = net->mib.icmpmsg_statistics->mibs;
310 311
311 seq_puts(seq, "\nIcmp: InMsgs InErrors"); 312 seq_puts(seq, "\nIcmp: InMsgs InErrors");
312 for (i=0; icmpmibmap[i].name != NULL; i++) 313 for (i=0; icmpmibmap[i].name != NULL; i++)
@@ -319,15 +320,13 @@ static void icmp_put(struct seq_file *seq)
319 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_INERRORS)); 320 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_INERRORS));
320 for (i=0; icmpmibmap[i].name != NULL; i++) 321 for (i=0; icmpmibmap[i].name != NULL; i++)
321 seq_printf(seq, " %lu", 322 seq_printf(seq, " %lu",
322 snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, 323 atomic_long_read(ptr + icmpmibmap[i].index));
323 icmpmibmap[i].index));
324 seq_printf(seq, " %lu %lu", 324 seq_printf(seq, " %lu %lu",
325 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTMSGS), 325 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTMSGS),
326 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTERRORS)); 326 snmp_fold_field((void __percpu **) net->mib.icmp_statistics, ICMP_MIB_OUTERRORS));
327 for (i=0; icmpmibmap[i].name != NULL; i++) 327 for (i=0; icmpmibmap[i].name != NULL; i++)
328 seq_printf(seq, " %lu", 328 seq_printf(seq, " %lu",
329 snmp_fold_field((void __percpu **) net->mib.icmpmsg_statistics, 329 atomic_long_read(ptr + (icmpmibmap[i].index | 0x100)));
330 icmpmibmap[i].index | 0x100));
331} 330}
332 331
333/* 332/*