X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=net%2Fcore%2Frequest_sock.c;h=b8203de5ff073c4e3bda5166ef1542b793141a0c;hb=0481990b758628e12f4b0a9e15094e70cefc7cd1;hp=1258333ca007bb9abb521f7e2878e16ee32a35ea;hpb=0e87506fcc734647c7b2497eee4eb81e785c857a;p=linux-2.6 diff --git a/net/core/request_sock.c b/net/core/request_sock.c index 1258333ca0..b8203de5ff 100644 --- a/net/core/request_sock.c +++ b/net/core/request_sock.c @@ -18,12 +18,27 @@ #include +/* + * Maximum number of SYN_RECV sockets in queue per LISTEN socket. + * One SYN_RECV socket costs about 80bytes on a 32bit machine. + * It would be better to replace it with a global counter for all sockets + * but then some measure against one socket starving all other sockets + * would be needed. + * + * It was 128 by default. Experiments with real servers show, that + * it is absolutely not enough even at 100conn/sec. 256 cures most + * of problems. This value is adjusted to 128 for very small machines + * (<=32Mb of memory) and to 1024 on normal or better ones (>=256Mb). + * Further increasing requires to change hash table size. + */ +int sysctl_max_syn_backlog = 256; + int reqsk_queue_alloc(struct request_sock_queue *queue, const int nr_table_entries) { - const int lopt_size = sizeof(struct tcp_listen_opt) + + const int lopt_size = sizeof(struct listen_sock) + nr_table_entries * sizeof(struct request_sock *); - struct tcp_listen_opt *lopt = kmalloc(lopt_size, GFP_KERNEL); + struct listen_sock *lopt = kmalloc(lopt_size, GFP_KERNEL); if (lopt == NULL) return -ENOMEM; @@ -37,6 +52,8 @@ int reqsk_queue_alloc(struct request_sock_queue *queue, get_random_bytes(&lopt->hash_rnd, sizeof(lopt->hash_rnd)); rwlock_init(&queue->syn_wait_lock); queue->rskq_accept_head = queue->rskq_accept_head = NULL; + queue->rskq_defer_accept = 0; + lopt->nr_table_entries = nr_table_entries; write_lock_bh(&queue->syn_wait_lock); queue->listen_opt = lopt; @@ -46,3 +63,28 @@ int reqsk_queue_alloc(struct request_sock_queue *queue, } EXPORT_SYMBOL(reqsk_queue_alloc); + +void reqsk_queue_destroy(struct request_sock_queue *queue) +{ + /* make all the listen_opt local to us */ + struct listen_sock *lopt = reqsk_queue_yank_listen_sk(queue); + + if (lopt->qlen != 0) { + int i; + + for (i = 0; i < lopt->nr_table_entries; i++) { + struct request_sock *req; + + while ((req = lopt->syn_table[i]) != NULL) { + lopt->syn_table[i] = req->dl_next; + lopt->qlen--; + reqsk_free(req); + } + } + } + + BUG_TRAP(lopt->qlen == 0); + kfree(lopt); +} + +EXPORT_SYMBOL(reqsk_queue_destroy);