From patchwork Tue Jan 31 18:15:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Sharma X-Patchwork-Id: 138835 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 316591007D1 for ; Wed, 1 Feb 2012 05:36:01 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754146Ab2AaSf7 (ORCPT ); Tue, 31 Jan 2012 13:35:59 -0500 Received: from intmgw001.ash2.facebook.com ([66.220.155.178]:55860 "EHLO intmgw002.ash2.facebook.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753706Ab2AaSf6 (ORCPT ); Tue, 31 Jan 2012 13:35:58 -0500 X-Greylist: delayed 1201 seconds by postgrey-1.27 at vger.kernel.org; Tue, 31 Jan 2012 13:35:58 EST Received: from [10.47.40.131] ([10.47.40.131:62038] helo=facebook.com) by 10.138.200.31 (envelope-from ) (ecelerity 2.2.2.45 r(34222M)) with ESMTP id 9C/6B-03960-DDF282F4; Tue, 31 Jan 2012 10:15:57 -0800 Received: from dev3310.snc6.facebook.com (localhost.localdomain [127.0.0.1]) by dev3310.snc6.facebook.com (Postfix) with ESMTP id B6929161186B; Tue, 31 Jan 2012 10:15:56 -0800 (PST) Received: (from asharma@localhost) by dev3310.snc6.facebook.com (8.13.8/8.13.8/Submit) id q0VIFsa7015767; Tue, 31 Jan 2012 10:15:54 -0800 X-Authentication-Warning: dev3310.snc6.facebook.com: asharma set sender to asharma@fb.com using -f Date: Tue, 31 Jan 2012 10:15:54 -0800 From: Arun Sharma To: Bjorn Helgaas Cc: Arun Sharma , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, David Miller , Glauber Costa , Ingo Molnar , christoph.paasch@uclouvain.be Subject: Re: [PATCH] net: Disambiguate kernel message Message-ID: <20120131181554.GA24397@dev3310.snc6.facebook.com> References: <1327963304-24828-1-git-send-email-asharma@fb.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, Jan 30, 2012 at 08:22:03PM -0800, Bjorn Helgaas wrote: > > We print a different message depending on whether we're out > > of TCP memory or there are too many orphan sockets. > > This patch mentions pairs of messages that are almost the same, but > not quite. If they're supposed to be different, I'd suggest making > them clearly different. As it is, the differences look like careless > mistakes: Good point. Updated patch changes the existing printks to be the same as well. On 1/31/12 12:51 AM, Christoph Paasch wrote: >> --- a/net/ipv4/tcp.c >> +++ b/net/ipv4/tcp.c >> @@ -2015,10 +2015,22 @@ adjudge_to_death: >> } >> if (sk->sk_state != TCP_CLOSE) { >> sk_mem_reclaim(sk); >> - if (tcp_too_many_orphans(sk, 0)) { >> + bool too_many_orphans = tcp_too_many_orphans(sk, 0); >> + bool out_of_socket_memory = tcp_out_of_memory(sk); > > This introduces a compiler warning because you have the declarations > after the code (sk_mem_reclaim()): > Fixed by the patch below. -Arun From 505717e51b15304b0bf50fc9dfed43fd06fad09a Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Mon, 30 Jan 2012 14:16:06 -0800 Subject: [PATCH] net: Disambiguate kernel message Some of our machines were reporting: TCP: too many of orphaned sockets even when the number of orphaned sockets was well below the limit. We print a different message depending on whether we're out of TCP memory or there are too many orphaned sockets. Signed-off-by: Arun Sharma Suggested-by: Mohan Srinivasan Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: David Miller Cc: Glauber Costa Cc: Ingo Molnar --- include/net/tcp.h | 12 ++++++++---- net/ipv4/tcp.c | 17 +++++++++++++++-- net/ipv4/tcp_timer.c | 12 +++++++++--- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 0118ea9..92965dd 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -273,6 +273,14 @@ static inline int between(__u32 seq1, __u32 seq2, __u32 seq3) return seq3 - seq2 >= seq1 - seq2; } +static inline bool tcp_out_of_memory(struct sock *sk) +{ + if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && + sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2)) + return true; + return false; +} + static inline bool tcp_too_many_orphans(struct sock *sk, int shift) { struct percpu_counter *ocp = sk->sk_prot->orphan_count; @@ -283,10 +291,6 @@ static inline bool tcp_too_many_orphans(struct sock *sk, int shift) if (orphans << shift > sysctl_tcp_max_orphans) return true; } - - if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && - sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2)) - return true; return false; } diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 9bcdec3..27de5e4 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2014,11 +2014,24 @@ adjudge_to_death: } } if (sk->sk_state != TCP_CLOSE) { + bool too_many_orphans, out_of_socket_memory; + sk_mem_reclaim(sk); - if (tcp_too_many_orphans(sk, 0)) { + too_many_orphans = tcp_too_many_orphans(sk, 0); + out_of_socket_memory = tcp_out_of_memory(sk); + if (too_many_orphans) { if (net_ratelimit()) - printk(KERN_INFO "TCP: too many of orphaned " + printk(KERN_INFO "TCP: too many orphaned " "sockets\n"); + } + + if (out_of_socket_memory) { + if (net_ratelimit()) + printk(KERN_INFO "TCP: out of memory. " + "Consider tuning tcp_mem\n"); + } + + if (too_many_orphans || out_of_socket_memory) { tcp_set_state(sk, TCP_CLOSE); tcp_send_active_reset(sk, GFP_ATOMIC); NET_INC_STATS_BH(sock_net(sk), diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index a516d1e..0ac006b 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -67,6 +67,7 @@ static int tcp_out_of_resources(struct sock *sk, int do_reset) { struct tcp_sock *tp = tcp_sk(sk); int shift = 0; + bool too_many_orphans, out_of_socket_memory; /* If peer does not open window for long time, or did not transmit * anything for long time, penalize it. */ @@ -77,9 +78,14 @@ static int tcp_out_of_resources(struct sock *sk, int do_reset) if (sk->sk_err_soft) shift++; - if (tcp_too_many_orphans(sk, shift)) { - if (net_ratelimit()) - printk(KERN_INFO "Out of socket memory\n"); + too_many_orphans = tcp_too_many_orphans(sk, shift); + out_of_socket_memory = tcp_out_of_memory(sk); + if (too_many_orphans || out_of_socket_memory) { + if (out_of_socket_memory && net_ratelimit()) + printk(KERN_INFO "TCP: out of memory. " + "Consider tuning tcp_mem\n"); + if (too_many_orphans && net_ratelimit()) + printk(KERN_INFO "TCP: too many orphaned sockets\n"); /* Catch exceptional cases, when connection requires reset. * 1. Last segment was sent recently. */