dlm: improve rsb searches
David Teigland
maintainerPATCH 7/10 dlm: improve rsb searches
By pre-allocating rsb structs before searching the hash table, they can be inserted immediately. This avoids always having to repeat the search when adding the struct to hash list.
This also adds space to the rsb struct for a max resource name, so an rsb allocation can be used by any request. The constant size also allows us to finally use a slab for the rsb structs.
Signed-off-by David Teigland <[email protected]>
--- fs/dlm/config.c | 9 +++- fs/dlm/config.h | 1 + fs/dlm/dlm_internal.h | 6 ++- fs/dlm/lock.c | 119 +++++++++++++++++++++++++++++++++--------------- fs/dlm/lockspace.c | 10 ++++ fs/dlm/memory.c | 22 ++++++--- fs/dlm/memory.h | 2 +- 7 files changed, 121 insertions(+), 48 deletions(-)
fs/dlm/config.c +8 -1
@@ -102,6 +102,7 @@ struct dlm_cluster {unsigned int cl_protocol;unsigned int cl_timewarn_cs;unsigned int cl_waitwarn_us; +unsigned int cl_new_rsb_count; };enum {
@@ -116,6 +117,7 @@ enum {CLUSTER_ATTR_PROTOCOL ,CLUSTER_ATTR_TIMEWARN_CS ,CLUSTER_ATTR_WAITWARN_US , + CLUSTER_ATTR_NEW_RSB_COUNT, }; struct cluster_attribute {
@@ -168,6 +170,7 @@ CLUSTER_ATTR(log_debug, 0);CLUSTER_ATTR (protocol,0 );CLUSTER_ATTR (timewarn_cs,1 );CLUSTER_ATTR (waitwarn_us,0 ); +CLUSTER_ATTR (new_rsb_count,0 );static struct configfs_attribute *cluster_attrs[] = { [CLUSTER_ATTR_TCP_PORT ] = &cluster_attr_tcp_port.attr,
@@ -181,6 +184,7 @@ static struct configfs_attribute *cluster_attrs[] = { [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr, [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr, [CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us.attr, + [CLUSTER_ATTR_NEW_RSB_COUNT ] = &cluster_attr_new_rsb_count.attr, NULL, };
@@ -450,6 +454,7 @@ static struct config_group *make_cluster(struct config_group *g, cl->cl_protocol = dlm_config.ci_protocol; cl->cl_timewarn_cs = dlm_config.ci_timewarn_cs; cl->cl_waitwarn_us = dlm_config.ci_waitwarn_us; + cl->cl_new_rsb_count = dlm_config.ci_new_rsb_count; space_list = &sps->ss_group; comm_list = &cms->cs_group;
@@ -1041,6 +1046,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)#define DEFAULT_PROTOCOL 0#define DEFAULT_TIMEWARN_CS 500/* 5 sec = 500 centiseconds */ #define DEFAULT_WAITWARN_US 0 +#define DEFAULT_NEW_RSB_COUNT 128struct dlm_config_info dlm_config = { .ci_tcp_port =DEFAULT_TCP_PORT ,
@@ -1053,6 +1059,7 @@ struct dlm_config_info dlm_config = { .ci_log_debug = DEFAULT_LOG_DEBUG, .ci_protocol = DEFAULT_PROTOCOL, .ci_timewarn_cs = DEFAULT_TIMEWARN_CS, - .ci_waitwarn_us = DEFAULT_WAITWARN_US + .ci_waitwarn_us = DEFAULT_WAITWARN_US, + .ci_new_rsb_count = DEFAULT_NEW_RSB_COUNT };
fs/dlm/config.h +1 -0
@@ -28,6 +28,7 @@ struct dlm_config_info {int ci_protocol;int ci_timewarn_cs;int ci_waitwarn_us; +int ci_new_rsb_count; };extern struct dlm_config_info dlm_config;
fs/dlm/dlm_internal.h +5 -1
@@ -293,7 +293,7 @@ struct dlm_rsb {int res_recover_locks_count;char *res_lvbptr; -char res_name[1 ]; +char res_name[DLM_RESNAME_MAXLEN +1 ]; };/* find_rsb() flags */
@@ -477,6 +477,10 @@ struct dlm_ls {struct mutex ls_timeout_mutex;struct list_head ls_timeout; +spinlock_t ls_new_rsb_spin; +int ls_new_rsb_count; +struct list_head ls_new_rsb;/* new rsb structs */ +struct list_head ls_nodes;/* current nodes in ls */ struct list_head ls_nodes_gone;/* dead node list, recovery */ int ls_num_nodes;/* number of nodes in ls */
fs/dlm/lock.c +82 -37
177 lines not on this page · raw message
fs/dlm/lockspace.c +10 -0
@@ -493,6 +493,9 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,INIT_LIST_HEAD (&ls->ls_timeout);mutex_init (&ls->ls_timeout_mutex); +INIT_LIST_HEAD (&ls->ls_new_rsb); +spin_lock_init (&ls->ls_new_rsb_spin); +INIT_LIST_HEAD (&ls->ls_nodes);INIT_LIST_HEAD (&ls->ls_nodes_gone); ls->ls_num_nodes =0 ;
@@ -764,6 +767,13 @@ static int release_lockspace(struct dlm_ls *ls, int force)vfree (ls->ls_rsbtbl); +while (!list_empty (&ls->ls_new_rsb)) { + rsb = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb, + res_hashchain); +list_del (&rsb->res_hashchain); +dlm_free_rsb (rsb); + } +/* * Free structures on any other lists */
fs/dlm/memory.c +14 -8
@@ -16,6 +16,7 @@#include "memory.h" static struct kmem_cache *lkb_cache; +static struct kmem_cache *rsb_cache;int __init dlm_memory_init (void )
@@ -26,6 +27,14 @@ int __init dlm_memory_init(void) __alignof__(struct dlm_lkb), 0, NULL);if (!lkb_cache) ret = -ENOMEM ; + + rsb_cache =kmem_cache_create ("dlm_rsb" ,sizeof (struct dlm_rsb ), + __alignof__(struct dlm_rsb ),0 ,NULL ); +if (!rsb_cache) { +kmem_cache_destroy (lkb_cache); + ret = -ENOMEM ; + } +return ret; }
@@ -33,6 +42,8 @@ void dlm_memory_exit(void) {if (lkb_cache)kmem_cache_destroy (lkb_cache); +if (rsb_cache) +kmem_cache_destroy (rsb_cache); }char *dlm_allocate_lvb (struct dlm_ls *ls)
@@ -48,16 +59,11 @@ void dlm_free_lvb(char *p)kfree (p); } -/* FIXME: have some minimal space built-in to rsb for the name and -kmalloc a separate name if needed, like dentries are done */ - -struct dlm_rsb *dlm_allocate_rsb (struct dlm_ls *ls,int namelen) +struct dlm_rsb *dlm_allocate_rsb (struct dlm_ls *ls) {struct dlm_rsb *r; - DLM_ASSERT(namelen <= DLM_RESNAME_MAXLEN,); - - r =kzalloc (sizeof (*r) + namelen,GFP_NOFS ); + r =kmem_cache_zalloc (rsb_cache,GFP_NOFS );return r; }
@@ -65,7 +71,7 @@ void dlm_free_rsb(struct dlm_rsb *r) {if (r->res_lvbptr)dlm_free_lvb (r->res_lvbptr); -kfree (r); +kmem_cache_free (rsb_cache, r); }struct dlm_lkb *dlm_allocate_lkb (struct dlm_ls *ls)
fs/dlm/memory.h +1 -1
@@ -16,7 +16,7 @@int dlm_memory_init (void );void dlm_memory_exit (void ); -struct dlm_rsb *dlm_allocate_rsb (struct dlm_ls *ls,int namelen); +struct dlm_rsb *dlm_allocate_rsb (struct dlm_ls *ls);void dlm_free_rsb (struct dlm_rsb *r);struct dlm_lkb *dlm_allocate_lkb (struct dlm_ls *ls);void dlm_free_lkb (struct dlm_lkb *l);
Signature · 1 line
1.7.6