diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-10-13 03:28:54 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-10-13 16:05:07 -0400 |
commit | 87fb4b7b533073eeeaed0b6bf7c2328995f6c075 (patch) | |
tree | be4b37f08d7fe2d018ae68bae4577b1b2bafd0fc /net/ipv4 | |
parent | 97ba0eb64ca690165f945a83e609102fcefa99cb (diff) |
net: more accurate skb truesize
skb truesize currently accounts for sk_buff struct and part of skb head.
kmalloc() roundings are also ignored.
Considering that skb_shared_info is larger than sk_buff, its time to
take it into account for better memory accounting.
This patch introduces SKB_TRUESIZE(X) macro to centralize various
assumptions into a single place.
At skb alloc phase, we put skb_shared_info struct at the exact end of
skb head, to allow a better use of memory (lowering number of
reallocations), since kmalloc() gives us power-of-two memory blocks.
Unless SLUB/SLUB debug is active, both skb->head and skb_shared_info are
aligned to cache lines, as before.
Note: This patch might trigger performance regressions because of
misconfigured protocol stacks, hitting per socket or global memory
limits that were previously not reached. But its a necessary step for a
more accurate memory accounting.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
CC: Andi Kleen <ak@linux.intel.com>
CC: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/icmp.c | 5 | ||||
-rw-r--r-- | net/ipv4/tcp_input.c | 14 |
2 files changed, 9 insertions, 10 deletions
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 23ef31baa1af..ab188ae12fd9 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c | |||
@@ -1152,10 +1152,9 @@ static int __net_init icmp_sk_init(struct net *net) | |||
1152 | net->ipv4.icmp_sk[i] = sk; | 1152 | net->ipv4.icmp_sk[i] = sk; |
1153 | 1153 | ||
1154 | /* Enough space for 2 64K ICMP packets, including | 1154 | /* Enough space for 2 64K ICMP packets, including |
1155 | * sk_buff struct overhead. | 1155 | * sk_buff/skb_shared_info struct overhead. |
1156 | */ | 1156 | */ |
1157 | sk->sk_sndbuf = | 1157 | sk->sk_sndbuf = 2 * SKB_TRUESIZE(64 * 1024); |
1158 | (2 * ((64 * 1024) + sizeof(struct sk_buff))); | ||
1159 | 1158 | ||
1160 | /* | 1159 | /* |
1161 | * Speedup sock_wfree() | 1160 | * Speedup sock_wfree() |
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 81cae641c9a9..c1653fe47255 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c | |||
@@ -265,8 +265,7 @@ static inline int TCP_ECN_rcv_ecn_echo(struct tcp_sock *tp, struct tcphdr *th) | |||
265 | 265 | ||
266 | static void tcp_fixup_sndbuf(struct sock *sk) | 266 | static void tcp_fixup_sndbuf(struct sock *sk) |
267 | { | 267 | { |
268 | int sndmem = tcp_sk(sk)->rx_opt.mss_clamp + MAX_TCP_HEADER + 16 + | 268 | int sndmem = SKB_TRUESIZE(tcp_sk(sk)->rx_opt.mss_clamp + MAX_TCP_HEADER); |
269 | sizeof(struct sk_buff); | ||
270 | 269 | ||
271 | if (sk->sk_sndbuf < 3 * sndmem) { | 270 | if (sk->sk_sndbuf < 3 * sndmem) { |
272 | sk->sk_sndbuf = 3 * sndmem; | 271 | sk->sk_sndbuf = 3 * sndmem; |
@@ -349,7 +348,7 @@ static void tcp_grow_window(struct sock *sk, struct sk_buff *skb) | |||
349 | static void tcp_fixup_rcvbuf(struct sock *sk) | 348 | static void tcp_fixup_rcvbuf(struct sock *sk) |
350 | { | 349 | { |
351 | struct tcp_sock *tp = tcp_sk(sk); | 350 | struct tcp_sock *tp = tcp_sk(sk); |
352 | int rcvmem = tp->advmss + MAX_TCP_HEADER + 16 + sizeof(struct sk_buff); | 351 | int rcvmem = SKB_TRUESIZE(tp->advmss + MAX_TCP_HEADER); |
353 | 352 | ||
354 | /* Try to select rcvbuf so that 4 mss-sized segments | 353 | /* Try to select rcvbuf so that 4 mss-sized segments |
355 | * will fit to window and corresponding skbs will fit to our rcvbuf. | 354 | * will fit to window and corresponding skbs will fit to our rcvbuf. |
@@ -540,8 +539,7 @@ void tcp_rcv_space_adjust(struct sock *sk) | |||
540 | space /= tp->advmss; | 539 | space /= tp->advmss; |
541 | if (!space) | 540 | if (!space) |
542 | space = 1; | 541 | space = 1; |
543 | rcvmem = (tp->advmss + MAX_TCP_HEADER + | 542 | rcvmem = SKB_TRUESIZE(tp->advmss + MAX_TCP_HEADER); |
544 | 16 + sizeof(struct sk_buff)); | ||
545 | while (tcp_win_from_space(rcvmem) < tp->advmss) | 543 | while (tcp_win_from_space(rcvmem) < tp->advmss) |
546 | rcvmem += 128; | 544 | rcvmem += 128; |
547 | space *= rcvmem; | 545 | space *= rcvmem; |
@@ -4950,8 +4948,10 @@ static void tcp_new_space(struct sock *sk) | |||
4950 | struct tcp_sock *tp = tcp_sk(sk); | 4948 | struct tcp_sock *tp = tcp_sk(sk); |
4951 | 4949 | ||
4952 | if (tcp_should_expand_sndbuf(sk)) { | 4950 | if (tcp_should_expand_sndbuf(sk)) { |
4953 | int sndmem = max_t(u32, tp->rx_opt.mss_clamp, tp->mss_cache) + | 4951 | int sndmem = SKB_TRUESIZE(max_t(u32, |
4954 | MAX_TCP_HEADER + 16 + sizeof(struct sk_buff); | 4952 | tp->rx_opt.mss_clamp, |
4953 | tp->mss_cache) + | ||
4954 | MAX_TCP_HEADER); | ||
4955 | int demanded = max_t(unsigned int, tp->snd_cwnd, | 4955 | int demanded = max_t(unsigned int, tp->snd_cwnd, |
4956 | tp->reordering + 1); | 4956 | tp->reordering + 1); |
4957 | sndmem *= 2 * demanded; | 4957 | sndmem *= 2 * demanded; |