From: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
To: agruenba@redhat.com
Cc: gfs2@lists.linux.dev, linux-kernel@vger.kernel.org,
Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
Subject: [PATCH] gfs2: do not evict glocks with populated address spaces
Date: Tue, 23 Dec 2025 11:05:06 -0300 [thread overview]
Message-ID: <20251223140506.568643-1-trintaeoitogc@gmail.com> (raw)
Metadata glocks may have associated address spaces used as caches. Avoid
reclaiming such glocks under memory pressure while their mappings are
still populated or their state is not unlocked, as this can lead to
invalid page cache state and GLOCK_BUG_ON().
Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
---
fs/gfs2/glock.h | 30 ++++++++++++++++++++++++++++++
fs/gfs2/super.c | 3 +++
2 files changed, 33 insertions(+)
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 55d5985f32a0..12f57461f687 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -305,4 +305,34 @@ static inline bool glock_needs_demote(struct gfs2_glock *gl)
test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags));
}
+/*
+ * gfs2_glock_not_evictable - check if a glock is not evictable
+ * @gl: The glock to check
+ *
+ * Glocks which do not represent normal filesystem inodes (e.g. statfs, quota, rindex)
+ * may have associated address spaces used as metadata caches. These glocks must not
+ * be reclaimed under memory pressure while their mappings are still populated or their
+ * state is not unlocked.
+ */
+
+static inline bool gfs2_glock_not_evictable(struct gfs2_glock *gl)
+{
+ if (gl->gl_name.ln_type == LM_TYPE_INODE)
+ return false;
+
+ if (gl->gl_ops->go_flags & GLOF_ASPACE) {
+ struct gfs2_glock_aspace *gla;
+
+ gla = container_of(gl, struct gfs2_glock_aspace, glock);
+
+ if (!mapping_empty(&gla->mapping))
+ return true;
+ }
+
+ if (gl->gl_state != LM_ST_UNLOCKED)
+ return true;
+
+ return false;
+}
+
#endif /* __GLOCK_DOT_H__ */
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index f6cd907b3ec6..86544cdafe53 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1164,6 +1164,9 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root)
static void gfs2_glock_put_eventually(struct gfs2_glock *gl)
{
+ if (gfs2_glock_not_evictable(gl))
+ return;
+
if (current->flags & PF_MEMALLOC)
gfs2_glock_put_async(gl);
else
--
2.34.1
reply other threads:[~2025-12-23 14:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20251223140506.568643-1-trintaeoitogc@gmail.com \
--to=trintaeoitogc@gmail.com \
--cc=agruenba@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
/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