首页 > 未分类 > Out of socket memory

Out of socket memory

2007年12月27日 baoz 阅读评论 427 views

这个错误在繁忙的服务器很常见。

我尝试设置sysctl -w net.ipv4.tcp_max_orphans=65536,看是否可以解决,默认的是32768

tcp_orphan_retries –>这个到底设置多少,心里没底。

我们打开linux/net/ipv4/tcp_timer.c,有详细的描述。

/* Do not allow orphaned sockets to eat all our resources.
* This is direct violation of TCP specs, but it is required
* to prevent DoS attacks. It is called when a retransmission timeout
* or zero probe timeout occurs on orphaned socket.
*
* Criteria is still not confirmed experimentally and may change.
* We kill the socket, if:
* 1. If number of orphaned sockets exceeds an administratively configured
*    limit.
* 2. If we have strong memory pressure.
*/
static int tcp_out_of_resources(struct sock *sk, int do_reset)
{
        struct tcp_sock *tp = tcp_sk(sk);
        int orphans = atomic_read(&tcp_orphan_count);

        /* 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;

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

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

                /* Catch exceptional cases, when connection requires reset.
                 *      1. Last segment was sent recently. */
                if ((s32)(tcp_time_stamp – tp->lsndtime) <= TCP_TIMEWAIT_LEN ||
                    /* 2. Window is closed. */
                    (!tp->snd_wnd && !tp->packets_out))
                        do_reset = 1;
                if (do_reset)
                        tcp_send_active_reset(sk, GFP_ATOMIC);
                tcp_done(sk);
                NET_INC_STATS_BH(LINUX_MIB_TCPABORTONMEMORY);
                return 1;
        }

        }
        return 0;
}

看看文档目录。

tcp_max_orphans – INTEGER
        Maximal number of TCP sockets not attached to any user file handle,
        held by system. If this number is exceeded orphaned connections are
        reset immediately and warning is printed. This limit exists
        only to prevent simple DoS attacks, you _must_ not rely on this
        or lower the limit artificially, but rather increase it
        (probably, after increasing installed memory),
        if network conditions require more than default value,
        and tune network services to linger and kill such states
        more aggressively. Let me to remind again: each orphan eats
        up to ~64K of unswappable memory.

tcp_orphan_retries – INTEGER
        How may times to retry before killing TCP connection, closed
        by our side. Default value 7 corresponds to ~50sec-16min
        depending on RTO. If you machine is loaded WEB server,
        you should think about lowering this value, such sockets
        may consume significant resources. Cf. tcp_max_orphans.

包子猜您可能还喜欢下列文章:

  1. 解决Out of socket memory
  2. sysctl参数备份
  3. Enabling High Performance Data Transfers
  4. Prevent detects these and many other defects in C/C++ code

分类: 未分类 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.