]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - net/core/request_sock.c
net: Optimize hard_start_xmit() return checking
[linux-2.6.git] / net / core / request_sock.c
index 4e99ce5c08f2c5fe44fbcf94c236a5c35ef51418..7552495aff7aef090d99654312d5365afa421e95 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;
-EXPORT_SYMBOL(sysctl_max_syn_backlog);
 
 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);
@@ -62,15 +69,48 @@ int reqsk_queue_alloc(struct request_sock_queue *queue,
        return 0;
 }
 
-EXPORT_SYMBOL(reqsk_queue_alloc);
+void __reqsk_queue_destroy(struct request_sock_queue *queue)
+{
+       struct listen_sock *lopt;
+       size_t lopt_size;
+
+       /*
+        * this is an error recovery path only
+        * no locking needed and the lopt is not NULL
+        */
+
+       lopt = queue->listen_opt;
+       lopt_size = sizeof(struct listen_sock) +
+               lopt->nr_table_entries * sizeof(struct request_sock *);
+
+       if (lopt_size > PAGE_SIZE)
+               vfree(lopt);
+       else
+               kfree(lopt);
+}
+
+static inline struct listen_sock *reqsk_queue_yank_listen_sk(
+               struct request_sock_queue *queue)
+{
+       struct listen_sock *lopt;
+
+       write_lock_bh(&queue->syn_wait_lock);
+       lopt = queue->listen_opt;
+       queue->listen_opt = NULL;
+       write_unlock_bh(&queue->syn_wait_lock);
+
+       return lopt;
+}
 
 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,8 +123,10 @@ void reqsk_queue_destroy(struct request_sock_queue *queue)
                }
        }
 
-       BUG_TRAP(lopt->qlen == 0);
-       kfree(lopt);
+       WARN_ON(lopt->qlen != 0);
+       if (lopt_size > PAGE_SIZE)
+               vfree(lopt);
+       else
+               kfree(lopt);
 }
 
-EXPORT_SYMBOL(reqsk_queue_destroy);