Skip to content

Commit 15fd7e5

Browse files
Alexander Aringteigland
authored andcommitted
dlm: use rwlock for lkbidr
Convert the lock for lkbidr to an rwlock. Most idr lookups will use the read lock. Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent e913135 commit 15fd7e5

File tree

3 files changed

+11
-41
lines changed

3 files changed

+11
-41
lines changed

fs/dlm/dlm_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ struct dlm_ls {
582582
struct kobject ls_kobj;
583583

584584
struct idr ls_lkbidr;
585-
spinlock_t ls_lkbidr_spin;
585+
rwlock_t ls_lkbidr_lock;
586586

587587
struct rhashtable ls_rsbtbl;
588588
rwlock_t ls_rsbtbl_lock;

fs/dlm/lock.c

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,11 +1522,11 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
15221522
INIT_LIST_HEAD(&lkb->lkb_ownqueue);
15231523
INIT_LIST_HEAD(&lkb->lkb_rsb_lookup);
15241524

1525-
spin_lock_bh(&ls->ls_lkbidr_spin);
1525+
write_lock_bh(&ls->ls_lkbidr_lock);
15261526
rv = idr_alloc(&ls->ls_lkbidr, lkb, start, end, GFP_NOWAIT);
15271527
if (rv >= 0)
15281528
lkb->lkb_id = rv;
1529-
spin_unlock_bh(&ls->ls_lkbidr_spin);
1529+
write_unlock_bh(&ls->ls_lkbidr_lock);
15301530

15311531
if (rv < 0) {
15321532
log_error(ls, "create_lkb idr error %d", rv);
@@ -1547,11 +1547,11 @@ static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)
15471547
{
15481548
struct dlm_lkb *lkb;
15491549

1550-
spin_lock_bh(&ls->ls_lkbidr_spin);
1550+
read_lock_bh(&ls->ls_lkbidr_lock);
15511551
lkb = idr_find(&ls->ls_lkbidr, lkid);
15521552
if (lkb)
15531553
kref_get(&lkb->lkb_ref);
1554-
spin_unlock_bh(&ls->ls_lkbidr_spin);
1554+
read_unlock_bh(&ls->ls_lkbidr_lock);
15551555

15561556
*lkb_ret = lkb;
15571557
return lkb ? 0 : -ENOENT;
@@ -1567,36 +1567,6 @@ static void kill_lkb(struct kref *kref)
15671567
DLM_ASSERT(!lkb->lkb_status, dlm_print_lkb(lkb););
15681568
}
15691569

1570-
/* TODO move this to lib/refcount.c */
1571-
static __must_check bool
1572-
dlm_refcount_dec_and_lock_bh(refcount_t *r, spinlock_t *lock)
1573-
__cond_acquires(lock)
1574-
{
1575-
if (refcount_dec_not_one(r))
1576-
return false;
1577-
1578-
spin_lock_bh(lock);
1579-
if (!refcount_dec_and_test(r)) {
1580-
spin_unlock_bh(lock);
1581-
return false;
1582-
}
1583-
1584-
return true;
1585-
}
1586-
1587-
/* TODO move this to include/linux/kref.h */
1588-
static inline int dlm_kref_put_lock_bh(struct kref *kref,
1589-
void (*release)(struct kref *kref),
1590-
spinlock_t *lock)
1591-
{
1592-
if (dlm_refcount_dec_and_lock_bh(&kref->refcount, lock)) {
1593-
release(kref);
1594-
return 1;
1595-
}
1596-
1597-
return 0;
1598-
}
1599-
16001570
/* __put_lkb() is used when an lkb may not have an rsb attached to
16011571
it so we need to provide the lockspace explicitly */
16021572

@@ -1605,11 +1575,11 @@ static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb)
16051575
uint32_t lkid = lkb->lkb_id;
16061576
int rv;
16071577

1608-
rv = dlm_kref_put_lock_bh(&lkb->lkb_ref, kill_lkb,
1609-
&ls->ls_lkbidr_spin);
1578+
rv = dlm_kref_put_write_lock_bh(&lkb->lkb_ref, kill_lkb,
1579+
&ls->ls_lkbidr_lock);
16101580
if (rv) {
16111581
idr_remove(&ls->ls_lkbidr, lkid);
1612-
spin_unlock_bh(&ls->ls_lkbidr_spin);
1582+
write_unlock_bh(&ls->ls_lkbidr_lock);
16131583

16141584
detach_lkb(lkb);
16151585

fs/dlm/lockspace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static int new_lockspace(const char *name, const char *cluster,
431431
goto out_lsfree;
432432

433433
idr_init(&ls->ls_lkbidr);
434-
spin_lock_init(&ls->ls_lkbidr_spin);
434+
rwlock_init(&ls->ls_lkbidr_lock);
435435

436436
INIT_LIST_HEAD(&ls->ls_waiters);
437437
spin_lock_init(&ls->ls_waiters_lock);
@@ -676,15 +676,15 @@ static int lockspace_busy(struct dlm_ls *ls, int force)
676676
{
677677
int rv;
678678

679-
spin_lock_bh(&ls->ls_lkbidr_spin);
679+
read_lock_bh(&ls->ls_lkbidr_lock);
680680
if (force == 0) {
681681
rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls);
682682
} else if (force == 1) {
683683
rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls);
684684
} else {
685685
rv = 0;
686686
}
687-
spin_unlock_bh(&ls->ls_lkbidr_spin);
687+
read_unlock_bh(&ls->ls_lkbidr_lock);
688688
return rv;
689689
}
690690

0 commit comments

Comments
 (0)