Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 210137
b: refs/heads/master
c: ad1af0f
h: refs/heads/master
i:
  210135: 03c7526
v: v3
  • Loading branch information
David S. Miller committed Aug 25, 2010
1 parent f4878b1 commit 63c7847
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b2bc85631e72485b984bcd202a104591874babba
refs/heads/master: ad1af0fedba14f82b240a03fe20eb9b2fdbd0357
18 changes: 14 additions & 4 deletions trunk/include/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,21 @@ static inline int between(__u32 seq1, __u32 seq2, __u32 seq3)
return seq3 - seq2 >= seq1 - seq2;
}

static inline int tcp_too_many_orphans(struct sock *sk, int num)
static inline bool tcp_too_many_orphans(struct sock *sk, int shift)
{
return (num > sysctl_tcp_max_orphans) ||
(sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2]);
struct percpu_counter *ocp = sk->sk_prot->orphan_count;
int orphans = percpu_counter_read_positive(ocp);

if (orphans << shift > sysctl_tcp_max_orphans) {
orphans = percpu_counter_sum_positive(ocp);
if (orphans << shift > sysctl_tcp_max_orphans)
return true;
}

if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])
return true;
return false;
}

/* syncookies: remember time of last synqueue overflow */
Expand Down
5 changes: 1 addition & 4 deletions trunk/net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2011,11 +2011,8 @@ void tcp_close(struct sock *sk, long timeout)
}
}
if (sk->sk_state != TCP_CLOSE) {
int orphan_count = percpu_counter_read_positive(
sk->sk_prot->orphan_count);

sk_mem_reclaim(sk);
if (tcp_too_many_orphans(sk, orphan_count)) {
if (tcp_too_many_orphans(sk, 0)) {
if (net_ratelimit())
printk(KERN_INFO "TCP: too many of orphaned "
"sockets\n");
Expand Down
8 changes: 4 additions & 4 deletions trunk/net/ipv4/tcp_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ static void tcp_write_err(struct sock *sk)
static int tcp_out_of_resources(struct sock *sk, int do_reset)
{
struct tcp_sock *tp = tcp_sk(sk);
int orphans = percpu_counter_read_positive(&tcp_orphan_count);
int shift = 0;

/* If peer does not open window for long time, or did not transmit
* anything for long time, penalize it. */
if ((s32)(tcp_time_stamp - tp->lsndtime) > 2*TCP_RTO_MAX || !do_reset)
orphans <<= 1;
shift++;

/* If some dubious ICMP arrived, penalize even more. */
if (sk->sk_err_soft)
orphans <<= 1;
shift++;

if (tcp_too_many_orphans(sk, orphans)) {
if (tcp_too_many_orphans(sk, shift)) {
if (net_ratelimit())
printk(KERN_INFO "Out of socket memory\n");

Expand Down

0 comments on commit 63c7847

Please sign in to comment.