From: Eric Dumazet <dada1@cosmosbay.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH, resent] [NET] reduce per cpu ram used for loopback stats
Date: Wed, 18 Oct 2006 19:00:03 +0200 [thread overview]
Message-ID: <200610181900.03583.dada1@cosmosbay.com> (raw)
In-Reply-To: <200610181835.48744.dada1@cosmosbay.com>
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
Sorry David, the previous attachment had a missing / in one filename
[NET] reduce per cpu ram used for loopback device stats
We dont need a full struct net_device_stats (currently 23 long : 184 bytes on
x86_64) per possible CPU, but only two counters : bytes and packets
We save few CPU cycles too in loopback_xmit() not updating 4 fields, but 2.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: loopback.patch --]
[-- Type: text/plain, Size: 1894 bytes --]
--- linux/drivers/net/loopback.c 2006-10-18 17:28:20.000000000 +0200
+++ linux-ed/drivers/net/loopback.c 2006-10-18 18:26:41.000000000 +0200
@@ -58,7 +58,11 @@
#include <linux/tcp.h>
#include <linux/percpu.h>
-static DEFINE_PER_CPU(struct net_device_stats, loopback_stats);
+struct pcpu_lstats {
+ unsigned long packets;
+ unsigned long bytes;
+};
+static DEFINE_PER_CPU(struct pcpu_lstats, pcpu_lstats);
#define LOOPBACK_OVERHEAD (128 + MAX_HEADER + 16 + 16)
@@ -128,7 +132,7 @@
*/
static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
{
- struct net_device_stats *lb_stats;
+ struct pcpu_lstats *lb_stats;
skb_orphan(skb);
@@ -149,11 +153,9 @@
#endif
dev->last_rx = jiffies;
- lb_stats = &per_cpu(loopback_stats, get_cpu());
- lb_stats->rx_bytes += skb->len;
- lb_stats->tx_bytes = lb_stats->rx_bytes;
- lb_stats->rx_packets++;
- lb_stats->tx_packets = lb_stats->rx_packets;
+ lb_stats = &per_cpu(pcpu_lstats, get_cpu());
+ lb_stats->bytes += skb->len;
+ lb_stats->packets++;
put_cpu();
netif_rx(skb);
@@ -166,20 +168,21 @@
static struct net_device_stats *get_stats(struct net_device *dev)
{
struct net_device_stats *stats = &loopback_stats;
+ unsigned long bytes = 0;
+ unsigned long packets = 0;
int i;
- memset(stats, 0, sizeof(struct net_device_stats));
-
for_each_possible_cpu(i) {
- struct net_device_stats *lb_stats;
+ const struct pcpu_lstats *lb_stats;
- lb_stats = &per_cpu(loopback_stats, i);
- stats->rx_bytes += lb_stats->rx_bytes;
- stats->tx_bytes += lb_stats->tx_bytes;
- stats->rx_packets += lb_stats->rx_packets;
- stats->tx_packets += lb_stats->tx_packets;
+ lb_stats = &per_cpu(pcpu_lstats, i);
+ bytes += lb_stats->bytes;
+ packets += lb_stats->packets;
}
-
+ stats->rx_packets = packets;
+ stats->tx_packets = packets;
+ stats->rx_bytes = bytes;
+ stats->tx_bytes = bytes;
return stats;
}
next prev parent reply other threads:[~2006-10-18 17:00 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-17 0:53 [PATCH] Bound TSO defer time (resend) John Heffner
2006-10-17 3:20 ` Stephen Hemminger
2006-10-17 4:18 ` John Heffner
2006-10-17 5:35 ` David Miller
2006-10-17 12:22 ` John Heffner
2006-10-19 3:39 ` David Miller
2006-10-17 12:58 ` [PATCH] [NET] Size listen hash tables using backlog hint Eric Dumazet Hi
2006-10-18 7:38 ` [PATCH] [NET] inet_peer : group together avl_left, avl_right, v4daddr to speedup lookups on some CPUS Eric Dumazet
2006-10-18 16:35 ` [PATCH] [NET] reduce per cpu ram used for loopback stats Eric Dumazet
2006-10-18 17:00 ` Eric Dumazet [this message]
2006-10-19 3:53 ` [PATCH, resent] " David Miller
2006-10-19 3:53 ` [PATCH] " David Miller
2006-10-19 3:44 ` [PATCH] [NET] inet_peer : group together avl_left, avl_right, v4daddr to speedup lookups on some CPUS David Miller
2006-10-19 10:57 ` Eric Dumazet
2006-10-19 15:45 ` [PATCH] [NET] One NET_INC_STATS() could be NET_INC_STATS_BH in tcp_v4_err() Eric Dumazet
2006-10-20 7:22 ` David Miller
2006-10-20 14:21 ` Arnaldo Carvalho de Melo
2006-10-20 7:28 ` [PATCH] [NET] inet_peer : group together avl_left, avl_right, v4daddr to speedup lookups on some CPUS David Miller
2006-10-19 3:31 ` [PATCH] [NET] Size listen hash tables using backlog hint David Miller
2006-10-19 4:54 ` Stephen Hemminger
2006-10-19 5:08 ` David Miller
2006-10-19 5:12 ` Eric Dumazet
2006-10-19 6:12 ` David Miller
2006-10-19 6:34 ` Eric Dumazet
2006-10-19 6:57 ` David Miller
2006-10-19 8:29 ` Eric Dumazet
2006-10-19 8:41 ` David Miller
2006-10-19 9:11 ` Eric Dumazet
2006-10-19 9:27 ` Eric Dumazet
2006-10-20 7:27 ` David Miller
2006-10-18 15:37 ` [PATCH] Bound TSO defer time (resend) Andi Kleen
2006-10-18 16:40 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200610181900.03583.dada1@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.