Skip to contentSkip to conversation

gfs2: fix glock shrinker ref issues

PATCH New Bob Peterson 1 participant 1 message Sep 12, 2023 GFS2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs2: fix glock shrinker ref issues

Before this patch, function gfs2_scan_glock_lru would only try to free glocks that had a reference count of 0. But if the reference count ever got to 0, the glock should have already been freed.

Shrinker function gfs2_dispose_glock_lru checks whether glocks on the LRU are demote_ok, and if so, tries to demote them. But that's only possible if the reference count is at least 1.

This patch changes gfs2_scan_glock_lru so it will try to demote and/or dispose of glocks that have a reference count of 1 and which are either demotable, or are already unlocked.

Here is the life cycle of an inode glock from start to finish with "touch /mnt/gfs2/test" along with changes to gl->gl_lockref.count:

1. gfs2_glock_get - glock created = 1
2. gfs2_create_inode calls gfs2_glock_nq_init (glock_hold) 1 -> 2
3. do_xmote calls gfs2_glock_hold to call lm_lock() for the

   dlm request gl->gl_lockref.count++;                       2 -> 3
4. State_change gl->gl_lockref.count++;                      3 -> 4
5. gfs2_glock_put                                            4 -> 3
6. gfs2_permission                                           3 -> 4
7. gfs2_glock_put                                            4 -> 3
8. gfs2_setattr                                              3 -> 4
9. gfs2_glock_put                                            4 -> 3
10. glock_work_func drop_refs == 1                           3 -> 2
11. gfs2_add_revoke gfs2_glock_hold                          2 -> 3
12. glock_work_func drop_refs == 1                           3 -> 2

So now the inode glock is cached in EX. Here is what happens to it when you then do "rm /mnt/gfs2/test":

13. gfs2_unlink                                              2 -> 3
14. gfs2_glock_put                                           3 -> 2
15. evict_should_delete, gfs2_glock_nq_init                  2 -> 3
16. gfs2_glock_put                                           3 -> 2
17. gfs2_glock_put                                           2 -> 1

So now it's on the LRU with a ref count of 1 after being deleted. When you dump the glock list, however, it takes an additional reference:

18 - gfs2_glock_iter_next 1 -> 2

So it shows up in the list as having a ref count of 2, although the ref should be immediately dropped after the glock dump.

---
 fs/gfs2/glock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/glock.c +3 -1
index 9cbf8d98489a..4a280be229a6 100644
@@ -2010,7 +2010,9 @@ static long gfs2_scan_glock_lru(int nr)
 		if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
 			if (!spin_trylock(&gl->gl_lockref.lock))
 				continue;
-			if (!gl->gl_lockref.count) {
+			if (gl->gl_lockref.count <= 1 &&
+			    (gl->gl_state == LM_ST_UNLOCKED ||
+			     demote_ok(gl))) {
 				list_move(&gl->gl_lru, &dispose);
 				atomic_dec(&lru_count);
 				freed++;
Signature · 1 line
2.41.0