aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2009-11-08 05:17:05 -0500
committerDavid S. Miller <davem@davemloft.net>2009-11-08 23:53:04 -0500
commitfdcc8aa953a1123a289791dd192090651036d593 (patch)
treeb30e27d1ba4d3330e5eb9b7da43d4dfb3a4e42f8
parent415ce61aef5e9b2ed2516a13888c733bea15aedf (diff)
udp: add a counter into udp_hslot
Adds a counter in udp_hslot to keep an accurate count of sockets present in chain. This will permit to upcoming UDP lookup algo to chose the shortest chain when secondary hash is added. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/udp.h8
-rw-r--r--net/ipv4/udp.c3
2 files changed, 11 insertions, 0 deletions
diff --git a/include/net/udp.h b/include/net/udp.h
index 22aa2e7eb1d7..9167281e47dc 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -50,8 +50,16 @@ struct udp_skb_cb {
50}; 50};
51#define UDP_SKB_CB(__skb) ((struct udp_skb_cb *)((__skb)->cb)) 51#define UDP_SKB_CB(__skb) ((struct udp_skb_cb *)((__skb)->cb))
52 52
53/**
54 * struct udp_hslot - UDP hash slot
55 *
56 * @head: head of list of sockets
57 * @count: number of sockets in 'head' list
58 * @lock: spinlock protecting changes to head/count
59 */
53struct udp_hslot { 60struct udp_hslot {
54 struct hlist_nulls_head head; 61 struct hlist_nulls_head head;
62 int count;
55 spinlock_t lock; 63 spinlock_t lock;
56} __attribute__((aligned(2 * sizeof(long)))); 64} __attribute__((aligned(2 * sizeof(long))));
57 65
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index d5e75e976513..ffc837643a04 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -218,6 +218,7 @@ found:
218 sk->sk_hash = snum; 218 sk->sk_hash = snum;
219 if (sk_unhashed(sk)) { 219 if (sk_unhashed(sk)) {
220 sk_nulls_add_node_rcu(sk, &hslot->head); 220 sk_nulls_add_node_rcu(sk, &hslot->head);
221 hslot->count++;
221 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 222 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
222 } 223 }
223 error = 0; 224 error = 0;
@@ -1053,6 +1054,7 @@ void udp_lib_unhash(struct sock *sk)
1053 1054
1054 spin_lock_bh(&hslot->lock); 1055 spin_lock_bh(&hslot->lock);
1055 if (sk_nulls_del_node_init_rcu(sk)) { 1056 if (sk_nulls_del_node_init_rcu(sk)) {
1057 hslot->count--;
1056 inet_sk(sk)->inet_num = 0; 1058 inet_sk(sk)->inet_num = 0;
1057 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 1059 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
1058 } 1060 }
@@ -1862,6 +1864,7 @@ void __init udp_table_init(struct udp_table *table, const char *name)
1862 } 1864 }
1863 for (i = 0; i <= table->mask; i++) { 1865 for (i = 0; i <= table->mask; i++) {
1864 INIT_HLIST_NULLS_HEAD(&table->hash[i].head, i); 1866 INIT_HLIST_NULLS_HEAD(&table->hash[i].head, i);
1867 table->hash[i].count = 0;
1865 spin_lock_init(&table->hash[i].lock); 1868 spin_lock_init(&table->hash[i].lock);
1866 } 1869 }
1867} 1870}