From: Alexander Aring <aahringo@redhat.com>
To: teigland@redhat.com
Cc: gfs2@lists.linux.dev, aahringo@redhat.com
Subject: [PATCH v6.10-rc1 08/11] dlm: move lkb idr to xarray datastructure
Date: Tue, 28 May 2024 17:12:38 -0400 [thread overview]
Message-ID: <20240528211241.2140441-8-aahringo@redhat.com> (raw)
In-Reply-To: <20240528211241.2140441-1-aahringo@redhat.com>
According to kernel doc idr is deprecated and xarrays should be used
nowadays. This patch is moving the lkb idr implementation to xarrays.
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
fs/dlm/dlm_internal.h | 5 ++--
fs/dlm/lock.c | 30 ++++++++++++----------
fs/dlm/lockspace.c | 60 +++++++++++++++++++++----------------------
3 files changed, 49 insertions(+), 46 deletions(-)
diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h
index 5acdc6c2b4b8..3a62675bf52e 100644
--- a/fs/dlm/dlm_internal.h
+++ b/fs/dlm/dlm_internal.h
@@ -37,6 +37,7 @@
#include <linux/rhashtable.h>
#include <linux/mutex.h>
#include <linux/idr.h>
+#include <linux/xarray.h>
#include <linux/ratelimit.h>
#include <linux/uaccess.h>
@@ -571,8 +572,8 @@ struct dlm_ls {
unsigned long ls_flags; /* LSFL_ */
struct kobject ls_kobj;
- struct idr ls_lkbidr;
- rwlock_t ls_lkbidr_lock;
+ struct xarray ls_lkbxa;
+ rwlock_t ls_lkbxa_lock;
struct rhashtable ls_rsbtbl;
rwlock_t ls_rsbtbl_lock;
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index 69a25ec82d1e..e176cf48011a 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -1460,11 +1460,15 @@ static void detach_lkb(struct dlm_lkb *lkb)
}
static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
- int start, int end)
+ unsigned long start, unsigned long end)
{
+ struct xa_limit limit;
struct dlm_lkb *lkb;
int rv;
+ limit.max = end;
+ limit.min = start;
+
lkb = dlm_allocate_lkb(ls);
if (!lkb)
return -ENOMEM;
@@ -1478,14 +1482,12 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
INIT_LIST_HEAD(&lkb->lkb_ownqueue);
INIT_LIST_HEAD(&lkb->lkb_rsb_lookup);
- write_lock_bh(&ls->ls_lkbidr_lock);
- rv = idr_alloc(&ls->ls_lkbidr, lkb, start, end, GFP_NOWAIT);
- if (rv >= 0)
- lkb->lkb_id = rv;
- write_unlock_bh(&ls->ls_lkbidr_lock);
+ write_lock_bh(&ls->ls_lkbxa_lock);
+ rv = xa_alloc(&ls->ls_lkbxa, &lkb->lkb_id, lkb, limit, GFP_ATOMIC);
+ write_unlock_bh(&ls->ls_lkbxa_lock);
if (rv < 0) {
- log_error(ls, "create_lkb idr error %d", rv);
+ log_error(ls, "create_lkb xa error %d", rv);
dlm_free_lkb(lkb);
return rv;
}
@@ -1496,18 +1498,18 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret)
{
- return _create_lkb(ls, lkb_ret, 1, 0);
+ return _create_lkb(ls, lkb_ret, 1, ULONG_MAX);
}
static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)
{
struct dlm_lkb *lkb;
- read_lock_bh(&ls->ls_lkbidr_lock);
- lkb = idr_find(&ls->ls_lkbidr, lkid);
+ read_lock_bh(&ls->ls_lkbxa_lock);
+ lkb = xa_load(&ls->ls_lkbxa, lkid);
if (lkb)
kref_get(&lkb->lkb_ref);
- read_unlock_bh(&ls->ls_lkbidr_lock);
+ read_unlock_bh(&ls->ls_lkbxa_lock);
*lkb_ret = lkb;
return lkb ? 0 : -ENOENT;
@@ -1532,10 +1534,10 @@ static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb)
int rv;
rv = dlm_kref_put_write_lock_bh(&lkb->lkb_ref, kill_lkb,
- &ls->ls_lkbidr_lock);
+ &ls->ls_lkbxa_lock);
if (rv) {
- idr_remove(&ls->ls_lkbidr, lkid);
- write_unlock_bh(&ls->ls_lkbidr_lock);
+ xa_erase(&ls->ls_lkbxa, lkid);
+ write_unlock_bh(&ls->ls_lkbxa_lock);
detach_lkb(lkb);
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index ecb9b5fcad8e..a1aefe804727 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -420,8 +420,8 @@ static int new_lockspace(const char *name, const char *cluster,
if (error)
goto out_lsfree;
- idr_init(&ls->ls_lkbidr);
- rwlock_init(&ls->ls_lkbidr_lock);
+ xa_init_flags(&ls->ls_lkbxa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_BH);
+ rwlock_init(&ls->ls_lkbxa_lock);
INIT_LIST_HEAD(&ls->ls_waiters);
spin_lock_init(&ls->ls_waiters_lock);
@@ -471,7 +471,7 @@ static int new_lockspace(const char *name, const char *cluster,
ls->ls_recover_buf = kmalloc(DLM_MAX_SOCKET_BUFSIZE, GFP_NOFS);
if (!ls->ls_recover_buf) {
error = -ENOMEM;
- goto out_lkbidr;
+ goto out_lkbxa;
}
ls->ls_slot = 0;
@@ -572,8 +572,8 @@ static int new_lockspace(const char *name, const char *cluster,
spin_unlock_bh(&lslist_lock);
idr_destroy(&ls->ls_recover_idr);
kfree(ls->ls_recover_buf);
- out_lkbidr:
- idr_destroy(&ls->ls_lkbidr);
+ out_lkbxa:
+ xa_destroy(&ls->ls_lkbxa);
rhashtable_destroy(&ls->ls_rsbtbl);
out_lsfree:
if (do_unreg)
@@ -633,22 +633,8 @@ int dlm_new_user_lockspace(const char *name, const char *cluster,
ops_arg, ops_result, lockspace);
}
-static int lkb_idr_is_local(int id, void *p, void *data)
+static int lkb_idr_free(struct dlm_lkb *lkb)
{
- struct dlm_lkb *lkb = p;
-
- return lkb->lkb_nodeid == 0 && lkb->lkb_grmode != DLM_LOCK_IV;
-}
-
-static int lkb_idr_is_any(int id, void *p, void *data)
-{
- return 1;
-}
-
-static int lkb_idr_free(int id, void *p, void *data)
-{
- struct dlm_lkb *lkb = p;
-
if (lkb->lkb_lvbptr && test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags))
dlm_free_lvb(lkb->lkb_lvbptr);
@@ -656,23 +642,34 @@ static int lkb_idr_free(int id, void *p, void *data)
return 0;
}
-/* NOTE: We check the lkbidr here rather than the resource table.
+/* NOTE: We check the lkbxa here rather than the resource table.
This is because there may be LKBs queued as ASTs that have been unlinked
from their RSBs and are pending deletion once the AST has been delivered */
static int lockspace_busy(struct dlm_ls *ls, int force)
{
- int rv;
+ struct dlm_lkb *lkb;
+ unsigned long id;
+ int rv = 0;
- read_lock_bh(&ls->ls_lkbidr_lock);
+ read_lock_bh(&ls->ls_lkbxa_lock);
if (force == 0) {
- rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls);
+ xa_for_each(&ls->ls_lkbxa, id, lkb) {
+ rv = 1;
+ break;
+ }
} else if (force == 1) {
- rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls);
+ xa_for_each(&ls->ls_lkbxa, id, lkb) {
+ if (lkb->lkb_nodeid == 0 &&
+ lkb->lkb_grmode != DLM_LOCK_IV) {
+ rv = 1;
+ break;
+ }
+ }
} else {
rv = 0;
}
- read_unlock_bh(&ls->ls_lkbidr_lock);
+ read_unlock_bh(&ls->ls_lkbxa_lock);
return rv;
}
@@ -685,6 +682,8 @@ static void rhash_free_rsb(void *ptr, void *arg)
static int release_lockspace(struct dlm_ls *ls, int force)
{
+ struct dlm_lkb *lkb;
+ unsigned long id;
int busy, rv;
busy = lockspace_busy(ls, force);
@@ -741,11 +740,12 @@ static int release_lockspace(struct dlm_ls *ls, int force)
kfree(ls->ls_recover_buf);
/*
- * Free all lkb's in idr
+ * Free all lkb's in xa
*/
-
- idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls);
- idr_destroy(&ls->ls_lkbidr);
+ xa_for_each(&ls->ls_lkbxa, id, lkb) {
+ lkb_idr_free(lkb);
+ }
+ xa_destroy(&ls->ls_lkbxa);
/*
* Free all rsb's on rsbtbl
--
2.43.0
next prev parent reply other threads:[~2024-05-28 21:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 21:12 [PATCH v6.10-rc1 01/11] dlm: remove scand leftovers Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 02/11] dlm: don't kref_init rsbs created for toss list Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 03/11] dlm: remove unused parameter in dlm_midcomms_addr Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 04/11] dlm: remove ls_local_handle from struct dlm_ls Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 05/11] dlm: rename dlm_find_lockspace_local to dlm_get_lockspace Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 06/11] dlm: drop own rsb pre allocation mechanism Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 07/11] dlm: using rcu to avoid rsb lookup again Alexander Aring
2024-05-28 21:12 ` Alexander Aring [this message]
2024-05-28 21:12 ` [PATCH v6.10-rc1 09/11] dlm: move recover idr to xarray datastructure Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 10/11] dlm: merge nodeid field to master_nodeid Alexander Aring
2024-05-28 21:12 ` [PATCH v6.10-rc1 11/11] dlm: use is_master() where it's prossible Alexander Aring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240528211241.2140441-8-aahringo@redhat.com \
--to=aahringo@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=teigland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox