Skip to contentSkip to conversation

xfs: unregister inode shrinker before freeing filesystem structures

PATCH In review Dave Chinner 3 participants 3 messages Jun 25, 2010 – Jun 26, 2010 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: unregister inode shrinker before freeing filesystem structures

From: Dave Chinner <[email protected]>

Currently we don't remove the XFS mount from the shrinker list until late in the unmount path. By this time, we have already torn down the internals of the filesystem (e.g. the per-ag structures), and hence if the shrinker is executed between the teardown and the unregistering, the shrinker will get NULL per-ag structure pointers and panic trying to dereference them.

Fix this by removingthe xfs mount from the shrinker list before tearing down it's internal structures.

---
 fs/xfs/linux-2.6/xfs_super.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +5 -1
index e3de46c..4605cd4 100644
@@ -1156,9 +1156,13 @@ xfs_fs_put_super(
 
 	XFS_bflush(mp->m_ddev_targp);
 
+	/*
+	 * Unregister the memory shrinker before we tear down the mount
+	 * structure so we don't have memory reclaim racing with us here.
+	 */
+	xfs_inode_shrinker_unregister(mp);
 	xfs_unmountfs(mp);
 	xfs_freesb(mp);
-	xfs_inode_shrinker_unregister(mp);
 	xfs_icsb_destroy_counters(mp);
 	xfs_close_devices(mp);
 	xfs_free_fsname(mp);
Signature · 6 lines
1.7.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dave Chinner

From: Dave Chinner <[email protected]>

Currently we don't remove the XFS mount from the shrinker list until late in the unmount path. By this time, we have already torn down the internals of the filesystem (e.g. the per-ag structures), and hence if the shrinker is executed between the teardown and the unregistering, the shrinker will get NULL per-ag structure pointers and panic trying to dereference them.

Quoted 4 lines

Fix this by removingthe xfs mount from the shrinker list before tearing down it's internal structures.

Looks right to me, and is more symmetric with setup I think.

Quoted 13 lines
---
 fs/xfs/linux-2.6/xfs_super.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +1 -0
index e3de46c..4605cd4 100644
@@ -1156,9 +1156,13 @@ xfs_fs_put_super(
 
 	XFS_bflush(mp->m_ddev_targp);
 
+	/*

fs/xfs/linux-2.6/xfs_super.c xfs_fs_put_super( · line 1168

Quoted 10 lines
fs/xfs/linux-2.6/xfs_super.c +4 -1
+	 * Unregister the memory shrinker before we tear down the mount
+	 * structure so we don't have memory reclaim racing with us here.
+	 */
+	xfs_inode_shrinker_unregister(mp);
 	xfs_unmountfs(mp);
 	xfs_freesb(mp);
-	xfs_inode_shrinker_unregister(mp);
 	xfs_icsb_destroy_counters(mp);
 	xfs_close_devices(mp);
 	xfs_free_fsname(mp);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
In reply to Dave Chinner
Quoted 21 lines · Dave Chinner

From: Dave Chinner <[email protected]>

Currently we don't remove the XFS mount from the shrinker list until late in the unmount path. By this time, we have already torn down the internals of the filesystem (e.g. the per-ag structures), and hence if the shrinker is executed between the teardown and the unregistering, the shrinker will get NULL per-ag structure pointers and panic trying to dereference them.

Fix this by removingthe xfs mount from the shrinker list before tearing down it's internal structures.

---
 fs/xfs/linux-2.6/xfs_super.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
fs/xfs/linux-2.6/xfs_super.c +0 -0
index e3de46c..4605cd4 100644

fs/xfs/linux-2.6/xfs_super.c xfs_fs_put_super( · line 1163

Quoted 8 lines
fs/xfs/linux-2.6/xfs_super.c +5 -0
@@ -1156,9 +1156,13 @@ xfs_fs_put_super(
 
 	XFS_bflush(mp->m_ddev_targp);
 
+	/*
+	 * Unregister the memory shrinker before we tear down the mount
+	 * structure so we don't have memory reclaim racing with us here.
+	 */
+	xfs_inode_shrinker_unregister(mp);

Given that we register the shrinker after syncd is started for we should also tear it down as the very first thing for symmetry resons.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs