Commit 6c648035 authored by Alexander Aring's avatar Alexander Aring Committed by David Teigland

dlm: switch to use rhashtable for rsbs

Replace our own hash table with the more advanced rhashtable
for keeping rsb structs.
Signed-off-by: default avatarAlexander Aring <aahringo@redhat.com>
Signed-off-by: default avatarDavid Teigland <teigland@redhat.com>
parent 93a693d1
...@@ -63,6 +63,14 @@ static void release_node(struct config_item *); ...@@ -63,6 +63,14 @@ static void release_node(struct config_item *);
static struct configfs_attribute *comm_attrs[]; static struct configfs_attribute *comm_attrs[];
static struct configfs_attribute *node_attrs[]; static struct configfs_attribute *node_attrs[];
const struct rhashtable_params dlm_rhash_rsb_params = {
.nelem_hint = 3, /* start small */
.key_len = DLM_RESNAME_MAXLEN,
.key_offset = offsetof(struct dlm_rsb, res_name),
.head_offset = offsetof(struct dlm_rsb, res_node),
.automatic_shrinking = true,
};
struct dlm_cluster { struct dlm_cluster {
struct config_group group; struct config_group group;
unsigned int cl_tcp_port; unsigned int cl_tcp_port;
......
...@@ -21,6 +21,8 @@ struct dlm_config_node { ...@@ -21,6 +21,8 @@ struct dlm_config_node {
uint32_t comm_seq; uint32_t comm_seq;
}; };
extern const struct rhashtable_params dlm_rhash_rsb_params;
#define DLM_MAX_ADDR_COUNT 3 #define DLM_MAX_ADDR_COUNT 3
#define DLM_PROTO_TCP 0 #define DLM_PROTO_TCP 0
......
...@@ -198,14 +198,10 @@ static struct dlm_rsb *find_rsb_root(struct dlm_ls *ls, const char *name, ...@@ -198,14 +198,10 @@ static struct dlm_rsb *find_rsb_root(struct dlm_ls *ls, const char *name,
int len) int len)
{ {
struct dlm_rsb *r; struct dlm_rsb *r;
uint32_t hash, bucket;
int rv; int rv;
hash = jhash(name, len, 0);
bucket = hash & (ls->ls_rsbtbl_size - 1);
spin_lock_bh(&ls->ls_rsbtbl_lock); spin_lock_bh(&ls->ls_rsbtbl_lock);
rv = dlm_search_rsb_tree(&ls->ls_rsbtbl[bucket].r, name, len, &r); rv = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);
spin_unlock_bh(&ls->ls_rsbtbl_lock); spin_unlock_bh(&ls->ls_rsbtbl_lock);
if (!rv) if (!rv)
return r; return r;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/jhash.h> #include <linux/jhash.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/rhashtable.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/ratelimit.h> #include <linux/ratelimit.h>
...@@ -99,15 +100,6 @@ do { \ ...@@ -99,15 +100,6 @@ do { \
} \ } \
} }
#define DLM_RTF_SHRINK_BIT 0
struct dlm_rsbtable {
struct rb_root r;
unsigned long flags;
};
/* /*
* Lockspace member (per node in a ls) * Lockspace member (per node in a ls)
*/ */
...@@ -327,13 +319,12 @@ struct dlm_rsb { ...@@ -327,13 +319,12 @@ struct dlm_rsb {
int res_id; /* for ls_recover_idr */ int res_id; /* for ls_recover_idr */
uint32_t res_lvbseq; uint32_t res_lvbseq;
uint32_t res_hash; uint32_t res_hash;
uint32_t res_bucket; /* rsbtbl */
unsigned long res_toss_time; unsigned long res_toss_time;
uint32_t res_first_lkid; uint32_t res_first_lkid;
struct list_head res_lookup; /* lkbs waiting on first */ struct list_head res_lookup; /* lkbs waiting on first */
union { union {
struct list_head res_hashchain; struct list_head res_hashchain;
struct rb_node res_hashnode; /* rsbtbl */ struct rhash_head res_node; /* rsbtbl */
}; };
struct list_head res_grantqueue; struct list_head res_grantqueue;
struct list_head res_convertqueue; struct list_head res_convertqueue;
...@@ -592,9 +583,10 @@ struct dlm_ls { ...@@ -592,9 +583,10 @@ struct dlm_ls {
struct idr ls_lkbidr; struct idr ls_lkbidr;
spinlock_t ls_lkbidr_spin; spinlock_t ls_lkbidr_spin;
struct dlm_rsbtable *ls_rsbtbl; struct rhashtable ls_rsbtbl;
#define DLM_RTF_SHRINK_BIT 0
unsigned long ls_rsbtbl_flags;
spinlock_t ls_rsbtbl_lock; spinlock_t ls_rsbtbl_lock;
uint32_t ls_rsbtbl_size;
struct list_head ls_toss; struct list_head ls_toss;
struct list_head ls_keep; struct list_head ls_keep;
......
This diff is collapsed.
...@@ -29,7 +29,7 @@ void dlm_unlock_recovery(struct dlm_ls *ls); ...@@ -29,7 +29,7 @@ void dlm_unlock_recovery(struct dlm_ls *ls);
int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name, int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,
int len, unsigned int flags, int *r_nodeid, int *result); int len, unsigned int flags, int *r_nodeid, int *result);
int dlm_search_rsb_tree(struct rb_root *tree, const void *name, int len, int dlm_search_rsb_tree(struct rhashtable *rhash, const void *name, int len,
struct dlm_rsb **r_ret); struct dlm_rsb **r_ret);
void dlm_recover_purge(struct dlm_ls *ls, const struct list_head *root_list); void dlm_recover_purge(struct dlm_ls *ls, const struct list_head *root_list);
......
...@@ -410,9 +410,9 @@ static int new_lockspace(const char *name, const char *cluster, ...@@ -410,9 +410,9 @@ static int new_lockspace(const char *name, const char *cluster,
int *ops_result, dlm_lockspace_t **lockspace) int *ops_result, dlm_lockspace_t **lockspace)
{ {
struct dlm_ls *ls; struct dlm_ls *ls;
int i, size, error;
int do_unreg = 0; int do_unreg = 0;
int namelen = strlen(name); int namelen = strlen(name);
int i, error;
if (namelen > DLM_LOCKSPACE_LEN || namelen == 0) if (namelen > DLM_LOCKSPACE_LEN || namelen == 0)
return -EINVAL; return -EINVAL;
...@@ -498,15 +498,10 @@ static int new_lockspace(const char *name, const char *cluster, ...@@ -498,15 +498,10 @@ static int new_lockspace(const char *name, const char *cluster,
INIT_LIST_HEAD(&ls->ls_toss); INIT_LIST_HEAD(&ls->ls_toss);
INIT_LIST_HEAD(&ls->ls_keep); INIT_LIST_HEAD(&ls->ls_keep);
spin_lock_init(&ls->ls_rsbtbl_lock); spin_lock_init(&ls->ls_rsbtbl_lock);
size = READ_ONCE(dlm_config.ci_rsbtbl_size);
ls->ls_rsbtbl_size = size;
ls->ls_rsbtbl = vmalloc(array_size(size, sizeof(struct dlm_rsbtable))); error = rhashtable_init(&ls->ls_rsbtbl, &dlm_rhash_rsb_params);
if (!ls->ls_rsbtbl) if (error)
goto out_lsfree; goto out_lsfree;
for (i = 0; i < size; i++) {
ls->ls_rsbtbl[i].r.rb_node = NULL;
}
for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) { for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
ls->ls_remove_names[i] = kzalloc(DLM_RESNAME_MAXLEN+1, ls->ls_remove_names[i] = kzalloc(DLM_RESNAME_MAXLEN+1,
...@@ -669,7 +664,7 @@ static int new_lockspace(const char *name, const char *cluster, ...@@ -669,7 +664,7 @@ static int new_lockspace(const char *name, const char *cluster,
out_rsbtbl: out_rsbtbl:
for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++)
kfree(ls->ls_remove_names[i]); kfree(ls->ls_remove_names[i]);
vfree(ls->ls_rsbtbl); rhashtable_destroy(&ls->ls_rsbtbl);
out_lsfree: out_lsfree:
if (do_unreg) if (do_unreg)
kobject_put(&ls->ls_kobj); kobject_put(&ls->ls_kobj);
...@@ -772,10 +767,16 @@ static int lockspace_busy(struct dlm_ls *ls, int force) ...@@ -772,10 +767,16 @@ static int lockspace_busy(struct dlm_ls *ls, int force)
return rv; return rv;
} }
static void rhash_free_rsb(void *ptr, void *arg)
{
struct dlm_rsb *rsb = ptr;
dlm_free_rsb(rsb);
}
static int release_lockspace(struct dlm_ls *ls, int force) static int release_lockspace(struct dlm_ls *ls, int force)
{ {
struct dlm_rsb *rsb; struct dlm_rsb *rsb;
struct rb_node *n;
int i, busy, rv; int i, busy, rv;
busy = lockspace_busy(ls, force); busy = lockspace_busy(ls, force);
...@@ -834,19 +835,9 @@ static int release_lockspace(struct dlm_ls *ls, int force) ...@@ -834,19 +835,9 @@ static int release_lockspace(struct dlm_ls *ls, int force)
idr_destroy(&ls->ls_lkbidr); idr_destroy(&ls->ls_lkbidr);
/* /*
* Free all rsb's on rsbtbl[] lists * Free all rsb's on rsbtbl
*/ */
rhashtable_free_and_destroy(&ls->ls_rsbtbl, rhash_free_rsb, NULL);
for (i = 0; i < ls->ls_rsbtbl_size; i++) {
while ((n = rb_first(&ls->ls_rsbtbl[i].r))) {
rsb = rb_entry(n, struct dlm_rsb, res_hashnode);
list_del(&rsb->res_rsbs_list);
rb_erase(n, &ls->ls_rsbtbl[i].r);
dlm_free_rsb(rsb);
}
}
vfree(ls->ls_rsbtbl);
for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++)
kfree(ls->ls_remove_names[i]); kfree(ls->ls_remove_names[i]);
......
...@@ -887,7 +887,8 @@ void dlm_clear_toss(struct dlm_ls *ls) ...@@ -887,7 +887,8 @@ void dlm_clear_toss(struct dlm_ls *ls)
spin_lock_bh(&ls->ls_rsbtbl_lock); spin_lock_bh(&ls->ls_rsbtbl_lock);
list_for_each_entry_safe(r, safe, &ls->ls_toss, res_rsbs_list) { list_for_each_entry_safe(r, safe, &ls->ls_toss, res_rsbs_list) {
list_del(&r->res_rsbs_list); list_del(&r->res_rsbs_list);
rb_erase(&r->res_hashnode, &ls->ls_rsbtbl[r->res_bucket].r); rhashtable_remove_fast(&ls->ls_rsbtbl, &r->res_node,
dlm_rhash_rsb_params);
dlm_free_rsb(r); dlm_free_rsb(r);
count++; count++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment