Skip to contentSkip to conversation

ocfs2: unregister the JBD2 shrinker before journal shutdown

PATCH In review Andrew Morton 2 participants 4 messages Nov 22 – Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: unregister the JBD2 shrinker before journal shutdown

From: Andrew Morton <[email protected]>
Subject: ocfs2: unregister the JBD2 shrinker before journal shutdown
Date: Sat, 21 Nov 2026 19:34:56 -0800

sysbot reports a lockdep cycle through shrinker_mutex, filesystem reclaim and osb->journal_shutdown_sem. Unmount holds the superblock's s_umount exclusively, while the OCFS2 reclaim path must first get its read side with super_trylock_shared(). That excludes the two paths for the same superblock; the report does not establish a runtime deadlock. Still, the lock ordering is visible to lockdep and produces the warning.

The write side of journal_shutdown_sem must cover all of jbd2_journal_destroy(): ocfs2_clear_inode() can otherwise release a JBD2 inode through a journal that is being destroyed. Move only the JBD2 shrinker unregister operation before taking the semaphore. shrinker_free() waits for active shrinker users, so the journal and its checkpoint counter remain alive while they finish. A successfully initialized JBD2 journal always has a checkpoint counter. Destroy it after unregistering the shrinker, whether unregistering happened here or before taking the OCFS2 semaphore. The semaphore continues to protect JBD2 destruction, removal of osb->journal and freeing the OCFS2 journal.

The userspace-visible result is removal of this lockdep warning during OCFS2 unmount; the report does not demonstrate a hung unmount.

---
Tested with CONFIG_PROVE_LOCKING=y in x86-64 QEMU guests. A omitted this patch; B added it alone. OCFS2 and JBD2 were built in.

Syzbot's C reproducer mounted a local OCFS2 image, accessed 200 files, exercised reclaim and unmounted it. A reproduced the reported circular locking warning: shrinker_free() ran from jbd2_journal_destroy() while ocfs2_journal_shutdown() held journal_shutdown_sem. The unmount completed; this test did not show a runtime deadlock.

B completed the same sequence without a warning. Three further mount/reclaim/unmount cycles on B also completed without warnings. An ext4 read/write/unmount control passed on both kernels.

Both builds needed the same temporary correction for an unrelated mm/util.c compile error in another queued patch. The correction was removed after testing. The test did not force an active JBD2 shrinker callback to overlap unmount or exercise failed-mount cleanup.

 fs/jbd2/journal.c    |   17 +++++++++++++----
 fs/ocfs2/journal.c   |    1 +
 include/linux/jbd2.h |    1 +
 3 files changed, 15 insertions(+), 4 deletions(-)
fs/jbd2/journal.c renamed from fs/jbd2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +13 -4
@@ -75,6 +75,7 @@ EXPORT_SYMBOL(jbd2_journal_check_availab
 EXPORT_SYMBOL(jbd2_journal_set_features);
 EXPORT_SYMBOL(jbd2_journal_load);
 EXPORT_SYMBOL(jbd2_journal_destroy);
+EXPORT_SYMBOL(jbd2_journal_unregister_shrinker);
 EXPORT_SYMBOL(jbd2_journal_abort);
 EXPORT_SYMBOL(jbd2_journal_errno);
 EXPORT_SYMBOL(jbd2_journal_ack_err);
@@ -2100,6 +2101,16 @@ int jbd2_journal_load(journal_t *journal
 	return 0;
 }
 
+void jbd2_journal_unregister_shrinker(journal_t *journal)
+{
+	struct shrinker *shrinker = journal->j_shrinker;
+
+	if (!shrinker)
+		return;
+	journal->j_shrinker = NULL;
+	shrinker_free(shrinker);
+}
+
 /**
  * jbd2_journal_destroy() - Release a journal_t structure.
  * @journal: Journal to act on.
@@ -2173,10 +2184,8 @@ int jbd2_journal_destroy(journal_t *jour
 		brelse(journal->j_sb_buffer);
 	}
 
-	if (journal->j_shrinker) {
-		percpu_counter_destroy(&journal->j_checkpoint_jh_count);
-		shrinker_free(journal->j_shrinker);
-	}
+	jbd2_journal_unregister_shrinker(journal);
+	percpu_counter_destroy(&journal->j_checkpoint_jh_count);
 	if (journal->j_proc_entry)
 		jbd2_stats_proc_exit(journal);
 	iput(journal->j_inode);
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1119,6 +1119,7 @@ void ocfs2_journal_shutdown(struct ocfs2
 	 * Exclude the final JBD2 inode cleanup in ocfs2_clear_inode() while
 	 * the journal is destroyed and freed.
 	 */
+	jbd2_journal_unregister_shrinker(journal->j_journal);
 	down_write(&osb->journal_shutdown_sem);
 
 	/* Shutdown the kernel journal system */
include/linux/jbd2.h renamed from include/linux/jbd2.h~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1566,6 +1566,7 @@ extern void	   jbd2_journal_clear_featur
 		   (journal_t *, unsigned long, unsigned long, unsigned long);
 extern int	   jbd2_journal_load       (journal_t *journal);
 extern int	   jbd2_journal_destroy    (journal_t *);
+extern void	   jbd2_journal_unregister_shrinker(journal_t *);
 extern int	   jbd2_journal_recover    (journal_t *journal);
 extern int	   jbd2_journal_wipe       (journal_t *, int);
 extern int	   jbd2_journal_skip_recovery	(journal_t *);

_

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 107 lines · Andrew Morton

From: Andrew Morton <[email protected]>
Subject: ocfs2: unregister the JBD2 shrinker before journal shutdown
Date: Sat, 21 Nov 2026 19:34:56 -0800

sysbot reports a lockdep cycle through shrinker_mutex, filesystem reclaim and osb->journal_shutdown_sem. Unmount holds the superblock's s_umount exclusively, while the OCFS2 reclaim path must first get its read side with super_trylock_shared(). That excludes the two paths for the same superblock; the report does not establish a runtime deadlock. Still, the lock ordering is visible to lockdep and produces the warning.

The write side of journal_shutdown_sem must cover all of jbd2_journal_destroy(): ocfs2_clear_inode() can otherwise release a JBD2 inode through a journal that is being destroyed. Move only the JBD2 shrinker unregister operation before taking the semaphore. shrinker_free() waits for active shrinker users, so the journal and its checkpoint counter remain alive while they finish. A successfully initialized JBD2 journal always has a checkpoint counter. Destroy it after unregistering the shrinker, whether unregistering happened here or before taking the OCFS2 semaphore. The semaphore continues to protect JBD2 destruction, removal of osb->journal and freeing the OCFS2 journal.

The userspace-visible result is removal of this lockdep warning during OCFS2 unmount; the report does not demonstrate a hung unmount.

---
Tested with CONFIG_PROVE_LOCKING=y in x86-64 QEMU guests. A omitted this patch; B added it alone. OCFS2 and JBD2 were built in.

Syzbot's C reproducer mounted a local OCFS2 image, accessed 200 files, exercised reclaim and unmounted it. A reproduced the reported circular locking warning: shrinker_free() ran from jbd2_journal_destroy() while ocfs2_journal_shutdown() held journal_shutdown_sem. The unmount completed; this test did not show a runtime deadlock.

B completed the same sequence without a warning. Three further mount/reclaim/unmount cycles on B also completed without warnings. An ext4 read/write/unmount control passed on both kernels.

Both builds needed the same temporary correction for an unrelated mm/util.c compile error in another queued patch. The correction was removed after testing. The test did not force an active JBD2 shrinker callback to overlap unmount or exercise failed-mount cleanup.

 fs/jbd2/journal.c    |   17 +++++++++++++----
 fs/ocfs2/journal.c   |    1 +
 include/linux/jbd2.h |    1 +
 3 files changed, 15 insertions(+), 4 deletions(-)
fs/jbd2/journal.c renamed from fs/jbd2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +13 -4
@@ -75,6 +75,7 @@ EXPORT_SYMBOL(jbd2_journal_check_availab
 EXPORT_SYMBOL(jbd2_journal_set_features);
 EXPORT_SYMBOL(jbd2_journal_load);
 EXPORT_SYMBOL(jbd2_journal_destroy);
+EXPORT_SYMBOL(jbd2_journal_unregister_shrinker);
 EXPORT_SYMBOL(jbd2_journal_abort);
 EXPORT_SYMBOL(jbd2_journal_errno);
 EXPORT_SYMBOL(jbd2_journal_ack_err);
@@ -2100,6 +2101,16 @@ int jbd2_journal_load(journal_t *journal
 	return 0;
 }
 
+void jbd2_journal_unregister_shrinker(journal_t *journal)
+{
+	struct shrinker *shrinker = journal->j_shrinker;
+
+	if (!shrinker)
+		return;
+	journal->j_shrinker = NULL;
+	shrinker_free(shrinker);
+}
+
 /**
  * jbd2_journal_destroy() - Release a journal_t structure.
  * @journal: Journal to act on.
@@ -2173,10 +2184,8 @@ int jbd2_journal_destroy(journal_t *jour
 		brelse(journal->j_sb_buffer);
 	}
 
-	if (journal->j_shrinker) {
-		percpu_counter_destroy(&journal->j_checkpoint_jh_count);
-		shrinker_free(journal->j_shrinker);
-	}
+	jbd2_journal_unregister_shrinker(journal);
+	percpu_counter_destroy(&journal->j_checkpoint_jh_count);
 	if (journal->j_proc_entry)
 		jbd2_stats_proc_exit(journal);
 	iput(journal->j_inode);

fs/ocfs2/journal.c void ocfs2_journal_shutdown(struct ocfs2 · line 1122

Quoted 4 lines
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1119,6 +1119,7 @@ void ocfs2_journal_shutdown(struct ocfs2
 	 * Exclude the final JBD2 inode cleanup in ocfs2_clear_inode() while
 	 * the journal is destroyed and freed.
 	 */
+	jbd2_journal_unregister_shrinker(journal->j_journal);

The comment above just explains why down_write() is taken, and the new jbd2_journal_unregister_shrinker() call is outside the exclusion the comment describes.
So it seems we'd better move the new call above the comment, or carry a short note that it must stay outside journal_shutdown_sem.

Other looks good.

Quoted 14 lines
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +0 -0
 	down_write(&osb->journal_shutdown_sem);
 
 	/* Shutdown the kernel journal system */
include/linux/jbd2.h renamed from include/linux/jbd2.h~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1566,6 +1566,7 @@ extern void	   jbd2_journal_clear_featur
 		   (journal_t *, unsigned long, unsigned long, unsigned long);
 extern int	   jbd2_journal_load       (journal_t *journal);
 extern int	   jbd2_journal_destroy    (journal_t *);
+extern void	   jbd2_journal_unregister_shrinker(journal_t *);
 extern int	   jbd2_journal_recover    (journal_t *journal);
 extern int	   jbd2_journal_wipe       (journal_t *, int);
 extern int	   jbd2_journal_skip_recovery	(journal_t *);

_

author Tested-by Reviewed-by Joseph Qi
#2 lore raw
Quoted 16 lines · On Mon, 23 Nov 2026 09:56:36 +0800 Joseph Qi <[email protected]>…

fs/ocfs2/journal.c void ocfs2_journal_shutdown(struct ocfs2 · line 1122

Quoted 9 lines
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1119,6 +1119,7 @@ void ocfs2_journal_shutdown(struct ocfs2
 	 * Exclude the final JBD2 inode cleanup in ocfs2_clear_inode() while
 	 * the journal is destroyed and freed.
 	 */
+	jbd2_journal_unregister_shrinker(journal->j_journal);

The comment above just explains why down_write() is taken, and the new jbd2_journal_unregister_shrinker() call is outside the exclusion the comment describes.
So it seems we'd better move the new call above the comment, or carry a short note that it must stay outside journal_shutdown_sem.

Thanks, this?

From: Andrew Morton <[email protected]>
Subject: ocfs2: unregister the JBD2 shrinker before journal shutdown
Date: Sat, 21 Nov 2026 19:34:56 -0800

sysbot reports a lockdep cycle through shrinker_mutex, filesystem reclaim and osb->journal_shutdown_sem. Unmount holds the superblock's s_umount exclusively, while the OCFS2 reclaim path must first get its read side with super_trylock_shared(). That excludes the two paths for the same superblock; the report does not establish a runtime deadlock. Still, the lock ordering is visible to lockdep and produces the warning.

The write side of journal_shutdown_sem must cover all of jbd2_journal_destroy(): ocfs2_clear_inode() can otherwise release a JBD2 inode through a journal that is being destroyed. Move only the JBD2 shrinker unregister operation before taking the semaphore. shrinker_free() waits for active shrinker users, so the journal and its checkpoint counter remain alive while they finish. A successfully initialized JBD2 journal always has a checkpoint counter. Destroy it after unregistering the shrinker, whether unregistering happened here or before taking the OCFS2 semaphore. The semaphore continues to protect JBD2 destruction, removal of osb->journal and freeing the OCFS2 journal.

The userspace-visible result is removal of this lockdep warning during OCFS2 unmount; the report does not demonstrate a hung unmount.

---
Tested with CONFIG_PROVE_LOCKING=y in x86-64 QEMU guests. A omitted this patch; B added it alone. OCFS2 and JBD2 were built in.

Syzbot's C reproducer mounted a local OCFS2 image, accessed 200 files, exercised reclaim and unmounted it. A reproduced the reported circular locking warning: shrinker_free() ran from jbd2_journal_destroy() while ocfs2_journal_shutdown() held journal_shutdown_sem. The unmount completed; this test did not show a runtime deadlock.

B completed the same sequence without a warning. Three further mount/reclaim/unmount cycles on B also completed without warnings. An ext4 read/write/unmount control passed on both kernels.

Both builds needed the same temporary correction for an unrelated mm/util.c compile error in another queued patch. The correction was removed after testing. The test did not force an active JBD2 shrinker callback to overlap unmount or exercise failed-mount cleanup.

 fs/jbd2/journal.c    |   17 +++++++++++++----
 fs/ocfs2/journal.c   |    1 +
 include/linux/jbd2.h |    1 +
 3 files changed, 15 insertions(+), 4 deletions(-)
fs/jbd2/journal.c renamed from fs/jbd2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +13 -4
@@ -75,6 +75,7 @@ EXPORT_SYMBOL(jbd2_journal_check_availab
 EXPORT_SYMBOL(jbd2_journal_set_features);
 EXPORT_SYMBOL(jbd2_journal_load);
 EXPORT_SYMBOL(jbd2_journal_destroy);
+EXPORT_SYMBOL(jbd2_journal_unregister_shrinker);
 EXPORT_SYMBOL(jbd2_journal_abort);
 EXPORT_SYMBOL(jbd2_journal_errno);
 EXPORT_SYMBOL(jbd2_journal_ack_err);
@@ -2100,6 +2101,16 @@ int jbd2_journal_load(journal_t *journal
 	return 0;
 }
 
+void jbd2_journal_unregister_shrinker(journal_t *journal)
+{
+	struct shrinker *shrinker = journal->j_shrinker;
+
+	if (!shrinker)
+		return;
+	journal->j_shrinker = NULL;
+	shrinker_free(shrinker);
+}
+
 /**
  * jbd2_journal_destroy() - Release a journal_t structure.
  * @journal: Journal to act on.
@@ -2173,10 +2184,8 @@ int jbd2_journal_destroy(journal_t *jour
 		brelse(journal->j_sb_buffer);
 	}
 
-	if (journal->j_shrinker) {
-		percpu_counter_destroy(&journal->j_checkpoint_jh_count);
-		shrinker_free(journal->j_shrinker);
-	}
+	jbd2_journal_unregister_shrinker(journal);
+	percpu_counter_destroy(&journal->j_checkpoint_jh_count);
 	if (journal->j_proc_entry)
 		jbd2_stats_proc_exit(journal);
 	iput(journal->j_inode);
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1115,6 +1115,7 @@ void ocfs2_journal_shutdown(struct ocfs2
 			mlog_errno(status);
 	}
 
+	jbd2_journal_unregister_shrinker(journal->j_journal);
 	/*
 	 * Exclude the final JBD2 inode cleanup in ocfs2_clear_inode() while
 	 * the journal is destroyed and freed.
include/linux/jbd2.h renamed from include/linux/jbd2.h~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1566,6 +1566,7 @@ extern void	   jbd2_journal_clear_featur
 		   (journal_t *, unsigned long, unsigned long, unsigned long);
 extern int	   jbd2_journal_load       (journal_t *journal);
 extern int	   jbd2_journal_destroy    (journal_t *);
+extern void	   jbd2_journal_unregister_shrinker(journal_t *);
 extern int	   jbd2_journal_recover    (journal_t *journal);
 extern int	   jbd2_journal_wipe       (journal_t *, int);
 extern int	   jbd2_journal_skip_recovery	(journal_t *);

_

maintainer
#3 lore raw
Quoted 19 lines · Andrew Morton
Quoted 16 lines · On Mon, 23 Nov 2026 09:56:36 +0800 Joseph Qi <[email protected]>…

fs/ocfs2/journal.c void ocfs2_journal_shutdown(struct ocfs2 · line 1122

Quoted 9 lines
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1119,6 +1119,7 @@ void ocfs2_journal_shutdown(struct ocfs2
 	 * Exclude the final JBD2 inode cleanup in ocfs2_clear_inode() while
 	 * the journal is destroyed and freed.
 	 */
+	jbd2_journal_unregister_shrinker(journal->j_journal);

The comment above just explains why down_write() is taken, and the new jbd2_journal_unregister_shrinker() call is outside the exclusion the comment describes.
So it seems we'd better move the new call above the comment, or carry a short note that it must stay outside journal_shutdown_sem.

Quoted 2 lines

Thanks, this?

Yes, it's fine now.

Thanks,
Joseph

Quoted 125 lines

From: Andrew Morton <[email protected]>
Subject: ocfs2: unregister the JBD2 shrinker before journal shutdown
Date: Sat, 21 Nov 2026 19:34:56 -0800

sysbot reports a lockdep cycle through shrinker_mutex, filesystem reclaim and osb->journal_shutdown_sem. Unmount holds the superblock's s_umount exclusively, while the OCFS2 reclaim path must first get its read side with super_trylock_shared(). That excludes the two paths for the same superblock; the report does not establish a runtime deadlock. Still, the lock ordering is visible to lockdep and produces the warning.

The write side of journal_shutdown_sem must cover all of jbd2_journal_destroy(): ocfs2_clear_inode() can otherwise release a JBD2 inode through a journal that is being destroyed. Move only the JBD2 shrinker unregister operation before taking the semaphore. shrinker_free() waits for active shrinker users, so the journal and its checkpoint counter remain alive while they finish. A successfully initialized JBD2 journal always has a checkpoint counter. Destroy it after unregistering the shrinker, whether unregistering happened here or before taking the OCFS2 semaphore. The semaphore continues to protect JBD2 destruction, removal of osb->journal and freeing the OCFS2 journal.

The userspace-visible result is removal of this lockdep warning during OCFS2 unmount; the report does not demonstrate a hung unmount.

---
Tested with CONFIG_PROVE_LOCKING=y in x86-64 QEMU guests. A omitted this patch; B added it alone. OCFS2 and JBD2 were built in.

Syzbot's C reproducer mounted a local OCFS2 image, accessed 200 files, exercised reclaim and unmounted it. A reproduced the reported circular locking warning: shrinker_free() ran from jbd2_journal_destroy() while ocfs2_journal_shutdown() held journal_shutdown_sem. The unmount completed; this test did not show a runtime deadlock.

B completed the same sequence without a warning. Three further mount/reclaim/unmount cycles on B also completed without warnings. An ext4 read/write/unmount control passed on both kernels.

Both builds needed the same temporary correction for an unrelated mm/util.c compile error in another queued patch. The correction was removed after testing. The test did not force an active JBD2 shrinker callback to overlap unmount or exercise failed-mount cleanup.

 fs/jbd2/journal.c    |   17 +++++++++++++----
 fs/ocfs2/journal.c   |    1 +
 include/linux/jbd2.h |    1 +
 3 files changed, 15 insertions(+), 4 deletions(-)
fs/jbd2/journal.c renamed from fs/jbd2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +13 -4
@@ -75,6 +75,7 @@ EXPORT_SYMBOL(jbd2_journal_check_availab
 EXPORT_SYMBOL(jbd2_journal_set_features);
 EXPORT_SYMBOL(jbd2_journal_load);
 EXPORT_SYMBOL(jbd2_journal_destroy);
+EXPORT_SYMBOL(jbd2_journal_unregister_shrinker);
 EXPORT_SYMBOL(jbd2_journal_abort);
 EXPORT_SYMBOL(jbd2_journal_errno);
 EXPORT_SYMBOL(jbd2_journal_ack_err);
@@ -2100,6 +2101,16 @@ int jbd2_journal_load(journal_t *journal
 	return 0;
 }
 
+void jbd2_journal_unregister_shrinker(journal_t *journal)
+{
+	struct shrinker *shrinker = journal->j_shrinker;
+
+	if (!shrinker)
+		return;
+	journal->j_shrinker = NULL;
+	shrinker_free(shrinker);
+}
+
 /**
  * jbd2_journal_destroy() - Release a journal_t structure.
  * @journal: Journal to act on.
@@ -2173,10 +2184,8 @@ int jbd2_journal_destroy(journal_t *jour
 		brelse(journal->j_sb_buffer);
 	}
 
-	if (journal->j_shrinker) {
-		percpu_counter_destroy(&journal->j_checkpoint_jh_count);
-		shrinker_free(journal->j_shrinker);
-	}
+	jbd2_journal_unregister_shrinker(journal);
+	percpu_counter_destroy(&journal->j_checkpoint_jh_count);
 	if (journal->j_proc_entry)
 		jbd2_stats_proc_exit(journal);
 	iput(journal->j_inode);
fs/ocfs2/journal.c renamed from fs/ocfs2/journal.c~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1115,6 +1115,7 @@ void ocfs2_journal_shutdown(struct ocfs2
 			mlog_errno(status);
 	}
 
+	jbd2_journal_unregister_shrinker(journal->j_journal);
 	/*
 	 * Exclude the final JBD2 inode cleanup in ocfs2_clear_inode() while
 	 * the journal is destroyed and freed.
include/linux/jbd2.h renamed from include/linux/jbd2.h~ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown +1 -0
@@ -1566,6 +1566,7 @@ extern void	   jbd2_journal_clear_featur
 		   (journal_t *, unsigned long, unsigned long, unsigned long);
 extern int	   jbd2_journal_load       (journal_t *journal);
 extern int	   jbd2_journal_destroy    (journal_t *);
+extern void	   jbd2_journal_unregister_shrinker(journal_t *);
 extern int	   jbd2_journal_recover    (journal_t *journal);
 extern int	   jbd2_journal_wipe       (journal_t *, int);
 extern int	   jbd2_journal_skip_recovery	(journal_t *);

_