From: Andreas Gruenbacher <agruenba@redhat.com>
To: gfs2@lists.linux.dev
Cc: Andreas Gruenbacher <agruenba@redhat.com>
Subject: [PATCH 15/15] gfs2: Fix lru_count accounting
Date: Tue, 9 Apr 2024 18:45:05 +0200 [thread overview]
Message-ID: <20240409164508.79570-16-agruenba@redhat.com> (raw)
In-Reply-To: <20240409164508.79570-1-agruenba@redhat.com>
Currently, gfs2_scan_glock_lru() decrements lru_count when a glock is
moved onto the dispose list. When such a glock is then stolen from the
dispose list while gfs2_dispose_glock_lru() doesn't hold the lru_lock,
lru_count will be decremented again, so the counter will eventually go
negative.
This bug has existed in one form or another since at least commit
97cc1025b1a91 ("GFS2: Kill two daemons with one patch").
Fix this by only decrementing lru_count when we actually remove a glock
and schedule for it to be unlocked and dropped. We also don't need to
remove and then re-add glocks when we can just as well move them back
onto the lru_list when necessary.
In addition, return the number of glocks freed as we should, not the
number of glocks moved onto the dispose list.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/gfs2/glock.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 5b2fd5994cfc..4be140ab53e4 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1988,29 +1988,30 @@ static bool can_free_glock(struct gfs2_glock *gl)
* private)
*/
-static void gfs2_dispose_glock_lru(struct list_head *list)
+static long gfs2_dispose_glock_lru(struct list_head *list)
__releases(&lru_lock)
__acquires(&lru_lock)
{
struct gfs2_glock *gl;
+ long freed = 0;
list_sort(NULL, list, glock_cmp);
while(!list_empty(list)) {
gl = list_first_entry(list, struct gfs2_glock, gl_lru);
- list_del_init(&gl->gl_lru);
- clear_bit(GLF_LRU, &gl->gl_flags);
if (!spin_trylock(&gl->gl_lockref.lock)) {
add_back_to_lru:
- list_add(&gl->gl_lru, &lru_list);
- set_bit(GLF_LRU, &gl->gl_flags);
- atomic_inc(&lru_count);
+ list_move(&gl->gl_lru, &lru_list);
continue;
}
if (!can_free_glock(gl)) {
spin_unlock(&gl->gl_lockref.lock);
goto add_back_to_lru;
}
+ list_del_init(&gl->gl_lru);
+ atomic_dec(&lru_count);
+ clear_bit(GLF_LRU, &gl->gl_flags);
+ freed++;
gl->gl_lockref.count++;
if (gl->gl_state != LM_ST_UNLOCKED)
handle_callback(gl, LM_ST_UNLOCKED, 0, false);
@@ -2018,6 +2019,7 @@ __acquires(&lru_lock)
spin_unlock(&gl->gl_lockref.lock);
cond_resched_lock(&lru_lock);
}
+ return freed;
}
/**
@@ -2039,14 +2041,11 @@ static long gfs2_scan_glock_lru(int nr)
list_for_each_entry_safe(gl, next, &lru_list, gl_lru) {
if (nr-- <= 0)
break;
- if (can_free_glock(gl)) {
+ if (can_free_glock(gl))
list_move(&gl->gl_lru, &dispose);
- atomic_dec(&lru_count);
- freed++;
- }
}
if (!list_empty(&dispose))
- gfs2_dispose_glock_lru(&dispose);
+ freed = gfs2_dispose_glock_lru(&dispose);
spin_unlock(&lru_lock);
return freed;
--
2.44.0
prev parent reply other threads:[~2024-04-09 16:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-09 16:44 [PATCH 00/15] gfs2 cleanups and fixes Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 01/15] gfs2: Get rid of newlines in log messages Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 02/15] gfs2: Remove unnecessary gfs2_meta_check_ii argument Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 03/15] gfs2: Follow-up to flag rename in sysfs status file Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 04/15] gfs2: Use [NO_]CREATE consistently for gfs2_glock_get Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 05/15] gfs2: Don't forget to complete delayed withdraw Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 06/15] gfs2: Fix NULL pointer dereference in gfs2_log_flush Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 07/15] gfs2: Get rid of gfs2_glock_queue_put in signal_our_withdraw Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 08/15] gfs2: Replace gfs2_glock_queue_put with gfs2_glock_put_async Andreas Gruenbacher
2024-04-09 16:44 ` [PATCH 09/15] gfs2: Don't set GLF_LOCK in gfs2_dispose_glock_lru Andreas Gruenbacher
2024-04-09 16:45 ` [PATCH 10/15] gfs2: Get rid of unnecessary test_and_set_bit Andreas Gruenbacher
2024-04-09 16:45 ` [PATCH 11/15] gfs2: Fix "ignore unlock failures after withdraw" Andreas Gruenbacher
2024-04-09 16:45 ` [PATCH 12/15] Revert "gfs2: fix glock shrinker ref issues" Andreas Gruenbacher
2024-04-09 16:45 ` [PATCH 13/15] gfs2: Fix "Make glock lru list scanning safer" Andreas Gruenbacher
2024-04-16 16:55 ` Andrew Price
2024-04-17 7:55 ` Andreas Gruenbacher
2024-04-09 16:45 ` [PATCH 14/15] gfs2: Get rid of demote_ok checks Andreas Gruenbacher
2024-04-12 6:00 ` Andreas Gruenbacher
2024-04-09 16:45 ` Andreas Gruenbacher [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240409164508.79570-16-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=gfs2@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).