fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / net / core / request_sock.c
index 98f0fc9..5f0818d 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/vmalloc.h>
 
 #include <net/request_sock.h>
 
  * 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.
+ * Note : Dont forget somaxconn that may limit backlog too.
  */
 int sysctl_max_syn_backlog = 256;
 
 int reqsk_queue_alloc(struct request_sock_queue *queue,
-                     const int nr_table_entries)
+                     unsigned int nr_table_entries)
 {
-       const int lopt_size = sizeof(struct listen_sock) +
-                             nr_table_entries * sizeof(struct request_sock *);
-       struct listen_sock *lopt = kmalloc(lopt_size, GFP_KERNEL);
-
+       size_t lopt_size = sizeof(struct listen_sock);
+       struct listen_sock *lopt;
+
+       nr_table_entries = min_t(u32, nr_table_entries, sysctl_max_syn_backlog);
+       nr_table_entries = max_t(u32, nr_table_entries, 8);
+       nr_table_entries = roundup_pow_of_two(nr_table_entries + 1);
+       lopt_size += nr_table_entries * sizeof(struct request_sock *);
+       if (lopt_size > PAGE_SIZE)
+               lopt = __vmalloc(lopt_size,
+                       GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+                       PAGE_KERNEL);
+       else
+               lopt = kzalloc(lopt_size, GFP_KERNEL);
        if (lopt == NULL)
                return -ENOMEM;
 
-       memset(lopt, 0, lopt_size);
-
-       for (lopt->max_qlen_log = 6;
-            (1 << lopt->max_qlen_log) < sysctl_max_syn_backlog;
+       for (lopt->max_qlen_log = 3;
+            (1 << lopt->max_qlen_log) < nr_table_entries;
             lopt->max_qlen_log++);
 
        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_accept_head = NULL;
        lopt->nr_table_entries = nr_table_entries;
 
        write_lock_bh(&queue->syn_wait_lock);
@@ -67,9 +75,11 @@ 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);
+       size_t lopt_size = sizeof(struct listen_sock) +
+               lopt->nr_table_entries * sizeof(struct request_sock *);
 
        if (lopt->qlen != 0) {
-               int i;
+               unsigned int i;
 
                for (i = 0; i < lopt->nr_table_entries; i++) {
                        struct request_sock *req;
@@ -83,7 +93,10 @@ void reqsk_queue_destroy(struct request_sock_queue *queue)
        }
 
        BUG_TRAP(lopt->qlen == 0);
-       kfree(lopt);
+       if (lopt_size > PAGE_SIZE)
+               vfree(lopt);
+       else
+               kfree(lopt);
 }
 
 EXPORT_SYMBOL(reqsk_queue_destroy);