]> Pileus Git - ~andy/linux/blobdiff - net/ipv4/udp.c
udp: introduce sk_for_each_rcu_safenext()
[~andy/linux] / net / ipv4 / udp.c
index 0ea974bf7962756035153b0543c1b69a9fc9bed1..c3ecec8a9e1cc93ef702e34225ee540f4d172596 100644 (file)
@@ -81,6 +81,8 @@
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
 #include <linux/bootmem.h>
+#include <linux/highmem.h>
+#include <linux/swap.h>
 #include <linux/types.h>
 #include <linux/fcntl.h>
 #include <linux/module.h>
@@ -254,7 +256,7 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
                int dif, struct udp_table *udptable)
 {
        struct sock *sk, *result;
-       struct hlist_node *node;
+       struct hlist_node *node, *next;
        unsigned short hnum = ntohs(dport);
        unsigned int hash = udp_hashfn(net, hnum);
        struct udp_hslot *hslot = &udptable->hash[hash];
@@ -264,7 +266,7 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
 begin:
        result = NULL;
        badness = -1;
-       sk_for_each_rcu(sk, node, &hslot->head) {
+       sk_for_each_rcu_safenext(sk, node, &hslot->head, next) {
                /*
                 * lockless reader, and SLAB_DESTROY_BY_RCU items:
                 * We must check this item was not moved to another chain
@@ -1577,7 +1579,7 @@ static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
        } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
 
        if (!sk) {
-               spin_unlock(&state->udp_table->hash[state->bucket].lock);
+               spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
                return udp_get_first(seq, state->bucket + 1);
        }
        return sk;
@@ -1751,15 +1753,16 @@ void __init udp_table_init(struct udp_table *table)
 
 void __init udp_init(void)
 {
-       unsigned long limit;
+       unsigned long nr_pages, limit;
 
        udp_table_init(&udp_table);
        /* Set the pressure threshold up by the same strategy of TCP. It is a
         * fraction of global memory that is up to 1/2 at 256 MB, decreasing
         * toward zero with the amount of memory, with a floor of 128 pages.
         */
-       limit = min(nr_all_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
-       limit = (limit * (nr_all_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
+       nr_pages = totalram_pages - totalhigh_pages;
+       limit = min(nr_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
+       limit = (limit * (nr_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
        limit = max(limit, 128UL);
        sysctl_udp_mem[0] = limit / 4 * 3;
        sysctl_udp_mem[1] = limit;