* [DST]: shrinks sizeof(struct rtable) by 64 bytes on x86_64
@ 2008-01-22 10:50 Eric Dumazet
2008-01-22 14:18 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2008-01-22 10:50 UTC (permalink / raw)
To: David Miller; +Cc: netdev@vger.kernel.org
On x86_64, sizeof(struct rtable) is 0x148, which is rounded up to 0x180
bytes by SLAB allocator.
We can reduce this to exactly 0x140 bytes, without alignment overhead,
and store 12 struct rtable per PAGE instead of 10.
rate_tokens is currently defined as an "unsigned long", while its content
should not exceed 6*HZ. It can safely be converted to an unsigned int.
Moving tclassid right after rate_tokens to fill the 4 bytes hole permits
to save 8 bytes on 'struct dst_entry', which finally permits to save 8
bytes on 'struct rtable'
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
diff --git a/include/net/dst.h b/include/net/dst.h
index c45dcc3..e3ac7d0 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -56,7 +56,11 @@ struct dst_entry
struct dst_entry *path;
unsigned long rate_last; /* rate limiting for ICMP */
- unsigned long rate_tokens;
+ unsigned int rate_tokens;
+
+#ifdef CONFIG_NET_CLS_ROUTE
+ __u32 tclassid;
+#endif
struct neighbour *neighbour;
struct hh_cache *hh;
@@ -65,10 +69,6 @@ struct dst_entry
int (*input)(struct sk_buff*);
int (*output)(struct sk_buff*);
-#ifdef CONFIG_NET_CLS_ROUTE
- __u32 tclassid;
-#endif
-
struct dst_ops *ops;
unsigned long lastuse;
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 7ed8c50..1dbe89c 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -275,18 +275,19 @@ static inline void icmp_xmit_unlock(void)
#define XRLIM_BURST_FACTOR 6
int xrlim_allow(struct dst_entry *dst, int timeout)
{
- unsigned long now;
+ unsigned long now, token = dst->rate_tokens;
int rc = 0;
now = jiffies;
- dst->rate_tokens += now - dst->rate_last;
+ token += now - dst->rate_last;
dst->rate_last = now;
- if (dst->rate_tokens > XRLIM_BURST_FACTOR * timeout)
- dst->rate_tokens = XRLIM_BURST_FACTOR * timeout;
- if (dst->rate_tokens >= timeout) {
- dst->rate_tokens -= timeout;
+ if (token > XRLIM_BURST_FACTOR * timeout)
+ token = XRLIM_BURST_FACTOR * timeout;
+ if (token >= timeout) {
+ token -= timeout;
rc = 1;
}
+ dst->rate_tokens = token;
return rc;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [DST]: shrinks sizeof(struct rtable) by 64 bytes on x86_64
2008-01-22 10:50 [DST]: shrinks sizeof(struct rtable) by 64 bytes on x86_64 Eric Dumazet
@ 2008-01-22 14:18 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2008-01-22 14:18 UTC (permalink / raw)
To: dada1; +Cc: netdev
From: Eric Dumazet <dada1@cosmosbay.com>
Date: Tue, 22 Jan 2008 11:50:06 +0100
> On x86_64, sizeof(struct rtable) is 0x148, which is rounded up to 0x180
> bytes by SLAB allocator.
>
> We can reduce this to exactly 0x140 bytes, without alignment overhead,
> and store 12 struct rtable per PAGE instead of 10.
>
> rate_tokens is currently defined as an "unsigned long", while its content
> should not exceed 6*HZ. It can safely be converted to an unsigned int.
>
> Moving tclassid right after rate_tokens to fill the 4 bytes hole permits
> to save 8 bytes on 'struct dst_entry', which finally permits to save 8
> bytes on 'struct rtable'
>
> Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Thanks for doing this work Eric.
Patch applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-01-22 14:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-22 10:50 [DST]: shrinks sizeof(struct rtable) by 64 bytes on x86_64 Eric Dumazet
2008-01-22 14:18 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox