Solved : The Pernicious USB-stick stall problem - Ubuntu 22.04.05 to some extent.

Solved : The Pernicious USB-stick stall problem - Ubuntu 22.04.05 to some extent.

Plugging in a slow storage device ( a USB stick ) into a Linux machine ( Ubuntu 22.04.05 ) and writing a lot of data to it ( copying an .iso file ). The entire system hangs and the speed of transfer decreases and after some time it halts.

This problem persists today also because the Linux Kernel is busy in matching the rate of creating the dirty memory to the rate at which the memory is writing on the storage device. And when the sync() function is called the kernel, things stop until the entire queue is written. Ultimately resulting in slow transfer rate and system hang.

To prevent it from happening, Linux Dev's have created a set of tweakable knobs under /proc/sys/vm to control what happens when processes create a lot of dirty pages. These knobs are:

  • dirty_background_ratio specifies a percentage of memory; when at least that percentage is dirty, the kernel will start writing those dirty pages back to the backing device. So, if a system has 1000 pages of memory and dirty_background_ratio is set to 10% (the default), writeback will begin when 100 pages have been dirtied.

  • dirty_ratio specifies the percentage at which processes that are dirtying pages are made to wait for writeback. If it is set to 20% (again, the default) on that 1000-page system, a process dirtying pages will be made to wait once the 200th page is dirtied. This mechanism will, thus, slow the dirtying of pages while the system catches up.
  • dirty_background_bytes works like dirty_background_ratio except that the limit is specified as an absolute number of bytes.
  • dirty_bytes is the equivalent of dirty_ratio except that, once again, it is specified in bytes rather than as a percentage of total memory.

Adjusting limits by byte-based threshold :


After these changes i was able to get a constant speed of 5.4 MB/sec. And less halting in a 16GB ram system.

Ref : https://lwn.net/Articles/572911/

要查看或添加评论,请登录

社区洞察

其他会员也浏览了