xfs: ratelimit inode flush on buffered write ENOSPC
PATCH 1/1 xfs: ratelimit inode flush on buffered write ENOSPC
From: Darrick J. Wong <[email protected]>
A customer reported rcu stalls and softlockup warnings on a computer with many CPU cores and many many more IO threads trying to write to a filesystem that is totally out of space. Subsequent analysis pointed to the many many IO threads calling xfs_flush_inodes -> sync_inodes_sb, which causes a lot of wb_writeback_work to be queued. The writeback worker spends so much time trying to wake the many many threads waiting for writeback completion that it trips the softlockup detector, and (in this case) the system automatically reboots.
In addition, they complain that the lengthy xfs_flush_inodes scan traps all of those threads in uninterruptible sleep, which hampers their ability to kill the program or do anything else to escape the situation.
If there's thousands of threads trying to write to files on a full filesystem, each of those threads will start separate copies of the inode flush scan. This is kind of pointless since we only need one scan, so rate limit the inode flush.
--- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
fs/xfs/xfs_mount.h +1 -0
@@ -167,6 +167,7 @@ typedef struct xfs_mount {struct xfs_kobj m_error_meta_kobj;struct xfs_error_cfg m_error_cfg[XFS_ERR_CLASS_MAX ][XFS_ERR_ERRNO_MAX ];struct xstats m_stats;/* per-fs stats */ +struct ratelimit_state m_flush_inodes_ratelimit;struct workqueue_struct *m_buf_workqueue;struct workqueue_struct *m_unwritten_workqueue;
fs/xfs/xfs_super.c +14 -0
@@ -528,6 +528,9 @@ xfs_flush_inodes( {struct super_block *sb = mp->m_super; +if (!__ratelimit (&mp->m_flush_inodes_ratelimit)) +return ; +if (down_read_trylock (&sb->s_umount)) {sync_inodes_sb (sb);up_read (&sb->s_umount);
@@ -1366,6 +1369,17 @@ xfs_fc_fill_super(if (error) goto out_free_names; +/* +* Cap the number of invocations of xfs_flush_inodes to 16 for every +* quarter of a second. The magic numbers here were determined by +* observation neither to cause stalls in writeback when there are a +* lot of IO threads and the fs is near ENOSPC, nor cause any fstest +* regressions. YMMV. +*/ +ratelimit_state_init (&mp->m_flush_inodes_ratelimit,HZ /4 ,16 ); +ratelimit_set_flags (&mp->m_flush_inodes_ratelimit, +RATELIMIT_MSG_ON_RELEASE ); + error =xfs_init_mount_workqueues (mp);if (error) goto out_close_devices;
Quoted 15 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
A customer reported rcu stalls and softlockup warnings on a computer with many CPU cores and many many more IO threads trying to write to a filesystem that is totally out of space. Subsequent analysis pointed to the many many IO threads calling
xfs_flush_inodes->sync_inodes_sb, which causes a lot ofwb_writeback_workto be queued. The writeback worker spends so much time trying to wake the many many threads waiting for writeback completion that it trips the softlockup detector, and (in this case) the system automatically reboots.In addition, they complain that the lengthy
xfs_flush_inodesscan traps all of those threads in uninterruptible sleep, which hampers their ability to kill the program or do anything else to escape the situation.
Quoted 6 lines
If there's thousands of threads trying to write to files on a full filesystem, each of those threads will start separate copies of the inode flush scan. This is kind of pointless since we only need one scan, so rate limit the inode flush.
Signed-off-by Darrick J. Wong <[email protected]>
Ok, makes sense
Quoted 50 lines
--- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)fs/xfs/xfs_mount.h +1
-0@@ -167,6 +167,7 @@ typedef struct xfs_mount {struct xfs_kobj m_error_meta_kobj;struct xfs_error_cfg m_error_cfg[XFS_ERR_CLASS_MAX ][XFS_ERR_ERRNO_MAX ];struct xstats m_stats;/* per-fs stats */ +struct ratelimit_state m_flush_inodes_ratelimit;struct workqueue_struct *m_buf_workqueue;struct workqueue_struct *m_unwritten_workqueue;fs/xfs/xfs_super.c +14
-0@@ -528,6 +528,9 @@ xfs_flush_inodes( {struct super_block *sb = mp->m_super; +if (!__ratelimit (&mp->m_flush_inodes_ratelimit)) +return ; +if (down_read_trylock (&sb->s_umount)) {sync_inodes_sb (sb);up_read (&sb->s_umount);@@ -1366,6 +1369,17 @@ xfs_fc_fill_super(if (error) goto out_free_names; +/* +* Cap the number of invocations of xfs_flush_inodes to 16 for every +* quarter of a second. The magic numbers here were determined by +* observation neither to cause stalls in writeback when there are a +* lot of IO threads and the fs is near ENOSPC, nor cause any fstest +* regressions. YMMV. +*/ +ratelimit_state_init (&mp->m_flush_inodes_ratelimit,HZ /4 ,16 ); +ratelimit_set_flags (&mp->m_flush_inodes_ratelimit, +RATELIMIT_MSG_ON_RELEASE ); + error =xfs_init_mount_workqueues (mp);if (error) goto out_close_devices;
Quoted 56 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
A customer reported rcu stalls and softlockup warnings on a computer with many CPU cores and many many more IO threads trying to write to a filesystem that is totally out of space. Subsequent analysis pointed to the many many IO threads calling
xfs_flush_inodes->sync_inodes_sb, which causes a lot ofwb_writeback_workto be queued. The writeback worker spends so much time trying to wake the many many threads waiting for writeback completion that it trips the softlockup detector, and (in this case) the system automatically reboots.In addition, they complain that the lengthy
xfs_flush_inodesscan traps all of those threads in uninterruptible sleep, which hampers their ability to kill the program or do anything else to escape the situation.If there's thousands of threads trying to write to files on a full filesystem, each of those threads will start separate copies of the inode flush scan. This is kind of pointless since we only need one scan, so rate limit the inode flush.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)fs/xfs/xfs_mount.h +1
-0@@ -167,6 +167,7 @@ typedef struct xfs_mount {struct xfs_kobj m_error_meta_kobj;struct xfs_error_cfg m_error_cfg[XFS_ERR_CLASS_MAX ][XFS_ERR_ERRNO_MAX ];struct xstats m_stats;/* per-fs stats */ +struct ratelimit_state m_flush_inodes_ratelimit;struct workqueue_struct *m_buf_workqueue;struct workqueue_struct *m_unwritten_workqueue;fs/xfs/xfs_super.c +3
-0@@ -528,6 +528,9 @@ xfs_flush_inodes( {struct super_block *sb = mp->m_super; +if (!__ratelimit (&mp->m_flush_inodes_ratelimit)) +return ; +if (down_read_trylock (&sb->s_umount)) {sync_inodes_sb (sb);up_read (&sb->s_umount);@@ -1366,6 +1369,17 @@ xfs_fc_fill_super(if (error) goto out_free_names;
fs/xfs/xfs_super.c xfs_fc_fill_super( · line 1381
Quoted 10 lines
fs/xfs/xfs_super.c +10
-0+/* +* Cap the number of invocations of xfs_flush_inodes to 16 for every +* quarter of a second. The magic numbers here were determined by +* observation neither to cause stalls in writeback when there are a +* lot of IO threads and the fs is near ENOSPC, nor cause any fstest +* regressions. YMMV. +*/ +ratelimit_state_init (&mp->m_flush_inodes_ratelimit,HZ /4 ,16 ); +ratelimit_set_flags (&mp->m_flush_inodes_ratelimit, +RATELIMIT_MSG_ON_RELEASE );
Urk.
RATELIMIT_MSG_ON_RELEASE prevents "callbacks suppressed" messages when rate limiting was active and resets via __rate_limit(). However, in ratelimit_state_exit(), that flag -enables- printing "callbacks suppressed" messages when rate limiting was active and is reset.
Same flag, exact opposite behaviour...
The comment says it's behaviour is supposed to match that of ratelimit_state_exit() (i.e. print message on ratelimit exit), so I really can't tell if this is correct/intended usage or just API abuse....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 76 lines · Dave Chinner
Quoted 56 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
A customer reported rcu stalls and softlockup warnings on a computer with many CPU cores and many many more IO threads trying to write to a filesystem that is totally out of space. Subsequent analysis pointed to the many many IO threads calling
xfs_flush_inodes->sync_inodes_sb, which causes a lot ofwb_writeback_workto be queued. The writeback worker spends so much time trying to wake the many many threads waiting for writeback completion that it trips the softlockup detector, and (in this case) the system automatically reboots.In addition, they complain that the lengthy
xfs_flush_inodesscan traps all of those threads in uninterruptible sleep, which hampers their ability to kill the program or do anything else to escape the situation.If there's thousands of threads trying to write to files on a full filesystem, each of those threads will start separate copies of the inode flush scan. This is kind of pointless since we only need one scan, so rate limit the inode flush.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)fs/xfs/xfs_mount.h +1
-0@@ -167,6 +167,7 @@ typedef struct xfs_mount {struct xfs_kobj m_error_meta_kobj;struct xfs_error_cfg m_error_cfg[XFS_ERR_CLASS_MAX ][XFS_ERR_ERRNO_MAX ];struct xstats m_stats;/* per-fs stats */ +struct ratelimit_state m_flush_inodes_ratelimit;struct workqueue_struct *m_buf_workqueue;struct workqueue_struct *m_unwritten_workqueue;fs/xfs/xfs_super.c +3
-0@@ -528,6 +528,9 @@ xfs_flush_inodes( {struct super_block *sb = mp->m_super; +if (!__ratelimit (&mp->m_flush_inodes_ratelimit)) +return ; +if (down_read_trylock (&sb->s_umount)) {sync_inodes_sb (sb);up_read (&sb->s_umount);@@ -1366,6 +1369,17 @@ xfs_fc_fill_super(if (error) goto out_free_names;fs/xfs/xfs_super.c xfs_fc_fill_super( · line 1381
Quoted 10 lines
fs/xfs/xfs_super.c +10
-0+/* +* Cap the number of invocations of xfs_flush_inodes to 16 for every +* quarter of a second. The magic numbers here were determined by +* observation neither to cause stalls in writeback when there are a +* lot of IO threads and the fs is near ENOSPC, nor cause any fstest +* regressions. YMMV. +*/ +ratelimit_state_init (&mp->m_flush_inodes_ratelimit,HZ /4 ,16 ); +ratelimit_set_flags (&mp->m_flush_inodes_ratelimit, +RATELIMIT_MSG_ON_RELEASE );Urk.
RATELIMIT_MSG_ON_RELEASEprevents "callbacks suppressed" messages when rate limiting was active and resets via__rate_limit(). However, inratelimit_state_exit(), that flag -enables- printing "callbacks suppressed" messages when rate limiting was active and is reset.
Quoted 6 lines
Same flag, exact opposite behaviour...
The comment says it's behaviour is supposed to match that of
ratelimit_state_exit()(i.e. print message on ratelimit exit), so I really can't tell if this is correct/intended usage or just API abuse....
This flag (AFAICT) basically means "summarize skipped calls later", where later is when _exit is called. It's very annoying that this printk thing is mixed in with what otherwise is a simple ratelimiting mechanism, since there isn't much to be gained by spamming dmesg every time a buffered write hits ENOSPC, and absolutely nothing to be gained by logging that at umount time (with comm being the umount process!)
Since there's no design documentation for how the ratelimiting system works, the best I can do is RTFS and do whatever magic gets the outcome I want (which is to set the flag and skip calling _exit. Only one of the ratelimit state users calls ratelimit_state_exit, so it's apparently not required.
This all is poor engineering practice, but you /did/ suggest ratelimiting (on IRC) and I don't want to go reimplementing ratelimit.c either, and it /does/ fix the xfs_flush_inodes flooding problems.
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Dave Chinner
Reviewed-byQuoted 91 lines · Darrick J. Wong
Quoted 76 lines · Dave Chinner
Quoted 56 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
A customer reported rcu stalls and softlockup warnings on a computer with many CPU cores and many many more IO threads trying to write to a filesystem that is totally out of space. Subsequent analysis pointed to the many many IO threads calling
xfs_flush_inodes->sync_inodes_sb, which causes a lot ofwb_writeback_workto be queued. The writeback worker spends so much time trying to wake the many many threads waiting for writeback completion that it trips the softlockup detector, and (in this case) the system automatically reboots.In addition, they complain that the lengthy
xfs_flush_inodesscan traps all of those threads in uninterruptible sleep, which hampers their ability to kill the program or do anything else to escape the situation.If there's thousands of threads trying to write to files on a full filesystem, each of those threads will start separate copies of the inode flush scan. This is kind of pointless since we only need one scan, so rate limit the inode flush.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)fs/xfs/xfs_mount.h +1
-0@@ -167,6 +167,7 @@ typedef struct xfs_mount {struct xfs_kobj m_error_meta_kobj;struct xfs_error_cfg m_error_cfg[XFS_ERR_CLASS_MAX ][XFS_ERR_ERRNO_MAX ];struct xstats m_stats;/* per-fs stats */ +struct ratelimit_state m_flush_inodes_ratelimit;struct workqueue_struct *m_buf_workqueue;struct workqueue_struct *m_unwritten_workqueue;fs/xfs/xfs_super.c +3
-0@@ -528,6 +528,9 @@ xfs_flush_inodes( {struct super_block *sb = mp->m_super; +if (!__ratelimit (&mp->m_flush_inodes_ratelimit)) +return ; +if (down_read_trylock (&sb->s_umount)) {sync_inodes_sb (sb);up_read (&sb->s_umount);@@ -1366,6 +1369,17 @@ xfs_fc_fill_super(if (error) goto out_free_names;fs/xfs/xfs_super.c xfs_fc_fill_super( · line 1381
Quoted 10 lines
fs/xfs/xfs_super.c +10
-0+/* +* Cap the number of invocations of xfs_flush_inodes to 16 for every +* quarter of a second. The magic numbers here were determined by +* observation neither to cause stalls in writeback when there are a +* lot of IO threads and the fs is near ENOSPC, nor cause any fstest +* regressions. YMMV. +*/ +ratelimit_state_init (&mp->m_flush_inodes_ratelimit,HZ /4 ,16 ); +ratelimit_set_flags (&mp->m_flush_inodes_ratelimit, +RATELIMIT_MSG_ON_RELEASE );Urk.
RATELIMIT_MSG_ON_RELEASEprevents "callbacks suppressed" messages when rate limiting was active and resets via__rate_limit(). However, inratelimit_state_exit(), that flag -enables- printing "callbacks suppressed" messages when rate limiting was active and is reset.Quoted 6 lines
Same flag, exact opposite behaviour...
The comment says it's behaviour is supposed to match that of
ratelimit_state_exit()(i.e. print message on ratelimit exit), so I really can't tell if this is correct/intended usage or just API abuse....This flag (AFAICT) basically means "summarize skipped calls later", where later is when
_exitis called. It's very annoying that this printk thing is mixed in with what otherwise is a simple ratelimiting mechanism, since there isn't much to be gained by spamming dmesg every time a buffered write hits ENOSPC, and absolutely nothing to be gained by logging that at umount time (with comm being the umount process!)
Quoted 5 lines
Since there's no design documentation for how the ratelimiting system works, the best I can do is RTFS and do whatever magic gets the outcome I want (which is to set the flag and skip calling
_exit. Only one of the ratelimit state users callsratelimit_state_exit, so it's apparently not required.
Yeah, that's pretty much where I got to with it - I wasn't at all sure if there was something obvious I was missing or it was just another piece of poorly written code...
Quoted 3 lines
This all is poor engineering practice, but you /did/ suggest ratelimiting (on IRC) and I don't want to go reimplementing
ratelimit.ceither, and it /does/ fix thexfs_flush_inodesflooding problems.
*nod*
Signature · 2 lines
Dave Chinner [email protected]