Skip to content

Commit c642570

Browse files
committed
xfs: ratelimit inode flush on buffered write ENOSPC
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. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent d4bc4c5 commit c642570

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

fs/xfs/xfs_mount.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ typedef struct xfs_mount {
167167
struct xfs_kobj m_error_meta_kobj;
168168
struct xfs_error_cfg m_error_cfg[XFS_ERR_CLASS_MAX][XFS_ERR_ERRNO_MAX];
169169
struct xstats m_stats; /* per-fs stats */
170+
struct ratelimit_state m_flush_inodes_ratelimit;
170171

171172
struct workqueue_struct *m_buf_workqueue;
172173
struct workqueue_struct *m_unwritten_workqueue;

fs/xfs/xfs_super.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ xfs_flush_inodes(
528528
{
529529
struct super_block *sb = mp->m_super;
530530

531+
if (!__ratelimit(&mp->m_flush_inodes_ratelimit))
532+
return;
533+
531534
if (down_read_trylock(&sb->s_umount)) {
532535
sync_inodes_sb(sb);
533536
up_read(&sb->s_umount);
@@ -1366,6 +1369,17 @@ xfs_fc_fill_super(
13661369
if (error)
13671370
goto out_free_names;
13681371

1372+
/*
1373+
* Cap the number of invocations of xfs_flush_inodes to 16 for every
1374+
* quarter of a second. The magic numbers here were determined by
1375+
* observation neither to cause stalls in writeback when there are a
1376+
* lot of IO threads and the fs is near ENOSPC, nor cause any fstest
1377+
* regressions. YMMV.
1378+
*/
1379+
ratelimit_state_init(&mp->m_flush_inodes_ratelimit, HZ / 4, 16);
1380+
ratelimit_set_flags(&mp->m_flush_inodes_ratelimit,
1381+
RATELIMIT_MSG_ON_RELEASE);
1382+
13691383
error = xfs_init_mount_workqueues(mp);
13701384
if (error)
13711385
goto out_close_devices;

0 commit comments

Comments
 (0)