mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiaming Zhang <r772577952@gmail.com>
To: Andreas Gruenbacher <agruenba@redhat.com>, gfs2@lists.linux.dev
Cc: Theodore Ts'o <tytso@mit.edu>, Al Viro <viro@zeniv.linux.org.uk>,
	linux-kernel@vger.kernel.org,
	Jiaming Zhang <r772577952@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] gfs2: skip gfs2_dirty_inode in PF_MEMALLOC context
Date: Sun,  6 Dec 2026 01:04:24 +0800	[thread overview]
Message-ID: <20261205170424.3686244-1-r772577952@gmail.com> (raw)

When VFS marks an inode dirty, gfs2_dirty_inode() writes updated inode
fields to the GFS2 journal by locking the inode's cluster lock (glock),
starting a transaction, and reading the inode metadata buffer, assuming
the caller is not running memory reclaim:

	if (gfs2_withdrawn(sdp))
		return;
	if (!gfs2_glock_is_locked_by_me(gl)) {
		ret = gfs2_glock_nq_init(gl, LM_ST_EXCLUSIVE, 0, &gh);

When a filesystem is mounted with MS_LAZYTIME, timestamp updates only
set I_DIRTY_TIME on the in-memory inode instead of writing metadata
right away.  Since commit 0ae45f63d4ef ("vfs: add support for a lazytime
mount option"), dropping the last reference to a linked inode in iput()
flushes I_DIRTY_TIME via mark_inode_dirty_sync() into ->dirty_inode().

During memory reclaim, tasks run with PF_MEMALLOC set and shrink cached
dentries via shrink_dentry_list(), calling iput() and gfs2_dirty_inode()
under PF_MEMALLOC.  When the inode's metadata folio is no longer cached
in the glock address space, refreshing the glock or reading the inode
buffer calls gfs2_getbuf(), passing __GFP_NOFAIL to __filemap_get_folio().

A PF_MEMALLOC task cannot enter direct reclaim to free pages for itself.
When free memory sits below watermarks, that __GFP_NOFAIL request hits
WARN_ON_ONCE(current->flags & PF_MEMALLOC) in __alloc_pages_slowpath()
and can loop forever once reserves run out, while locking glocks under
PF_MEMALLOC can also deadlock with the distributed lock manager (DLM).

Triggering this requires a GFS2 filesystem mounted with MS_LAZYTIME
(CAP_SYS_ADMIN to mount an image, or unprivileged file access and memory
pressure once such a filesystem is mounted).

Return early from gfs2_dirty_inode() when PF_MEMALLOC is set on
current->flags, matching GFS2's existing PF_MEMALLOC guards in
fs/gfs2/super.c so opportunistic lazytime flushes during dcache reclaim
neither block on glocks nor issue __GFP_NOFAIL metadata allocations.

Fixes: 0ae45f63d4ef ("vfs: add support for a lazytime mount option")
Closes: https://lore.kernel.org/lkml/CANypQFYMFA8zM_PE+0omF7neUmXFJ+iHJLxpkAhWgsx_6ObCcg@mail.gmail.com/T/#u
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:Gemini
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
 fs/gfs2/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 04bb4cf787d4..3ec6599a36e6 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -497,6 +497,8 @@ static void gfs2_dirty_inode(struct inode *inode, int flags)
 
 	if (gfs2_withdrawn(sdp))
 		return;
+	if (current->flags & PF_MEMALLOC)
+		return;
 	if (!gfs2_glock_is_locked_by_me(gl)) {
 		ret = gfs2_glock_nq_init(gl, LM_ST_EXCLUSIVE, 0, &gh);
 		if (ret) {

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.43.0


                 reply	other threads:[~2026-12-05 17:04 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=20261205170424.3686244-1-r772577952@gmail.com \
    --to=r772577952@gmail.com \
    --cc=agruenba@redhat.com \
    --cc=gfs2@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®