I/O Scheduler and large files to USB
rx7f
Status: Curious
Joined: 26 Jul 2019
Posts: 5
Reply Quote
Hi, I am wondering as copying large files to USB takes forever;
Could it be that the I/O scheduler is not configured optimally for copying large files?
Just thinking out loud.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4128
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
haha, I've noticed that too, for a long time, never was sure if it was a general Linux kernel thing, or a Liquorix thing.

Keep in mind there is no such thing as 'usb', there is USB 1.1, 2, 3.

The lowest speed between a hub and a device determines the speed.

:: Quote ::
USB 1.0/Low-Speed: 1.5 Megabits per second (Mbps)
USB 1.1/Full-Speed: 12 Mbps.
USB 2.0/Hi-Speed: 480 Mbps.
USB 3.0/SuperSpeed: 5 Gbps.
USB 3.1/SuperSpeed: 10 Gbps.


inxi --usb -xxx will show you the true usb revision version per device, and the associated device speed. Sometimes it shows the max speed, not the speed that it can actually achieve, that is, if the hub is actually usb 3, and the device usb 2, sometimes it will show you usb 3 for the device, it's not totally consistent, but the hub of course is the determining factor, a usb 2 hub can't communicate at any faster speed.

To be fair, I've always found Linux kernel long usb write performance to be really bad in most cases, but also keep in mind, it depends on the file systems, when I'm for example writing to ext3 or ext4 on a usb drive, I find the performance is usually quite peppy.
Back to top
damentz
Status: Assistant
Joined: 09 Sep 2008
Posts: 1143
Reply Quote
There's two things going against Linux on USB flash drives that make it feel inferior to Windows.

1) If you want to make a portable drive that works between MacOS, Windows, and Linux, you need to format it fat32 (or coming up, exFAT). Linux's FAT32 driver isn't super optimized as far as I know. NTFS is even worse using ntfs-3g.
2) Most Linux distributions don't use the sync mount option on portable drives, leaving most file transfers stuck at 99% until the copy randomly completes.

What you're experiencing is not that Linux is slower for the most part, it's that on nearly all Linux distributions, hotplug drives take advantage of writeback. On Windows, flash drives don't, or they use a very small writeback to help with buffering writes. This means on Linux, your file manager will say that 100% of data has been copied over after writing about a gigabyte of data, but the file manager itself will stay frozen while we wait for the kernel to say the transfer is complete.

You could probably fix this by writing a udev rule that says all hotplug drives are mounted with the sync flag, to follow the same behavior of Windows. The unfortunate side effect is if you plug in a real powerful SSD into your USB 3 port, this drive would be mounted as synchronous and your write speeds would suffer greatly there too.

However, it's more likely that your flash drive is slow. Most flash drives are incredibly slow and have awful random I/O unless they specifically mention their performance numbers. And by slow, I mean, a modern hard drive random I/O is faster than crappy cheap flash drives you can get for under $10. At least on modern hard drives, writeback can be used to re-order writes buffered in memory to the platter at high speeds (using NCQ as well), but poor flash controllers don't have this capability and will simply do their job badly until it's complete.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4128
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
That's a good explanation, thanks.
Back to top
rx7f
Status: Curious
Joined: 26 Jul 2019
Posts: 5
Reply Quote
Thank you for your elaborate explanations.
Indeed the partition type is Fat32.
I will give the Sync mount parameter a shot and will hope for the best.
At least I understand it now.

Thanks again and a good day to you both!

Device-4: 2-3:2 info: Kingston DataTraveler 100 G3/G4/SE9 G2 type: Mass Storage driver: usb-storage interfaces: 1
rev: 3.1 speed: 5 Gb/s chip ID: 0951:1666 serial: C860008AE288B230E9032B4
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4128
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
I'd correct one thing that damentz said, exfat is already here, I've formatted disks for it. And vfat is alsos available. In basically no case except tiny drives should you use fat32, unless the device it's going into simply only excepts fat32.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours