Root Cause Analysis
Lockdep reports a 3-lock circular dependency cycle:
shrinker_mutex -> fs_reclaim -> &osb->journal_shutdown_sem -> shrinker_mutex
1. &osb->journal_shutdown_sem -> shrinker_mutex
During unmount (cleanup_mnt() -> deactivate_locked_super() -> kill_block_super() -> generic_shutdown_super() -> ocfs2_put_super() -> ocfs2_dismount_volume()), or during mount error cleanup in ocfs2_fill_super() / ocfs2_mount_volume(), OCFS2 calls ocfs2_journal_shutdown() (fs/ocfs2/journal.c:1064).
In ocfs2_journal_shutdown():
down_write(&osb->journal_shutdown_sem) is acquired at fs/ocfs2/journal.c:1122 to exclude concurrent jbd2_journal_release_jbd_inode() calls in ocfs2_clear_inode() while osb->journal and its underlying journal_t (journal->j_journal) are being torn down.
- While still holding
osb->journal_shutdown_sem in write mode, it calls jbd2_journal_destroy(journal->j_journal) (fs/ocfs2/journal.c:1125).
jbd2_journal_destroy() (fs/jbd2/journal.c:2178) calls shrinker_free(journal->j_shrinker).
shrinker_free() (mm/shrinker.c:809) acquires mutex_lock(&shrinker_mutex).
2. shrinker_mutex -> fs_reclaim
mm/shrinker.c acquires shrinker_mutex around GFP_KERNEL allocations (which acquire the fs_reclaim pseudo-lock), for example in alloc_shrinker_info() (mm/shrinker.c:98-102) during mem_cgroup_css_online(), as well as in shrinker_memcg_alloc() (mm/shrinker.c:244-245) and shrinker_register() (mm/shrinker.c:765-768). This is the standard ordering in mm/shrinker.c (shrink_slab() avoids taking shrinker_mutex and instead uses RCU + shrinker_try_get()).
3. fs_reclaim -> &osb->journal_shutdown_sem
During memory reclaim (fs_reclaim), do_shrink_slab() invokes super_cache_scan() (fs/super.c:181), which calls prune_dcache_sb() / prune_icache_sb(), leading to dentry_kill() -> ocfs2_dentry_iput() -> evict() -> ocfs2_evict_inode() -> ocfs2_clear_inode() (fs/ocfs2/inode.c:1227).
At fs/ocfs2/inode.c:1326, ocfs2_clear_inode() acquires down_read(&osb->journal_shutdown_sem) to check osb->journal and call jbd2_journal_release_jbd_inode(osb->journal->j_journal, &oi->ip_jinode).
Why Lockdep Triggers (and Role of sb->s_umount)
- In
super_cache_scan() (fs/super.c:200), super_trylock_shared(sb) (fs/super.c:640) attempts down_read_trylock(&sb->s_umount) and checks !(sb->s_flags & SB_DYING) && sb->s_root && (sb->s_flags & SB_BORN) before pruning dentries or inodes.
- Both callers of
ocfs2_journal_shutdown() (ocfs2_dismount_volume() and ocfs2_mount_volume()) execute with sb->s_umount held exclusively (down_write), preventing super_cache_scan() from entering ocfs2_clear_inode() for that same osb while osb->journal_shutdown_sem is write-locked.
- Because
down_read_trylock(&sb->s_umount) is a trylock, lockdep does not record fs_reclaim -> s_umount as a dependency edge and does not model that sb->s_umount mutually excludes ocfs2_journal_shutdown() from running concurrently with super_cache_scan() on the same superblock; additionally, lockdep tracks &osb->journal_shutdown_sem by class rather than per-osb instance.
Fix Considerations
To eliminate the lockdep inversion in fs/ocfs2/journal.c / fs/ocfs2/inode.c:
ocfs2_journal_shutdown() only needs &osb->journal_shutdown_sem to synchronize osb->journal = NULL / freeing journal->j_journal against ocfs2_clear_inode(), or jbd2_journal_destroy() (or shrinker_free(journal->j_shrinker)) should not be invoked while holding osb->journal_shutdown_sem if journal_shutdown_sem is also taken in inode eviction (ocfs2_clear_inode()). Note that generic_shutdown_super() already runs shrink_dcache_for_umount() and evict_inodes() before ocfs2_put_super() -> ocfs2_dismount_volume(), and ocfs2_journal_shutdown() already holds an extra igrab(inode) reference on journal->j_inode until after up_write(&osb->journal_shutdown_sem) (fs/ocfs2/journal.c:1153-1156).