mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryusuke Konishi <konishi.ryusuke@gmail.com>
To: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: Wang Jianjian <wangjianjian3@huawei.com>,
	linux-nilfs <linux-nilfs@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Zheng Zheng <fengaojigui88@gmail.com>,
	Joshua Crofts <joshua.crofts1@gmail.com>
Subject: [PATCH 8/8] nilfs2: avoid infinite retry loop on GC failure
Date: Fri, 27 Nov 2026 13:41:01 +0900	[thread overview]
Message-ID: <20261127044231.37630-9-konishi.ryusuke@gmail.com> (raw)
In-Reply-To: <20261127044231.37630-1-konishi.ryusuke@gmail.com>

Currently, the GC loop in nilfs_clean_segments() only breaks out when
nilfs_segctor_construct() returns -EROFS, continuing to retry on any
other error.  When a persistent or non-retryable error such as -EIO or
-ENOSPC occurs during log writing due to filesystem corruption, I/O
errors, or free space exhaustion, this loop can spin indefinitely while
holding the transaction lock, leading to task hangs.

Now that GC-specific state changes can be selectively reverted on log
writing failure to preserve filesystem consistency for subsequent
operations, modify nilfs_clean_segments() to abort immediately on
errors in general, leaving only a minimal retry loop bounded by
NILFS_GC_RETRY_LIMIT for -EAGAIN and -EBUSY.

Fixes: ce5a5ad1a833 ("nilfs2: fix infinite loop in nilfs_clean_segments()")
Reported-by: Zheng Zheng <fengaojigui88@gmail.com>
Closes: https://lore.kernel.org/linux-nilfs/CAO-4RZ1Q-HzRCd+S1uHZJRdN-ZCtv47f=pXTxbq4YaJgn_DALQ@mail.gmail.com
Closes: https://lore.kernel.org/linux-nilfs/CAO-4RZ2pjEOpTBzqca5UxZHtaFS2Dj9zmNj1BtjvKm1yFE7_Jg@mail.gmail.com
Cc: stable@vger.kernel.org
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
 fs/nilfs2/segment.c | 9 ++++++++-
 fs/nilfs2/segment.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index b306f09c9497..5765959617fe 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -2582,6 +2582,7 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
 	size_t susz = NILFS_MDT(nilfs->ns_sufile)->mi_entry_size;
 	__u64 *segnumv = kbufs[4];
 	void *subuf = NULL;
+	unsigned int retries = 0;
 
 	if (unlikely(!sci))
 		return -EROFS;
@@ -2644,7 +2645,13 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
 
 		nilfs_warn(sb, "error %d cleaning segments", err);
 
-		if (unlikely(err == -EROFS))
+		/*
+		 * Although the log writer should not have any paths returning
+		 * retryable errors (-EAGAIN or -EBUSY), keep a bounded retry
+		 * path conservatively.
+		 */
+		if ((err != -EAGAIN && err != -EBUSY) ||
+			retries++ >= NILFS_GC_RETRY_LIMIT)
 			goto out_unlock;
 
 		set_current_state(TASK_INTERRUPTIBLE);
diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h
index 711c69e24575..4158948d890d 100644
--- a/fs/nilfs2/segment.h
+++ b/fs/nilfs2/segment.h
@@ -204,6 +204,7 @@ enum {
 					* Retry count of construction when
 					* destroying segctord
 					*/
+#define NILFS_GC_RETRY_LIMIT	    2  /* Number of internal GC retries */
 
 /*
  * Default values of timeout, in seconds.
-- 
2.53.0


      parent reply	other threads:[~2026-11-27  4:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  4:40 [PATCH 0/8] nilfs2: support GC error rollback and avoid infinite retry hangs Ryusuke Konishi
2026-11-27  4:40 ` [PATCH 1/8] nilfs2: fix leak of gc inodes on error Ryusuke Konishi
2026-11-27  4:40 ` [PATCH 2/8] nilfs2: cancel the relocation of GC-targeted blocks if log writing fails Ryusuke Konishi
2026-11-27  4:40 ` [PATCH 3/8] nilfs2: restore segment usage from the save buffer when aborting GC Ryusuke Konishi
2026-11-27  4:40 ` [PATCH 4/8] nilfs2: drop redirected buffer flag from DAT when clearing shadow map Ryusuke Konishi
2026-11-27  4:40 ` [PATCH 5/8] nilfs2: save DAT entry blocks to shadow mapping before freeing Ryusuke Konishi
2026-11-27  4:40 ` [PATCH 6/8] nilfs2: restore removed DAT entries when aborting GC Ryusuke Konishi
2026-11-27  4:41 ` [PATCH 7/8] nilfs2: free virtual block numbers just before collecting DAT changes Ryusuke Konishi
2026-11-27  4:41 ` Ryusuke Konishi [this message]

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=20261127044231.37630-9-konishi.ryusuke@gmail.com \
    --to=konishi.ryusuke@gmail.com \
    --cc=fengaojigui88@gmail.com \
    --cc=joshua.crofts1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nilfs@vger.kernel.org \
    --cc=slava@dubeyko.com \
    --cc=wangjianjian3@huawei.com \
    /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®