1 From: Sunil Mushran <sunil.mushran@oracle.com>
2 Date: Thu, 26 Feb 2009 15:00:41 -0800
3 Subject: ocfs2/dlm: Activate dlm->master_hash for master list entries
7 With this patch, the mles are stored in a hash and not a simple list.
8 This should improve the mle lookup time when the number of outstanding
11 Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com>
12 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
14 fs/ocfs2/dlm/dlmcommon.h | 4 +-
15 fs/ocfs2/dlm/dlmdebug.c | 24 +++++++++++-------
16 fs/ocfs2/dlm/dlmdomain.c | 1 -
17 fs/ocfs2/dlm/dlmmaster.c | 61 ++++++++++++++++++++++++++++++++-------------
18 4 files changed, 60 insertions(+), 30 deletions(-)
20 Index: linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmcommon.h
21 ===================================================================
22 --- linux-2.6.27-sle11_ocfs2_update.orig/fs/ocfs2/dlm/dlmcommon.h
23 +++ linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmcommon.h
24 @@ -56,12 +56,13 @@ enum dlm_mle_type {
27 struct dlm_lock_name {
30 unsigned char name[DLM_LOCKID_NAME_MAX];
33 struct dlm_master_list_entry {
34 - struct list_head list;
35 + struct hlist_node master_hash_node;
36 struct list_head hb_events;
39 @@ -152,7 +153,6 @@ struct dlm_ctxt
40 struct dlm_recovery_ctxt reco;
41 spinlock_t master_lock;
42 struct hlist_head **master_hash;
43 - struct list_head master_list;
44 struct list_head mle_hb_events;
46 /* these give a really vague idea of the system load */
47 Index: linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmdebug.c
48 ===================================================================
49 --- linux-2.6.27-sle11_ocfs2_update.orig/fs/ocfs2/dlm/dlmdebug.c
50 +++ linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmdebug.c
51 @@ -501,18 +501,25 @@ static struct file_operations debug_purg
52 static int debug_mle_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
54 struct dlm_master_list_entry *mle;
56 + struct hlist_head *bucket;
57 + struct hlist_node *list;
59 unsigned long total = 0;
61 out += snprintf(db->buf + out, db->len - out,
62 "Dumping MLEs for Domain: %s\n", dlm->name);
64 spin_lock(&dlm->master_lock);
65 - list_for_each_entry(mle, &dlm->master_list, list) {
67 - if (db->len - out < 200)
69 - out += dump_mle(mle, db->buf + out, db->len - out);
70 + for (i = 0; i < DLM_HASH_BUCKETS; i++) {
71 + bucket = dlm_master_hash(dlm, i);
72 + hlist_for_each(list, bucket) {
73 + mle = hlist_entry(list, struct dlm_master_list_entry,
76 + if (db->len - out < 200)
78 + out += dump_mle(mle, db->buf + out, db->len - out);
81 spin_unlock(&dlm->master_lock);
83 @@ -813,12 +820,11 @@ static int debug_state_print(struct dlm_
84 /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
85 out += snprintf(db->buf + out, db->len - out,
86 "Lists: Dirty=%s Purge=%s PendingASTs=%s "
87 - "PendingBASTs=%s Master=%s\n",
88 + "PendingBASTs=%s\n",
89 (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
90 (list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
91 (list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
92 - (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"),
93 - (list_empty(&dlm->master_list) ? "Empty" : "InUse"));
94 + (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"));
96 /* Purge Count: xxx Refs: xxx */
97 out += snprintf(db->buf + out, db->len - out,
98 Index: linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmdomain.c
99 ===================================================================
100 --- linux-2.6.27-sle11_ocfs2_update.orig/fs/ocfs2/dlm/dlmdomain.c
101 +++ linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmdomain.c
102 @@ -1597,7 +1597,6 @@ static struct dlm_ctxt *dlm_alloc_ctxt(c
103 init_waitqueue_head(&dlm->reco.event);
104 init_waitqueue_head(&dlm->ast_wq);
105 init_waitqueue_head(&dlm->migration_wq);
106 - INIT_LIST_HEAD(&dlm->master_list);
107 INIT_LIST_HEAD(&dlm->mle_hb_events);
109 dlm->joining_node = DLM_LOCK_RES_OWNER_UNKNOWN;
110 Index: linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmmaster.c
111 ===================================================================
112 --- linux-2.6.27-sle11_ocfs2_update.orig/fs/ocfs2/dlm/dlmmaster.c
113 +++ linux-2.6.27-sle11_ocfs2_update/fs/ocfs2/dlm/dlmmaster.c
114 @@ -69,7 +69,8 @@ static int dlm_do_assert_master(struct d
115 static void dlm_deref_lockres_worker(struct dlm_work_item *item, void *data);
117 static inline void __dlm_mle_name(struct dlm_master_list_entry *mle,
118 - unsigned char **name, unsigned int *namelen)
119 + unsigned char **name, unsigned int *namelen,
120 + unsigned int *namehash)
122 BUG_ON(mle->type != DLM_MLE_BLOCK &&
123 mle->type != DLM_MLE_MASTER &&
124 @@ -78,9 +79,13 @@ static inline void __dlm_mle_name(struct
125 if (mle->type != DLM_MLE_MASTER) {
126 *name = mle->u.mlename.name;
127 *namelen = mle->u.mlename.len;
129 + *namehash = mle->u.mlename.hash;
131 *name = (unsigned char *)mle->u.mleres->lockname.name;
132 *namelen = mle->u.mleres->lockname.len;
134 + *namehash = mle->u.mleres->lockname.hash;
138 @@ -95,7 +100,7 @@ static inline int dlm_mle_equal(struct d
142 - __dlm_mle_name(mle, &mlename, &mlelen);
143 + __dlm_mle_name(mle, &mlename, &mlelen, NULL);
145 if (namelen != mlelen || memcmp(name, mlename, namelen) != 0)
147 @@ -294,7 +299,7 @@ static void dlm_init_mle(struct dlm_mast
151 - INIT_LIST_HEAD(&mle->list);
152 + INIT_HLIST_NODE(&mle->master_hash_node);
153 INIT_LIST_HEAD(&mle->hb_events);
154 memset(mle->maybe_map, 0, sizeof(mle->maybe_map));
155 spin_lock_init(&mle->spinlock);
156 @@ -317,6 +322,7 @@ static void dlm_init_mle(struct dlm_mast
158 memcpy(mle->u.mlename.name, name, namelen);
159 mle->u.mlename.len = namelen;
160 + mle->u.mlename.hash = dlm_lockid_hash(name, namelen);
163 /* copy off the node_map and register hb callbacks on our copy */
164 @@ -334,15 +340,21 @@ void __dlm_unlink_mle(struct dlm_ctxt *d
165 assert_spin_locked(&dlm->spinlock);
166 assert_spin_locked(&dlm->master_lock);
168 - if (!list_empty(&mle->list))
169 - list_del_init(&mle->list);
170 + if (!hlist_unhashed(&mle->master_hash_node))
171 + hlist_del_init(&mle->master_hash_node);
174 void __dlm_insert_mle(struct dlm_ctxt *dlm, struct dlm_master_list_entry *mle)
176 + struct hlist_head *bucket;
177 + unsigned char *mname;
178 + unsigned int mlen, hash;
180 assert_spin_locked(&dlm->master_lock);
182 - list_add(&mle->list, &dlm->master_list);
183 + __dlm_mle_name(mle, &mname, &mlen, &hash);
184 + bucket = dlm_master_hash(dlm, hash);
185 + hlist_add_head(&mle->master_hash_node, bucket);
188 /* returns 1 if found, 0 if not */
189 @@ -351,10 +363,17 @@ static int dlm_find_mle(struct dlm_ctxt
190 char *name, unsigned int namelen)
192 struct dlm_master_list_entry *tmpmle;
193 + struct hlist_head *bucket;
194 + struct hlist_node *list;
197 assert_spin_locked(&dlm->master_lock);
199 - list_for_each_entry(tmpmle, &dlm->master_list, list) {
200 + hash = dlm_lockid_hash(name, namelen);
201 + bucket = dlm_master_hash(dlm, hash);
202 + hlist_for_each(list, bucket) {
203 + tmpmle = hlist_entry(list, struct dlm_master_list_entry,
205 if (!dlm_mle_equal(dlm, tmpmle, name, namelen))
208 @@ -428,23 +447,20 @@ static void dlm_mle_release(struct kref
210 struct dlm_master_list_entry *mle;
211 struct dlm_ctxt *dlm;
212 + unsigned char *mname;
217 mle = container_of(kref, struct dlm_master_list_entry, mle_refs);
220 - if (mle->type != DLM_MLE_MASTER) {
221 - mlog(0, "calling mle_release for %.*s, type %d\n",
222 - mle->u.mlename.len, mle->u.mlename.name, mle->type);
224 - mlog(0, "calling mle_release for %.*s, type %d\n",
225 - mle->u.mleres->lockname.len,
226 - mle->u.mleres->lockname.name, mle->type);
228 assert_spin_locked(&dlm->spinlock);
229 assert_spin_locked(&dlm->master_lock);
231 + __dlm_mle_name(mle, &mname, &mlen, NULL);
232 + mlog(0, "Releasing mle for %.*s, type %d\n", mlen, mname, mle->type);
234 /* remove from list if not already */
235 __dlm_unlink_mle(dlm, mle);
237 @@ -1335,7 +1351,7 @@ static int dlm_do_master_request(struct
239 BUG_ON(mle->type == DLM_MLE_MIGRATION);
241 - __dlm_mle_name(mle, &mlename, &mlenamelen);
242 + __dlm_mle_name(mle, &mlename, &mlenamelen, NULL);
244 request.namelen = (u8)mlenamelen;
245 memcpy(request.name, mlename, request.namelen);
246 @@ -3264,8 +3280,11 @@ static void dlm_clean_block_mle(struct d
248 void dlm_clean_master_list(struct dlm_ctxt *dlm, u8 dead_node)
250 - struct dlm_master_list_entry *mle, *next;
251 + struct dlm_master_list_entry *mle;
252 struct dlm_lock_resource *res;
253 + struct hlist_head *bucket;
254 + struct hlist_node *list;
257 mlog_entry("dlm=%s, dead node=%u\n", dlm->name, dead_node);
259 @@ -3273,7 +3292,12 @@ top:
261 /* clean the master list */
262 spin_lock(&dlm->master_lock);
263 - list_for_each_entry_safe(mle, next, &dlm->master_list, list) {
264 + for (i = 0; i < DLM_HASH_BUCKETS; i++) {
265 + bucket = dlm_master_hash(dlm, i);
266 + hlist_for_each(list, bucket) {
267 + mle = hlist_entry(list, struct dlm_master_list_entry,
270 BUG_ON(mle->type != DLM_MLE_BLOCK &&
271 mle->type != DLM_MLE_MASTER &&
272 mle->type != DLM_MLE_MIGRATION);
273 @@ -3329,6 +3353,7 @@ top:
274 /* this may be the last reference */
278 spin_unlock(&dlm->master_lock);