Commit e4fd5da3 authored by Pavel Emelianov's avatar Pavel Emelianov Committed by David S. Miller

[TCP]: Consolidate checking for tcp orphan count being too big.

tcp_out_of_resources() and tcp_close() perform the
same checking of number of orphan sockets. Move this
code into common place.
Signed-off-by: default avatarPavel Emelianov <xemul@openvz.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4e07a91c
...@@ -254,6 +254,12 @@ static inline int between(__u32 seq1, __u32 seq2, __u32 seq3) ...@@ -254,6 +254,12 @@ static inline int between(__u32 seq1, __u32 seq2, __u32 seq3)
return seq3 - seq2 >= seq1 - seq2; return seq3 - seq2 >= seq1 - seq2;
} }
static inline int tcp_too_many_orphans(struct sock *sk, int num)
{
return (num > sysctl_tcp_max_orphans) ||
(sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2]);
}
extern struct proto tcp_prot; extern struct proto tcp_prot;
......
...@@ -1674,9 +1674,8 @@ adjudge_to_death: ...@@ -1674,9 +1674,8 @@ adjudge_to_death:
} }
if (sk->sk_state != TCP_CLOSE) { if (sk->sk_state != TCP_CLOSE) {
sk_stream_mem_reclaim(sk); sk_stream_mem_reclaim(sk);
if (atomic_read(sk->sk_prot->orphan_count) > sysctl_tcp_max_orphans || if (tcp_too_many_orphans(sk,
(sk->sk_wmem_queued > SOCK_MIN_SNDBUF && atomic_read(sk->sk_prot->orphan_count))) {
atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])) {
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_INFO "TCP: too many of orphaned " printk(KERN_INFO "TCP: too many of orphaned "
"sockets\n"); "sockets\n");
......
...@@ -78,9 +78,7 @@ static int tcp_out_of_resources(struct sock *sk, int do_reset) ...@@ -78,9 +78,7 @@ static int tcp_out_of_resources(struct sock *sk, int do_reset)
if (sk->sk_err_soft) if (sk->sk_err_soft)
orphans <<= 1; orphans <<= 1;
if (orphans >= sysctl_tcp_max_orphans || if (tcp_too_many_orphans(sk, orphans)) {
(sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])) {
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_INFO "Out of socket memory\n"); printk(KERN_INFO "Out of socket memory\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment