A kworker at 100% CPU from vm.dirtytime_expire_seconds=0

If you mount a filesystem with lazytime, the kernel keeps inode timestamp updates in memory and flushes them to disk on a timer. You can tune how often that runs with the vm.dirtytime_expire_seconds sysctl. Only there was a catch: if you set it to 0, a kworker thread would spin at 100% CPU (bugzilla 220227).

The reason is pretty straightforward once you look at wakeup_dirtytime_writeback(). It runs from delayed work, wakes the writeback threads, and then reschedules itself using dirtytime_expire_interval * HZ as the delay. Set the sysctl to 0 and the delay becomes 0, so the work item immediately schedules itself again in a tight loop. That behavior had been around since commit a2f4870697a5 (“fs: make sure the timestamps for lazytime inodes eventually get written”).

The neighboring dirty_writeback_centisecs sysctl already treats 0 as “turn periodic writeback off,” so making vm.dirtytime_expire_seconds do the same was the natural fix. In fs/fs-writeback.c, wakeup_dirtytime_writeback() now only reschedules when the interval is non-zero, dirtytime_interval_handler() cancels the delayed work when set to 0 (and kicks it back off if you set a non-zero value again), and start_dirtytime_writeback() skips the initial schedule when the interval is 0.

Before interval = 0 wakeup_dirtytime_writeback() schedule_delayed_work(0) 0-tick delay → immediate re-run (100% CPU kworker) After interval = 0 dirtytime_interval_handler() cancel_delayed_work_sync() — idle

The fix landed in mainline as 543467d6fe97 (lore thread).

Comments