diff options
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r-- | net/ipv4/tcp.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 06373b4a449a..37755ccc0e96 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -1876,6 +1876,20 @@ void tcp_shutdown(struct sock *sk, int how) | |||
1876 | } | 1876 | } |
1877 | EXPORT_SYMBOL(tcp_shutdown); | 1877 | EXPORT_SYMBOL(tcp_shutdown); |
1878 | 1878 | ||
1879 | bool tcp_check_oom(struct sock *sk, int shift) | ||
1880 | { | ||
1881 | bool too_many_orphans, out_of_socket_memory; | ||
1882 | |||
1883 | too_many_orphans = tcp_too_many_orphans(sk, shift); | ||
1884 | out_of_socket_memory = tcp_out_of_memory(sk); | ||
1885 | |||
1886 | if (too_many_orphans && net_ratelimit()) | ||
1887 | pr_info("TCP: too many orphaned sockets\n"); | ||
1888 | if (out_of_socket_memory && net_ratelimit()) | ||
1889 | pr_info("TCP: out of memory -- consider tuning tcp_mem\n"); | ||
1890 | return too_many_orphans || out_of_socket_memory; | ||
1891 | } | ||
1892 | |||
1879 | void tcp_close(struct sock *sk, long timeout) | 1893 | void tcp_close(struct sock *sk, long timeout) |
1880 | { | 1894 | { |
1881 | struct sk_buff *skb; | 1895 | struct sk_buff *skb; |
@@ -2015,10 +2029,7 @@ adjudge_to_death: | |||
2015 | } | 2029 | } |
2016 | if (sk->sk_state != TCP_CLOSE) { | 2030 | if (sk->sk_state != TCP_CLOSE) { |
2017 | sk_mem_reclaim(sk); | 2031 | sk_mem_reclaim(sk); |
2018 | if (tcp_too_many_orphans(sk, 0)) { | 2032 | if (tcp_check_oom(sk, 0)) { |
2019 | if (net_ratelimit()) | ||
2020 | printk(KERN_INFO "TCP: too many of orphaned " | ||
2021 | "sockets\n"); | ||
2022 | tcp_set_state(sk, TCP_CLOSE); | 2033 | tcp_set_state(sk, TCP_CLOSE); |
2023 | tcp_send_active_reset(sk, GFP_ATOMIC); | 2034 | tcp_send_active_reset(sk, GFP_ATOMIC); |
2024 | NET_INC_STATS_BH(sock_net(sk), | 2035 | NET_INC_STATS_BH(sock_net(sk), |
@@ -3218,7 +3229,6 @@ __setup("thash_entries=", set_thash_entries); | |||
3218 | 3229 | ||
3219 | void tcp_init_mem(struct net *net) | 3230 | void tcp_init_mem(struct net *net) |
3220 | { | 3231 | { |
3221 | /* Set per-socket limits to no more than 1/128 the pressure threshold */ | ||
3222 | unsigned long limit = nr_free_buffer_pages() / 8; | 3232 | unsigned long limit = nr_free_buffer_pages() / 8; |
3223 | limit = max(limit, 128UL); | 3233 | limit = max(limit, 128UL); |
3224 | net->ipv4.sysctl_tcp_mem[0] = limit / 4 * 3; | 3234 | net->ipv4.sysctl_tcp_mem[0] = limit / 4 * 3; |
@@ -3287,7 +3297,8 @@ void __init tcp_init(void) | |||
3287 | sysctl_max_syn_backlog = max(128, cnt / 256); | 3297 | sysctl_max_syn_backlog = max(128, cnt / 256); |
3288 | 3298 | ||
3289 | tcp_init_mem(&init_net); | 3299 | tcp_init_mem(&init_net); |
3290 | limit = nr_free_buffer_pages() / 8; | 3300 | /* Set per-socket limits to no more than 1/128 the pressure threshold */ |
3301 | limit = nr_free_buffer_pages() << (PAGE_SHIFT - 10); | ||
3291 | limit = max(limit, 128UL); | 3302 | limit = max(limit, 128UL); |
3292 | max_share = min(4UL*1024*1024, limit); | 3303 | max_share = min(4UL*1024*1024, limit); |
3293 | 3304 | ||