netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fix tcp fin memory accounting
@ 2015-03-19 23:19 Josh Hunt
  2015-03-20  2:17 ` Eric Dumazet
  2015-03-20 17:20 ` David Miller
  0 siblings, 2 replies; 25+ messages in thread
From: Josh Hunt @ 2015-03-19 23:19 UTC (permalink / raw)
  To: davem, netdev; +Cc: edumazet, Josh Hunt

tcp_send_fin() does not account for the memory it allocates properly, so
sk_forward_alloc can be negative in cases where we've sent a FIN:

ss example output (ss -amn | grep -B1 f4294):
tcp    FIN-WAIT-1 0      1            192.168.0.1:45520         192.0.2.1:8080
	skmem:(r0,rb87380,t0,tb87380,f4294966016,w1280,o0,bl0)
--
tcp    FIN-WAIT-1 0      1            192.168.0.1:8080          192.0.2.1:59710
	skmem:(r0,rb87380,t0,tb87380,f4294966016,w1280,o0,bl0)

This can be resolved by using sk_stream_alloc_skb() instead of calling alloc_skb_fclone()
directly. The same fix was made in tcp_connect() in commit 355a901e6cf1 (tcp: make connect() mem charging friendly).

With this fix applied I no longer see the negative sk_forward_alloc values (or
very large values repoted by ss) in my tests.

Signed-off-by: Josh Hunt <johunt@akamai.com>
---
 net/ipv4/tcp_output.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 5a73ad5..c2f0f60 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2820,15 +2820,11 @@ void tcp_send_fin(struct sock *sk)
 	} else {
 		/* Socket is locked, keep trying until memory is available. */
 		for (;;) {
-			skb = alloc_skb_fclone(MAX_TCP_HEADER,
-					       sk->sk_allocation);
+			skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation);
 			if (skb)
 				break;
 			yield();
 		}
-
-		/* Reserve space for headers and prepare control bits. */
-		skb_reserve(skb, MAX_TCP_HEADER);
 		/* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */
 		tcp_init_nondata_skb(skb, tp->write_seq,
 				     TCPHDR_ACK | TCPHDR_FIN);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-04-24 15:07 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-19 23:19 [PATCH] fix tcp fin memory accounting Josh Hunt
2015-03-20  2:17 ` Eric Dumazet
2015-03-20 17:20 ` David Miller
2015-03-20 17:36   ` Josh Hunt
2015-03-24  6:10     ` David Miller
2015-03-24  6:11       ` Josh Hunt
2015-04-22  0:09         ` Eric Dumazet
2015-04-22  1:32           ` [PATCH net] tcp: fix possible deadlock in tcp_send_fin() Eric Dumazet
2015-04-22 14:33             ` [PATCH net] net: do not deplete pfmemalloc reserve Eric Dumazet
2015-04-22 19:35               ` David Miller
2015-04-22 20:20                 ` Eric Dumazet
2015-04-22 20:24                   ` David Miller
2015-04-22 18:15             ` [PATCH net] tcp: fix possible deadlock in tcp_send_fin() David Miller
2015-04-22 18:39               ` Eric Dumazet
2015-04-22 18:50                 ` David Miller
2015-04-22 19:12                   ` Eric Dumazet
2015-04-22 19:29                     ` David Miller
2015-04-23 13:48           ` [PATCH] fix tcp fin memory accounting Josh Hunt
2015-04-23 14:02             ` Eric Dumazet
2015-04-23 15:54               ` David Miller
2015-04-23 16:16                 ` Eric Dumazet
2015-04-23 16:48                   ` Eric Dumazet
2015-04-23 17:12                     ` David Miller
2015-04-23 17:42                       ` [PATCH net] tcp: avoid looping in tcp_send_fin() Eric Dumazet
2015-04-24 15:07                         ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).