Decrease dirty bytes for more reliable USB transfer

Well I understand what you mean and on slow USB Stick. It fill up the cache and the file manager assumes it has been copied, while it is not. I understand that this could be an annoying problem on slow usb flash drives.

However… set it to:

  1. dirty → ~50MB
  2. dirty_background → ~16MB

is really low. it should be:

  1. dirty → ~256MB
  2. dirty_background → ~128MB

However… the value is only set for slow connections, while HDDs/SSDs have no problem what so ever with the default settings.

I believe even Windows has by default on the Desktop a 10% global dirty page threshold, so nothing static, but if it the threshold is arrived it switches to write-through (direct io).

Windows disables the write cache for usb thumb drives, while Linux does not by default.

A better approach:

Using a udev rule, so that it add the sync option on all usb devices:

SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_MOUNT_OPTIONS_DEFAULTS}+="sync", ENV{UDISKS_MOUNT_OPTIONS_ALLOW}+="sync"

:warning: This udev rule is just an example. Adjuste it if needed.

Then you don’t have to worry about dirty pages, because it writes directly and synchronously. async is the default, which leads to that described behavior on slow disks.

That would be then the same behavior like on WIndows, where the write cache is disabled on usb flash drives, but it decrease the life-time of the flash drive for this usability .

4 Likes