diff options
Diffstat (limited to 'fs/gfs2/glock.c')
-rw-r--r-- | fs/gfs2/glock.c | 410 |
1 files changed, 158 insertions, 252 deletions
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 7cd9a5a68d5..e2431313491 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c | |||
@@ -26,6 +26,9 @@ | |||
26 | #include <linux/freezer.h> | 26 | #include <linux/freezer.h> |
27 | #include <linux/workqueue.h> | 27 | #include <linux/workqueue.h> |
28 | #include <linux/jiffies.h> | 28 | #include <linux/jiffies.h> |
29 | #include <linux/rcupdate.h> | ||
30 | #include <linux/rculist_bl.h> | ||
31 | #include <linux/bit_spinlock.h> | ||
29 | 32 | ||
30 | #include "gfs2.h" | 33 | #include "gfs2.h" |
31 | #include "incore.h" | 34 | #include "incore.h" |
@@ -41,10 +44,6 @@ | |||
41 | #define CREATE_TRACE_POINTS | 44 | #define CREATE_TRACE_POINTS |
42 | #include "trace_gfs2.h" | 45 | #include "trace_gfs2.h" |
43 | 46 | ||
44 | struct gfs2_gl_hash_bucket { | ||
45 | struct hlist_head hb_list; | ||
46 | }; | ||
47 | |||
48 | struct gfs2_glock_iter { | 47 | struct gfs2_glock_iter { |
49 | int hash; /* hash bucket index */ | 48 | int hash; /* hash bucket index */ |
50 | struct gfs2_sbd *sdp; /* incore superblock */ | 49 | struct gfs2_sbd *sdp; /* incore superblock */ |
@@ -54,7 +53,6 @@ struct gfs2_glock_iter { | |||
54 | 53 | ||
55 | typedef void (*glock_examiner) (struct gfs2_glock * gl); | 54 | typedef void (*glock_examiner) (struct gfs2_glock * gl); |
56 | 55 | ||
57 | static int gfs2_dump_lockstate(struct gfs2_sbd *sdp); | ||
58 | static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl); | 56 | static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl); |
59 | #define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { __dump_glock(NULL, gl); BUG(); } } while(0) | 57 | #define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { __dump_glock(NULL, gl); BUG(); } } while(0) |
60 | static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target); | 58 | static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target); |
@@ -70,57 +68,9 @@ static DEFINE_SPINLOCK(lru_lock); | |||
70 | #define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) | 68 | #define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) |
71 | #define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1) | 69 | #define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1) |
72 | 70 | ||
73 | static struct gfs2_gl_hash_bucket gl_hash_table[GFS2_GL_HASH_SIZE]; | 71 | static struct hlist_bl_head gl_hash_table[GFS2_GL_HASH_SIZE]; |
74 | static struct dentry *gfs2_root; | 72 | static struct dentry *gfs2_root; |
75 | 73 | ||
76 | /* | ||
77 | * Despite what you might think, the numbers below are not arbitrary :-) | ||
78 | * They are taken from the ipv4 routing hash code, which is well tested | ||
79 | * and thus should be nearly optimal. Later on we might tweek the numbers | ||
80 | * but for now this should be fine. | ||
81 | * | ||
82 | * The reason for putting the locks in a separate array from the list heads | ||
83 | * is that we can have fewer locks than list heads and save memory. We use | ||
84 | * the same hash function for both, but with a different hash mask. | ||
85 | */ | ||
86 | #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \ | ||
87 | defined(CONFIG_PROVE_LOCKING) | ||
88 | |||
89 | #ifdef CONFIG_LOCKDEP | ||
90 | # define GL_HASH_LOCK_SZ 256 | ||
91 | #else | ||
92 | # if NR_CPUS >= 32 | ||
93 | # define GL_HASH_LOCK_SZ 4096 | ||
94 | # elif NR_CPUS >= 16 | ||
95 | # define GL_HASH_LOCK_SZ 2048 | ||
96 | # elif NR_CPUS >= 8 | ||
97 | # define GL_HASH_LOCK_SZ 1024 | ||
98 | # elif NR_CPUS >= 4 | ||
99 | # define GL_HASH_LOCK_SZ 512 | ||
100 | # else | ||
101 | # define GL_HASH_LOCK_SZ 256 | ||
102 | # endif | ||
103 | #endif | ||
104 | |||
105 | /* We never want more locks than chains */ | ||
106 | #if GFS2_GL_HASH_SIZE < GL_HASH_LOCK_SZ | ||
107 | # undef GL_HASH_LOCK_SZ | ||
108 | # define GL_HASH_LOCK_SZ GFS2_GL_HASH_SIZE | ||
109 | #endif | ||
110 | |||
111 | static rwlock_t gl_hash_locks[GL_HASH_LOCK_SZ]; | ||
112 | |||
113 | static inline rwlock_t *gl_lock_addr(unsigned int x) | ||
114 | { | ||
115 | return &gl_hash_locks[x & (GL_HASH_LOCK_SZ-1)]; | ||
116 | } | ||
117 | #else /* not SMP, so no spinlocks required */ | ||
118 | static inline rwlock_t *gl_lock_addr(unsigned int x) | ||
119 | { | ||
120 | return NULL; | ||
121 | } | ||
122 | #endif | ||
123 | |||
124 | /** | 74 | /** |
125 | * gl_hash() - Turn glock number into hash bucket number | 75 | * gl_hash() - Turn glock number into hash bucket number |
126 | * @lock: The glock number | 76 | * @lock: The glock number |
@@ -141,25 +91,35 @@ static unsigned int gl_hash(const struct gfs2_sbd *sdp, | |||
141 | return h; | 91 | return h; |
142 | } | 92 | } |
143 | 93 | ||
144 | /** | 94 | static inline void spin_lock_bucket(unsigned int hash) |
145 | * glock_free() - Perform a few checks and then release struct gfs2_glock | 95 | { |
146 | * @gl: The glock to release | 96 | struct hlist_bl_head *bl = &gl_hash_table[hash]; |
147 | * | 97 | bit_spin_lock(0, (unsigned long *)bl); |
148 | * Also calls lock module to release its internal structure for this glock. | 98 | } |
149 | * | ||
150 | */ | ||
151 | 99 | ||
152 | static void glock_free(struct gfs2_glock *gl) | 100 | static inline void spin_unlock_bucket(unsigned int hash) |
101 | { | ||
102 | struct hlist_bl_head *bl = &gl_hash_table[hash]; | ||
103 | __bit_spin_unlock(0, (unsigned long *)bl); | ||
104 | } | ||
105 | |||
106 | static void gfs2_glock_dealloc(struct rcu_head *rcu) | ||
107 | { | ||
108 | struct gfs2_glock *gl = container_of(rcu, struct gfs2_glock, gl_rcu); | ||
109 | |||
110 | if (gl->gl_ops->go_flags & GLOF_ASPACE) | ||
111 | kmem_cache_free(gfs2_glock_aspace_cachep, gl); | ||
112 | else | ||
113 | kmem_cache_free(gfs2_glock_cachep, gl); | ||
114 | } | ||
115 | |||
116 | void gfs2_glock_free(struct gfs2_glock *gl) | ||
153 | { | 117 | { |
154 | struct gfs2_sbd *sdp = gl->gl_sbd; | 118 | struct gfs2_sbd *sdp = gl->gl_sbd; |
155 | struct address_space *mapping = gfs2_glock2aspace(gl); | ||
156 | struct kmem_cache *cachep = gfs2_glock_cachep; | ||
157 | 119 | ||
158 | GLOCK_BUG_ON(gl, mapping && mapping->nrpages); | 120 | call_rcu(&gl->gl_rcu, gfs2_glock_dealloc); |
159 | trace_gfs2_glock_put(gl); | 121 | if (atomic_dec_and_test(&sdp->sd_glock_disposal)) |
160 | if (mapping) | 122 | wake_up(&sdp->sd_glock_wait); |
161 | cachep = gfs2_glock_aspace_cachep; | ||
162 | sdp->sd_lockstruct.ls_ops->lm_put_lock(cachep, gl); | ||
163 | } | 123 | } |
164 | 124 | ||
165 | /** | 125 | /** |
@@ -185,34 +145,49 @@ static int demote_ok(const struct gfs2_glock *gl) | |||
185 | { | 145 | { |
186 | const struct gfs2_glock_operations *glops = gl->gl_ops; | 146 | const struct gfs2_glock_operations *glops = gl->gl_ops; |
187 | 147 | ||
148 | /* assert_spin_locked(&gl->gl_spin); */ | ||
149 | |||
188 | if (gl->gl_state == LM_ST_UNLOCKED) | 150 | if (gl->gl_state == LM_ST_UNLOCKED) |
189 | return 0; | 151 | return 0; |
190 | if (!list_empty(&gl->gl_holders)) | 152 | if (test_bit(GLF_LFLUSH, &gl->gl_flags)) |
153 | return 0; | ||
154 | if ((gl->gl_name.ln_type != LM_TYPE_INODE) && | ||
155 | !list_empty(&gl->gl_holders)) | ||
191 | return 0; | 156 | return 0; |
192 | if (glops->go_demote_ok) | 157 | if (glops->go_demote_ok) |
193 | return glops->go_demote_ok(gl); | 158 | return glops->go_demote_ok(gl); |
194 | return 1; | 159 | return 1; |
195 | } | 160 | } |
196 | 161 | ||
162 | |||
197 | /** | 163 | /** |
198 | * gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list | 164 | * __gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list |
199 | * @gl: the glock | 165 | * @gl: the glock |
200 | * | 166 | * |
167 | * If the glock is demotable, then we add it (or move it) to the end | ||
168 | * of the glock LRU list. | ||
201 | */ | 169 | */ |
202 | 170 | ||
203 | static void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl) | 171 | static void __gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl) |
204 | { | 172 | { |
205 | int may_reclaim; | 173 | if (demote_ok(gl)) { |
206 | may_reclaim = (demote_ok(gl) && | 174 | spin_lock(&lru_lock); |
207 | (atomic_read(&gl->gl_ref) == 1 || | 175 | |
208 | (gl->gl_name.ln_type == LM_TYPE_INODE && | 176 | if (!list_empty(&gl->gl_lru)) |
209 | atomic_read(&gl->gl_ref) <= 2))); | 177 | list_del_init(&gl->gl_lru); |
210 | spin_lock(&lru_lock); | 178 | else |
211 | if (list_empty(&gl->gl_lru) && may_reclaim) { | 179 | atomic_inc(&lru_count); |
180 | |||
212 | list_add_tail(&gl->gl_lru, &lru_list); | 181 | list_add_tail(&gl->gl_lru, &lru_list); |
213 | atomic_inc(&lru_count); | 182 | spin_unlock(&lru_lock); |
214 | } | 183 | } |
215 | spin_unlock(&lru_lock); | 184 | } |
185 | |||
186 | void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl) | ||
187 | { | ||
188 | spin_lock(&gl->gl_spin); | ||
189 | __gfs2_glock_schedule_for_reclaim(gl); | ||
190 | spin_unlock(&gl->gl_spin); | ||
216 | } | 191 | } |
217 | 192 | ||
218 | /** | 193 | /** |
@@ -227,7 +202,6 @@ void gfs2_glock_put_nolock(struct gfs2_glock *gl) | |||
227 | { | 202 | { |
228 | if (atomic_dec_and_test(&gl->gl_ref)) | 203 | if (atomic_dec_and_test(&gl->gl_ref)) |
229 | GLOCK_BUG_ON(gl, 1); | 204 | GLOCK_BUG_ON(gl, 1); |
230 | gfs2_glock_schedule_for_reclaim(gl); | ||
231 | } | 205 | } |
232 | 206 | ||
233 | /** | 207 | /** |
@@ -236,30 +210,26 @@ void gfs2_glock_put_nolock(struct gfs2_glock *gl) | |||
236 | * | 210 | * |
237 | */ | 211 | */ |
238 | 212 | ||
239 | int gfs2_glock_put(struct gfs2_glock *gl) | 213 | void gfs2_glock_put(struct gfs2_glock *gl) |
240 | { | 214 | { |
241 | int rv = 0; | 215 | struct gfs2_sbd *sdp = gl->gl_sbd; |
216 | struct address_space *mapping = gfs2_glock2aspace(gl); | ||
242 | 217 | ||
243 | write_lock(gl_lock_addr(gl->gl_hash)); | 218 | if (atomic_dec_and_test(&gl->gl_ref)) { |
244 | if (atomic_dec_and_lock(&gl->gl_ref, &lru_lock)) { | 219 | spin_lock_bucket(gl->gl_hash); |
245 | hlist_del(&gl->gl_list); | 220 | hlist_bl_del_rcu(&gl->gl_list); |
221 | spin_unlock_bucket(gl->gl_hash); | ||
222 | spin_lock(&lru_lock); | ||
246 | if (!list_empty(&gl->gl_lru)) { | 223 | if (!list_empty(&gl->gl_lru)) { |
247 | list_del_init(&gl->gl_lru); | 224 | list_del_init(&gl->gl_lru); |
248 | atomic_dec(&lru_count); | 225 | atomic_dec(&lru_count); |
249 | } | 226 | } |
250 | spin_unlock(&lru_lock); | 227 | spin_unlock(&lru_lock); |
251 | write_unlock(gl_lock_addr(gl->gl_hash)); | ||
252 | GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); | 228 | GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); |
253 | glock_free(gl); | 229 | GLOCK_BUG_ON(gl, mapping && mapping->nrpages); |
254 | rv = 1; | 230 | trace_gfs2_glock_put(gl); |
255 | goto out; | 231 | sdp->sd_lockstruct.ls_ops->lm_put_lock(gl); |
256 | } | 232 | } |
257 | spin_lock(&gl->gl_spin); | ||
258 | gfs2_glock_schedule_for_reclaim(gl); | ||
259 | spin_unlock(&gl->gl_spin); | ||
260 | write_unlock(gl_lock_addr(gl->gl_hash)); | ||
261 | out: | ||
262 | return rv; | ||
263 | } | 233 | } |
264 | 234 | ||
265 | /** | 235 | /** |
@@ -275,17 +245,15 @@ static struct gfs2_glock *search_bucket(unsigned int hash, | |||
275 | const struct lm_lockname *name) | 245 | const struct lm_lockname *name) |
276 | { | 246 | { |
277 | struct gfs2_glock *gl; | 247 | struct gfs2_glock *gl; |
278 | struct hlist_node *h; | 248 | struct hlist_bl_node *h; |
279 | 249 | ||
280 | hlist_for_each_entry(gl, h, &gl_hash_table[hash].hb_list, gl_list) { | 250 | hlist_bl_for_each_entry_rcu(gl, h, &gl_hash_table[hash], gl_list) { |
281 | if (!lm_name_equal(&gl->gl_name, name)) | 251 | if (!lm_name_equal(&gl->gl_name, name)) |
282 | continue; | 252 | continue; |
283 | if (gl->gl_sbd != sdp) | 253 | if (gl->gl_sbd != sdp) |
284 | continue; | 254 | continue; |
285 | 255 | if (atomic_inc_not_zero(&gl->gl_ref)) | |
286 | atomic_inc(&gl->gl_ref); | 256 | return gl; |
287 | |||
288 | return gl; | ||
289 | } | 257 | } |
290 | 258 | ||
291 | return NULL; | 259 | return NULL; |
@@ -743,10 +711,11 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, | |||
743 | struct gfs2_glock *gl, *tmp; | 711 | struct gfs2_glock *gl, *tmp; |
744 | unsigned int hash = gl_hash(sdp, &name); | 712 | unsigned int hash = gl_hash(sdp, &name); |
745 | struct address_space *mapping; | 713 | struct address_space *mapping; |
714 | struct kmem_cache *cachep; | ||
746 | 715 | ||
747 | read_lock(gl_lock_addr(hash)); | 716 | rcu_read_lock(); |
748 | gl = search_bucket(hash, sdp, &name); | 717 | gl = search_bucket(hash, sdp, &name); |
749 | read_unlock(gl_lock_addr(hash)); | 718 | rcu_read_unlock(); |
750 | 719 | ||
751 | *glp = gl; | 720 | *glp = gl; |
752 | if (gl) | 721 | if (gl) |
@@ -755,9 +724,10 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, | |||
755 | return -ENOENT; | 724 | return -ENOENT; |
756 | 725 | ||
757 | if (glops->go_flags & GLOF_ASPACE) | 726 | if (glops->go_flags & GLOF_ASPACE) |
758 | gl = kmem_cache_alloc(gfs2_glock_aspace_cachep, GFP_KERNEL); | 727 | cachep = gfs2_glock_aspace_cachep; |
759 | else | 728 | else |
760 | gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL); | 729 | cachep = gfs2_glock_cachep; |
730 | gl = kmem_cache_alloc(cachep, GFP_KERNEL); | ||
761 | if (!gl) | 731 | if (!gl) |
762 | return -ENOMEM; | 732 | return -ENOMEM; |
763 | 733 | ||
@@ -790,15 +760,16 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, | |||
790 | mapping->writeback_index = 0; | 760 | mapping->writeback_index = 0; |
791 | } | 761 | } |
792 | 762 | ||
793 | write_lock(gl_lock_addr(hash)); | 763 | spin_lock_bucket(hash); |
794 | tmp = search_bucket(hash, sdp, &name); | 764 | tmp = search_bucket(hash, sdp, &name); |
795 | if (tmp) { | 765 | if (tmp) { |
796 | write_unlock(gl_lock_addr(hash)); | 766 | spin_unlock_bucket(hash); |
797 | glock_free(gl); | 767 | kmem_cache_free(cachep, gl); |
768 | atomic_dec(&sdp->sd_glock_disposal); | ||
798 | gl = tmp; | 769 | gl = tmp; |
799 | } else { | 770 | } else { |
800 | hlist_add_head(&gl->gl_list, &gl_hash_table[hash].hb_list); | 771 | hlist_bl_add_head_rcu(&gl->gl_list, &gl_hash_table[hash]); |
801 | write_unlock(gl_lock_addr(hash)); | 772 | spin_unlock_bucket(hash); |
802 | } | 773 | } |
803 | 774 | ||
804 | *glp = gl; | 775 | *glp = gl; |
@@ -1007,13 +978,13 @@ fail: | |||
1007 | insert_pt = &gh2->gh_list; | 978 | insert_pt = &gh2->gh_list; |
1008 | } | 979 | } |
1009 | set_bit(GLF_QUEUED, &gl->gl_flags); | 980 | set_bit(GLF_QUEUED, &gl->gl_flags); |
981 | trace_gfs2_glock_queue(gh, 1); | ||
1010 | if (likely(insert_pt == NULL)) { | 982 | if (likely(insert_pt == NULL)) { |
1011 | list_add_tail(&gh->gh_list, &gl->gl_holders); | 983 | list_add_tail(&gh->gh_list, &gl->gl_holders); |
1012 | if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY)) | 984 | if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY)) |
1013 | goto do_cancel; | 985 | goto do_cancel; |
1014 | return; | 986 | return; |
1015 | } | 987 | } |
1016 | trace_gfs2_glock_queue(gh, 1); | ||
1017 | list_add_tail(&gh->gh_list, insert_pt); | 988 | list_add_tail(&gh->gh_list, insert_pt); |
1018 | do_cancel: | 989 | do_cancel: |
1019 | gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); | 990 | gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); |
@@ -1113,6 +1084,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh) | |||
1113 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) | 1084 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) |
1114 | fast_path = 1; | 1085 | fast_path = 1; |
1115 | } | 1086 | } |
1087 | __gfs2_glock_schedule_for_reclaim(gl); | ||
1116 | trace_gfs2_glock_queue(gh, 0); | 1088 | trace_gfs2_glock_queue(gh, 0); |
1117 | spin_unlock(&gl->gl_spin); | 1089 | spin_unlock(&gl->gl_spin); |
1118 | if (likely(fast_path)) | 1090 | if (likely(fast_path)) |
@@ -1276,10 +1248,8 @@ int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs) | |||
1276 | 1248 | ||
1277 | void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs) | 1249 | void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs) |
1278 | { | 1250 | { |
1279 | unsigned int x; | 1251 | while (num_gh--) |
1280 | 1252 | gfs2_glock_dq(&ghs[num_gh]); | |
1281 | for (x = 0; x < num_gh; x++) | ||
1282 | gfs2_glock_dq(&ghs[x]); | ||
1283 | } | 1253 | } |
1284 | 1254 | ||
1285 | /** | 1255 | /** |
@@ -1291,10 +1261,8 @@ void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs) | |||
1291 | 1261 | ||
1292 | void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs) | 1262 | void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs) |
1293 | { | 1263 | { |
1294 | unsigned int x; | 1264 | while (num_gh--) |
1295 | 1265 | gfs2_glock_dq_uninit(&ghs[num_gh]); | |
1296 | for (x = 0; x < num_gh; x++) | ||
1297 | gfs2_glock_dq_uninit(&ghs[x]); | ||
1298 | } | 1266 | } |
1299 | 1267 | ||
1300 | void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) | 1268 | void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) |
@@ -1440,42 +1408,30 @@ static struct shrinker glock_shrinker = { | |||
1440 | * @sdp: the filesystem | 1408 | * @sdp: the filesystem |
1441 | * @bucket: the bucket | 1409 | * @bucket: the bucket |
1442 | * | 1410 | * |
1443 | * Returns: 1 if the bucket has entries | ||
1444 | */ | 1411 | */ |
1445 | 1412 | ||
1446 | static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, | 1413 | static void examine_bucket(glock_examiner examiner, const struct gfs2_sbd *sdp, |
1447 | unsigned int hash) | 1414 | unsigned int hash) |
1448 | { | 1415 | { |
1449 | struct gfs2_glock *gl, *prev = NULL; | 1416 | struct gfs2_glock *gl; |
1450 | int has_entries = 0; | 1417 | struct hlist_bl_head *head = &gl_hash_table[hash]; |
1451 | struct hlist_head *head = &gl_hash_table[hash].hb_list; | 1418 | struct hlist_bl_node *pos; |
1452 | 1419 | ||
1453 | read_lock(gl_lock_addr(hash)); | 1420 | rcu_read_lock(); |
1454 | /* Can't use hlist_for_each_entry - don't want prefetch here */ | 1421 | hlist_bl_for_each_entry_rcu(gl, pos, head, gl_list) { |
1455 | if (hlist_empty(head)) | 1422 | if ((gl->gl_sbd == sdp) && atomic_read(&gl->gl_ref)) |
1456 | goto out; | ||
1457 | gl = list_entry(head->first, struct gfs2_glock, gl_list); | ||
1458 | while(1) { | ||
1459 | if (!sdp || gl->gl_sbd == sdp) { | ||
1460 | gfs2_glock_hold(gl); | ||
1461 | read_unlock(gl_lock_addr(hash)); | ||
1462 | if (prev) | ||
1463 | gfs2_glock_put(prev); | ||
1464 | prev = gl; | ||
1465 | examiner(gl); | 1423 | examiner(gl); |
1466 | has_entries = 1; | ||
1467 | read_lock(gl_lock_addr(hash)); | ||
1468 | } | ||
1469 | if (gl->gl_list.next == NULL) | ||
1470 | break; | ||
1471 | gl = list_entry(gl->gl_list.next, struct gfs2_glock, gl_list); | ||
1472 | } | 1424 | } |
1473 | out: | 1425 | rcu_read_unlock(); |
1474 | read_unlock(gl_lock_addr(hash)); | ||
1475 | if (prev) | ||
1476 | gfs2_glock_put(prev); | ||
1477 | cond_resched(); | 1426 | cond_resched(); |
1478 | return has_entries; | 1427 | } |
1428 | |||
1429 | static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp) | ||
1430 | { | ||
1431 | unsigned x; | ||
1432 | |||
1433 | for (x = 0; x < GFS2_GL_HASH_SIZE; x++) | ||
1434 | examine_bucket(examiner, sdp, x); | ||
1479 | } | 1435 | } |
1480 | 1436 | ||
1481 | 1437 | ||
@@ -1529,10 +1485,21 @@ static void clear_glock(struct gfs2_glock *gl) | |||
1529 | 1485 | ||
1530 | void gfs2_glock_thaw(struct gfs2_sbd *sdp) | 1486 | void gfs2_glock_thaw(struct gfs2_sbd *sdp) |
1531 | { | 1487 | { |
1532 | unsigned x; | 1488 | glock_hash_walk(thaw_glock, sdp); |
1489 | } | ||
1533 | 1490 | ||
1534 | for (x = 0; x < GFS2_GL_HASH_SIZE; x++) | 1491 | static int dump_glock(struct seq_file *seq, struct gfs2_glock *gl) |
1535 | examine_bucket(thaw_glock, sdp, x); | 1492 | { |
1493 | int ret; | ||
1494 | spin_lock(&gl->gl_spin); | ||
1495 | ret = __dump_glock(seq, gl); | ||
1496 | spin_unlock(&gl->gl_spin); | ||
1497 | return ret; | ||
1498 | } | ||
1499 | |||
1500 | static void dump_glock_func(struct gfs2_glock *gl) | ||
1501 | { | ||
1502 | dump_glock(NULL, gl); | ||
1536 | } | 1503 | } |
1537 | 1504 | ||
1538 | /** | 1505 | /** |
@@ -1545,13 +1512,10 @@ void gfs2_glock_thaw(struct gfs2_sbd *sdp) | |||
1545 | 1512 | ||
1546 | void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) | 1513 | void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) |
1547 | { | 1514 | { |
1548 | unsigned int x; | 1515 | glock_hash_walk(clear_glock, sdp); |
1549 | |||
1550 | for (x = 0; x < GFS2_GL_HASH_SIZE; x++) | ||
1551 | examine_bucket(clear_glock, sdp, x); | ||
1552 | flush_workqueue(glock_workqueue); | 1516 | flush_workqueue(glock_workqueue); |
1553 | wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0); | 1517 | wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0); |
1554 | gfs2_dump_lockstate(sdp); | 1518 | glock_hash_walk(dump_glock_func, sdp); |
1555 | } | 1519 | } |
1556 | 1520 | ||
1557 | void gfs2_glock_finish_truncate(struct gfs2_inode *ip) | 1521 | void gfs2_glock_finish_truncate(struct gfs2_inode *ip) |
@@ -1717,66 +1681,15 @@ out: | |||
1717 | return error; | 1681 | return error; |
1718 | } | 1682 | } |
1719 | 1683 | ||
1720 | static int dump_glock(struct seq_file *seq, struct gfs2_glock *gl) | ||
1721 | { | ||
1722 | int ret; | ||
1723 | spin_lock(&gl->gl_spin); | ||
1724 | ret = __dump_glock(seq, gl); | ||
1725 | spin_unlock(&gl->gl_spin); | ||
1726 | return ret; | ||
1727 | } | ||
1728 | 1684 | ||
1729 | /** | ||
1730 | * gfs2_dump_lockstate - print out the current lockstate | ||
1731 | * @sdp: the filesystem | ||
1732 | * @ub: the buffer to copy the information into | ||
1733 | * | ||
1734 | * If @ub is NULL, dump the lockstate to the console. | ||
1735 | * | ||
1736 | */ | ||
1737 | |||
1738 | static int gfs2_dump_lockstate(struct gfs2_sbd *sdp) | ||
1739 | { | ||
1740 | struct gfs2_glock *gl; | ||
1741 | struct hlist_node *h; | ||
1742 | unsigned int x; | ||
1743 | int error = 0; | ||
1744 | |||
1745 | for (x = 0; x < GFS2_GL_HASH_SIZE; x++) { | ||
1746 | |||
1747 | read_lock(gl_lock_addr(x)); | ||
1748 | |||
1749 | hlist_for_each_entry(gl, h, &gl_hash_table[x].hb_list, gl_list) { | ||
1750 | if (gl->gl_sbd != sdp) | ||
1751 | continue; | ||
1752 | |||
1753 | error = dump_glock(NULL, gl); | ||
1754 | if (error) | ||
1755 | break; | ||
1756 | } | ||
1757 | |||
1758 | read_unlock(gl_lock_addr(x)); | ||
1759 | |||
1760 | if (error) | ||
1761 | break; | ||
1762 | } | ||
1763 | |||
1764 | |||
1765 | return error; | ||
1766 | } | ||
1767 | 1685 | ||
1768 | 1686 | ||
1769 | int __init gfs2_glock_init(void) | 1687 | int __init gfs2_glock_init(void) |
1770 | { | 1688 | { |
1771 | unsigned i; | 1689 | unsigned i; |
1772 | for(i = 0; i < GFS2_GL_HASH_SIZE; i++) { | 1690 | for(i = 0; i < GFS2_GL_HASH_SIZE; i++) { |
1773 | INIT_HLIST_HEAD(&gl_hash_table[i].hb_list); | 1691 | INIT_HLIST_BL_HEAD(&gl_hash_table[i]); |
1774 | } | ||
1775 | #ifdef GL_HASH_LOCK_SZ | ||
1776 | for(i = 0; i < GL_HASH_LOCK_SZ; i++) { | ||
1777 | rwlock_init(&gl_hash_locks[i]); | ||
1778 | } | 1692 | } |
1779 | #endif | ||
1780 | 1693 | ||
1781 | glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM | | 1694 | glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM | |
1782 | WQ_HIGHPRI | WQ_FREEZABLE, 0); | 1695 | WQ_HIGHPRI | WQ_FREEZABLE, 0); |
@@ -1802,62 +1715,54 @@ void gfs2_glock_exit(void) | |||
1802 | destroy_workqueue(gfs2_delete_workqueue); | 1715 | destroy_workqueue(gfs2_delete_workqueue); |
1803 | } | 1716 | } |
1804 | 1717 | ||
1718 | static inline struct gfs2_glock *glock_hash_chain(unsigned hash) | ||
1719 | { | ||
1720 | return hlist_bl_entry(hlist_bl_first_rcu(&gl_hash_table[hash]), | ||
1721 | struct gfs2_glock, gl_list); | ||
1722 | } | ||
1723 | |||
1724 | static inline struct gfs2_glock *glock_hash_next(struct gfs2_glock *gl) | ||
1725 | { | ||
1726 | return hlist_bl_entry(rcu_dereference(gl->gl_list.next), | ||
1727 | struct gfs2_glock, gl_list); | ||
1728 | } | ||
1729 | |||
1805 | static int gfs2_glock_iter_next(struct gfs2_glock_iter *gi) | 1730 | static int gfs2_glock_iter_next(struct gfs2_glock_iter *gi) |
1806 | { | 1731 | { |
1807 | struct gfs2_glock *gl; | 1732 | struct gfs2_glock *gl; |
1808 | 1733 | ||
1809 | restart: | 1734 | do { |
1810 | read_lock(gl_lock_addr(gi->hash)); | 1735 | gl = gi->gl; |
1811 | gl = gi->gl; | 1736 | if (gl) { |
1812 | if (gl) { | 1737 | gi->gl = glock_hash_next(gl); |
1813 | gi->gl = hlist_entry(gl->gl_list.next, | 1738 | } else { |
1814 | struct gfs2_glock, gl_list); | 1739 | gi->gl = glock_hash_chain(gi->hash); |
1815 | } else { | 1740 | } |
1816 | gi->gl = hlist_entry(gl_hash_table[gi->hash].hb_list.first, | 1741 | while (gi->gl == NULL) { |
1817 | struct gfs2_glock, gl_list); | 1742 | gi->hash++; |
1818 | } | 1743 | if (gi->hash >= GFS2_GL_HASH_SIZE) { |
1819 | if (gi->gl) | 1744 | rcu_read_unlock(); |
1820 | gfs2_glock_hold(gi->gl); | 1745 | return 1; |
1821 | read_unlock(gl_lock_addr(gi->hash)); | 1746 | } |
1822 | if (gl) | 1747 | gi->gl = glock_hash_chain(gi->hash); |
1823 | gfs2_glock_put(gl); | 1748 | } |
1824 | while (gi->gl == NULL) { | 1749 | /* Skip entries for other sb and dead entries */ |
1825 | gi->hash++; | 1750 | } while (gi->sdp != gi->gl->gl_sbd || atomic_read(&gi->gl->gl_ref) == 0); |
1826 | if (gi->hash >= GFS2_GL_HASH_SIZE) | ||
1827 | return 1; | ||
1828 | read_lock(gl_lock_addr(gi->hash)); | ||
1829 | gi->gl = hlist_entry(gl_hash_table[gi->hash].hb_list.first, | ||
1830 | struct gfs2_glock, gl_list); | ||
1831 | if (gi->gl) | ||
1832 | gfs2_glock_hold(gi->gl); | ||
1833 | read_unlock(gl_lock_addr(gi->hash)); | ||
1834 | } | ||
1835 | |||
1836 | if (gi->sdp != gi->gl->gl_sbd) | ||
1837 | goto restart; | ||
1838 | 1751 | ||
1839 | return 0; | 1752 | return 0; |
1840 | } | 1753 | } |
1841 | 1754 | ||
1842 | static void gfs2_glock_iter_free(struct gfs2_glock_iter *gi) | ||
1843 | { | ||
1844 | if (gi->gl) | ||
1845 | gfs2_glock_put(gi->gl); | ||
1846 | gi->gl = NULL; | ||
1847 | } | ||
1848 | |||
1849 | static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos) | 1755 | static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos) |
1850 | { | 1756 | { |
1851 | struct gfs2_glock_iter *gi = seq->private; | 1757 | struct gfs2_glock_iter *gi = seq->private; |
1852 | loff_t n = *pos; | 1758 | loff_t n = *pos; |
1853 | 1759 | ||
1854 | gi->hash = 0; | 1760 | gi->hash = 0; |
1761 | rcu_read_lock(); | ||
1855 | 1762 | ||
1856 | do { | 1763 | do { |
1857 | if (gfs2_glock_iter_next(gi)) { | 1764 | if (gfs2_glock_iter_next(gi)) |
1858 | gfs2_glock_iter_free(gi); | ||
1859 | return NULL; | 1765 | return NULL; |
1860 | } | ||
1861 | } while (n--); | 1766 | } while (n--); |
1862 | 1767 | ||
1863 | return gi->gl; | 1768 | return gi->gl; |
@@ -1870,10 +1775,8 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, | |||
1870 | 1775 | ||
1871 | (*pos)++; | 1776 | (*pos)++; |
1872 | 1777 | ||
1873 | if (gfs2_glock_iter_next(gi)) { | 1778 | if (gfs2_glock_iter_next(gi)) |
1874 | gfs2_glock_iter_free(gi); | ||
1875 | return NULL; | 1779 | return NULL; |
1876 | } | ||
1877 | 1780 | ||
1878 | return gi->gl; | 1781 | return gi->gl; |
1879 | } | 1782 | } |
@@ -1881,7 +1784,10 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, | |||
1881 | static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr) | 1784 | static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr) |
1882 | { | 1785 | { |
1883 | struct gfs2_glock_iter *gi = seq->private; | 1786 | struct gfs2_glock_iter *gi = seq->private; |
1884 | gfs2_glock_iter_free(gi); | 1787 | |
1788 | if (gi->gl) | ||
1789 | rcu_read_unlock(); | ||
1790 | gi->gl = NULL; | ||
1885 | } | 1791 | } |
1886 | 1792 | ||
1887 | static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr) | 1793 | static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr) |