llc: convert the socket list to RCU locking

For the reclamation phase we use the SLAB_DESTROY_BY_RCU mechanism,
which require some extra checks in the lookup code:

a) If the current socket was released, reallocated & inserted in
another list it will short circuit the iteration for the current list,
thus we need to restart the lookup.

b) If the current socket was released, reallocated & inserted in the
same list we just need to recheck it matches the look-up criteria and
if not we can skip to the next element.

In this case there is no need to restart the lookup, since sockets are
inserted at the start of the list and the worst that will happen is
that we will iterate throught some of the list elements more then
once.

Note that the /proc and multicast delivery was not yet converted to
RCU, it still uses spinlocks for protection.

Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Octavian Purdila
2009-12-26 11:51:02 +00:00
committed by David S. Miller
parent abf9d537fe
commit b76f5a8427
6 changed files with 120 additions and 68 deletions

View File

@@ -34,19 +34,19 @@ static struct sock *llc_get_sk_idx(loff_t pos)
{
struct list_head *sap_entry;
struct llc_sap *sap;
struct hlist_node *node;
struct hlist_nulls_node *node;
struct sock *sk = NULL;
list_for_each(sap_entry, &llc_sap_list) {
sap = list_entry(sap_entry, struct llc_sap, node);
read_lock_bh(&sap->sk_list.lock);
sk_for_each(sk, node, &sap->sk_list.list) {
spin_lock_bh(&sap->sk_lock);
sk_nulls_for_each(sk, node, &sap->sk_list) {
if (!pos)
goto found;
--pos;
}
read_unlock_bh(&sap->sk_list.lock);
spin_unlock_bh(&sap->sk_lock);
}
sk = NULL;
found:
@@ -73,25 +73,25 @@ static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
goto out;
}
sk = v;
next = sk_next(sk);
next = sk_nulls_next(sk);
if (next) {
sk = next;
goto out;
}
llc = llc_sk(sk);
sap = llc->sap;
read_unlock_bh(&sap->sk_list.lock);
spin_unlock_bh(&sap->sk_lock);
sk = NULL;
for (;;) {
if (sap->node.next == &llc_sap_list)
break;
sap = list_entry(sap->node.next, struct llc_sap, node);
read_lock_bh(&sap->sk_list.lock);
if (!hlist_empty(&sap->sk_list.list)) {
sk = sk_head(&sap->sk_list.list);
spin_lock_bh(&sap->sk_lock);
if (!hlist_nulls_empty(&sap->sk_list)) {
sk = sk_nulls_head(&sap->sk_list);
break;
}
read_unlock_bh(&sap->sk_list.lock);
spin_unlock_bh(&sap->sk_lock);
}
out:
return sk;
@@ -104,7 +104,7 @@ static void llc_seq_stop(struct seq_file *seq, void *v)
struct llc_sock *llc = llc_sk(sk);
struct llc_sap *sap = llc->sap;
read_unlock_bh(&sap->sk_list.lock);
spin_unlock_bh(&sap->sk_lock);
}
read_unlock_bh(&llc_sap_list_lock);
}