From: Andrew Price <anprice@redhat.com>
To: Andreas Gruenbacher <agruenba@redhat.com>
Cc: gfs2@lists.linux.dev
Subject: Re: [PATCH 13/15] gfs2: Fix "Make glock lru list scanning safer"
Date: Tue, 16 Apr 2024 17:55:54 +0100 [thread overview]
Message-ID: <f1c9bcc3-475f-4b1c-8a0a-078c200d31e2@redhat.com> (raw)
In-Reply-To: <20240409164508.79570-14-agruenba@redhat.com>
On 09/04/2024 17:45, Andreas Gruenbacher wrote:
> Commit 228804a35caa tried to add a refcount check to
> gfs2_scan_glock_lru() to make sure that glocks that are still referenced
> cannot be freed. It failed to account for the bias state_change() adds
> to the refcount for held glocks, so held glocks are no longer removed
> from the glock cache, which can lead to out-of-memory problems. Fix
> that. (The inodes those glocks are associated with do get shrunk and do
> get pushed out of memory.)
>
> In addition, use the same eligibility check in gfs2_scan_glock_lru() and
> gfs2_dispose_glock_lru().
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
> fs/gfs2/glock.c | 24 +++++++++++++-----------
> 1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
> index 2882a42e88aa..04e0a8ac61d7 100644
> --- a/fs/gfs2/glock.c
> +++ b/fs/gfs2/glock.c
> @@ -1987,6 +1987,14 @@ static int glock_cmp(void *priv, const struct list_head *a,
> return 0;
> }
>
> +static bool can_free_glock(struct gfs2_glock *gl)
> +{
> + bool held = gl->gl_state != LM_ST_UNLOCKED;
> +
> + return !test_bit(GLF_LOCK, &gl->gl_flags) &&
> + gl->gl_lockref.count == held;
Wouldn't this comparison go wrong when the lockref count is > 1? In any
case it's unusual to see a lockref count being compared to a bool.
Andy
> +}
> +
> /**
> * gfs2_dispose_glock_lru - Demote a list of glocks
> * @list: The list to dispose of
> @@ -2020,7 +2028,7 @@ __acquires(&lru_lock)
> atomic_inc(&lru_count);
> continue;
> }
> - if (test_bit(GLF_LOCK, &gl->gl_flags)) {
> + if (!can_free_glock(gl)) {
> spin_unlock(&gl->gl_lockref.lock);
> goto add_back_to_lru;
> }
> @@ -2052,16 +2060,10 @@ static long gfs2_scan_glock_lru(int nr)
> list_for_each_entry_safe(gl, next, &lru_list, gl_lru) {
> if (nr-- <= 0)
> break;
> - /* Test for being demotable */
> - if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
> - if (!spin_trylock(&gl->gl_lockref.lock))
> - continue;
> - if (!gl->gl_lockref.count) {
> - list_move(&gl->gl_lru, &dispose);
> - atomic_dec(&lru_count);
> - freed++;
> - }
> - spin_unlock(&gl->gl_lockref.lock);
> + if (can_free_glock(gl)) {
> + list_move(&gl->gl_lru, &dispose);
> + atomic_dec(&lru_count);
> + freed++;
> }
> }
> if (!list_empty(&dispose))
next prev parent reply other threads:[~2024-04-16 16:56 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 [this message]
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 ` [PATCH 15/15] gfs2: Fix lru_count accounting Andreas Gruenbacher
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=f1c9bcc3-475f-4b1c-8a0a-078c200d31e2@redhat.com \
--to=anprice@redhat.com \
--cc=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).