All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gfs2: skip gfs2_dirty_inode in PF_MEMALLOC context
@ 2026-12-05 17:04 Jiaming Zhang
  2026-12-05 17:21 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Jiaming Zhang @ 2026-12-05 17:04 UTC (permalink / raw)
  To: Andreas Gruenbacher, gfs2
  Cc: Theodore Ts'o, Al Viro, linux-kernel, Jiaming Zhang, stable

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gfs2: skip gfs2_dirty_inode in PF_MEMALLOC context
  2026-12-05 17:04 [PATCH] gfs2: skip gfs2_dirty_inode in PF_MEMALLOC context Jiaming Zhang
@ 2026-12-05 17:21 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 17:21 UTC (permalink / raw)
  To: Jiaming Zhang, Andreas Gruenbacher, gfs2; +Cc: Theodore Ts'o, Al Viro

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] gfs2: early PF_MEMALLOC return in gfs2_dirty_inode() loses
  lazytime timestamps
- [Medium] gfs2: wrong-layer PF_MEMALLOC skip in gfs2_dirty_inode()
  loses lazytime
--

commit c1c530e233dcbc62874e126ec2bff49723b1b936
Author: Jiaming Zhang <r772577952@gmail.com>

gfs2: skip gfs2_dirty_inode in PF_MEMALLOC context

This patch adds an early return to gfs2_dirty_inode() when PF_MEMALLOC
is set in current->flags, avoiding glock acquisition and metadata buffer
allocation during memory reclaim.

> diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
> index 04bb4cf787d4d..3ec6599a36e68 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;

[Severity: High]
Can this early return permanently lose lazytime timestamp updates?

When dentry reclaim drops a linked inode under PF_MEMALLOC, iput() ->
sync_lazytime() -> __mark_inode_dirty() clears I_DIRTY_TIME before
calling gfs2_dirty_inode().  Returning here skips gfs2_dinode_out(),
and gfs2_write_inode() never serializes the dinode.

Because I_DIRTY_TIME is already clear, later fsync(), sync(), or
unmount never writes the updated mtime, ctime, or atime to disk, so
they are lost once the inode is evicted.

Unlike gfs2_drop_inode() and gfs2_glock_put_eventually(), this discards
metadata instead of deferring work, while __mark_inode_dirty() still
sets I_DIRTY_SYNC and triggers a wasted gfs2_write_inode() flush.

[Severity: Medium]
Should this PF_MEMALLOC reclaim hazard be fixed in VFS iput() rather
than inside gfs2_dirty_inode()?

iput() calls sync_lazytime() under PF_MEMALLOC and retries if
I_DIRTY_TIME stays set, so filesystems cannot leave it set in
->dirty_inode().  XFS (xfs_vn_sync_lazytime()), ext4
(ext4_dirty_inode()), and nilfs2 hit the same __GFP_NOFAIL hazard here.

Deferring sync_lazytime() in iput()/iput_final() under PF_MEMALLOC for
normal cached linked inodes (while still handling immediate-eviction
cases like drop or I_DONTCACHE) would leave the inode on
wb->b_dirty_time for non-PF_MEMALLOC writeback across all filesystems.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205170424.3686244-1-r772577952@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 17:04 [PATCH] gfs2: skip gfs2_dirty_inode in PF_MEMALLOC context Jiaming Zhang
2026-12-05 17:21 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.