Skip to content

Commit

Permalink
[IPV4] fib: convert reader/writer to spinlock
Browse files Browse the repository at this point in the history
Ther is no point in using a more expensive reader/writer lock
for a low contention lock like the fib_info_lock. The only
reader case is in handling route redirects.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Stephen Hemminger authored and David S. Miller committed Sep 22, 2006
1 parent b142955 commit 832b4c5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions net/ipv4/fib_semantics.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#define FSprintk(a...)

static DEFINE_RWLOCK(fib_info_lock);
static DEFINE_SPINLOCK(fib_info_lock);
static struct hlist_head *fib_info_hash;
static struct hlist_head *fib_info_laddrhash;
static unsigned int fib_hash_size;
Expand Down Expand Up @@ -159,7 +159,7 @@ void free_fib_info(struct fib_info *fi)

void fib_release_info(struct fib_info *fi)
{
write_lock_bh(&fib_info_lock);
spin_lock_bh(&fib_info_lock);
if (fi && --fi->fib_treeref == 0) {
hlist_del(&fi->fib_hash);
if (fi->fib_prefsrc)
Expand All @@ -172,7 +172,7 @@ void fib_release_info(struct fib_info *fi)
fi->fib_dead = 1;
fib_info_put(fi);
}
write_unlock_bh(&fib_info_lock);
spin_unlock_bh(&fib_info_lock);
}

static __inline__ int nh_comp(const struct fib_info *fi, const struct fib_info *ofi)
Expand Down Expand Up @@ -254,20 +254,20 @@ int ip_fib_check_default(u32 gw, struct net_device *dev)
struct fib_nh *nh;
unsigned int hash;

read_lock(&fib_info_lock);
spin_lock(&fib_info_lock);

hash = fib_devindex_hashfn(dev->ifindex);
head = &fib_info_devhash[hash];
hlist_for_each_entry(nh, node, head, nh_hash) {
if (nh->nh_dev == dev &&
nh->nh_gw == gw &&
!(nh->nh_flags&RTNH_F_DEAD)) {
read_unlock(&fib_info_lock);
spin_unlock(&fib_info_lock);
return 0;
}
}

read_unlock(&fib_info_lock);
spin_unlock(&fib_info_lock);

return -1;
}
Expand Down Expand Up @@ -598,7 +598,7 @@ static void fib_hash_move(struct hlist_head *new_info_hash,
unsigned int old_size = fib_hash_size;
unsigned int i, bytes;

write_lock_bh(&fib_info_lock);
spin_lock_bh(&fib_info_lock);
old_info_hash = fib_info_hash;
old_laddrhash = fib_info_laddrhash;
fib_hash_size = new_size;
Expand Down Expand Up @@ -639,7 +639,7 @@ static void fib_hash_move(struct hlist_head *new_info_hash,
}
fib_info_laddrhash = new_laddrhash;

write_unlock_bh(&fib_info_lock);
spin_unlock_bh(&fib_info_lock);

bytes = old_size * sizeof(struct hlist_head *);
fib_hash_free(old_info_hash, bytes);
Expand Down Expand Up @@ -820,7 +820,7 @@ fib_create_info(const struct rtmsg *r, struct kern_rta *rta,

fi->fib_treeref++;
atomic_inc(&fi->fib_clntref);
write_lock_bh(&fib_info_lock);
spin_lock_bh(&fib_info_lock);
hlist_add_head(&fi->fib_hash,
&fib_info_hash[fib_info_hashfn(fi)]);
if (fi->fib_prefsrc) {
Expand All @@ -839,7 +839,7 @@ fib_create_info(const struct rtmsg *r, struct kern_rta *rta,
head = &fib_info_devhash[hash];
hlist_add_head(&nh->nh_hash, head);
} endfor_nexthops(fi)
write_unlock_bh(&fib_info_lock);
spin_unlock_bh(&fib_info_lock);
return fi;

err_inval:
Expand Down

0 comments on commit 832b4c5

Please sign in to comment.