Making Linux responsive aka how IO priority and buffer size influences responsiveness

When doing backups on Linux, it is ususally wanted that the system stays responsive to inputs. That includes terminals and Xorg/Wayland. In the context of IO niceness, the concept of “everything is a file” bites Xorg/Wayland into the ass quite well because it turns out that writing to the frame buffers and refreshing the screen is also subject to IO classes and niceness. In conjunction with the fact that by default the Linux kernel has relatively large dirty page buffers and seems to work on the buffers in a single thread, this leads to Xorg and Wayland being blocked by tasks that have a large buffer to write back.

To the user, this looks like the system is unresponsive. This problem can be solved by setting the IO class of Xorg and the relevant desktop applications to realtime and giving them a high priority, which can be done automatically using a niceness daemon like ananicy, and by setting the dirty pages buffer size to 0 and the writeback period to a low setting. This can be done using sysctl:

vm.dirty_background_bytes=0
vm.dirty_background_ratio=0
vm.dirty_expire_centisecs=20
vm.dirty_writeback_centisecs=10
vm.dirtytime_expire_seconds=60
vm.dirty_ratio=2

The background of the settings is that there is a flusher task running in the kernel that periodically writes back dirty buffers to permanent storage. It seems that this task blocks the writes that Xorg/Wayland do to the frame buffers (or indirectly through the drivers). By reducing the buffer size and the time between runs of the flusher task, the size of the buffer can be reduced so the flusher task blocks for a shorter amoung of time or does not run at all.

For an example rule set using ionice and nice settings for Xorg, see the ananicy project.

In order to make the desktop itself, like the window manager, task bards, email clients, … responsive, those applications need to have their niceness and ioniceness adjusted as well. The ananicy daemon does this in its default rule set. It sets the IO class of those applications to “realtime”.