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 --- 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