Bug 198605 - Mounting vfat fs from usb flash drives with "flush" option causes slow write performance
Summary: Mounting vfat fs from usb flash drives with "flush" option causes slow write ...
Status: CLOSED INVALID
Alias: None
Product: File System
Classification: Unclassified
Component: FAT/VFAT/MSDOS (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: OGAWA Hirofumi
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-29 11:25 UTC by pezcurrel
Modified: 2018-01-30 11:58 UTC (History)
0 users

See Also:
Kernel Version: 4.14.15-1-ARCH
Tree: Mainline
Regression: No


Attachments

Description pezcurrel 2018-01-29 11:25:37 UTC
Mounting vfat filesystems from usb flash drives with "flush" option causes slow write performance on my desktop pc with Arch Linux and 4.14.15 kernel. 
Mounting them without the "flush" option I get around double the speed (a speed that is on par with what I see under windows copying the same files, ie ~ 10 mb/s on one usb stick and ~ 4 mb on another).
In order to take into account the "sync" time I checked by timing (with "time") a script that copies 3 files for a total of 3.3 gb and soon after that unmounts the flash drives.
The results are similar if I use usb 2 or usb 3 ports (both the pendrives are usb 2.0).
Comment 1 pezcurrel 2018-01-29 11:30:36 UTC
I forgot to mention that the write speed on the same two drives, when formatted to ext4, is on par with what I get with vfat without the "flush" option (actually, it's a bit faster).
Comment 2 OGAWA Hirofumi 2018-01-29 12:50:38 UTC
Yes, it is intent.

If the "flush" option is on, some syscalls wait written data reach to usb flash.
In contrast, if off, syscalls just write to memory (data page cache, or metadata buffer).

This is to reduce damages of filesystem from unexpected unplugging by writing data to usb flash early.

(Or you mean, "flush" option is slower than necessary?)
Comment 3 pezcurrel 2018-01-29 17:33:39 UTC
I don't know whether it's slower than necessary since I don't know its internals and wouldn't understand them since I'm not a coder :) , but its speed is half the speed I get when not using it *taking into account the unmount time*. I mean: if the "flush" option is not used data get cached more, but when unmounting, the cached data still need to be written, so I would expect the overall time taken by "copying the same files + unmounting soon after copying" to be approximately the same with or without the "flush" option. What I see instead is that when the "flush" option is on the overall time taken by "copying the same files + unmounting soon after copying" is almost double the time it takes without "flush" option.
Comment 4 OGAWA Hirofumi 2018-01-29 20:13:51 UTC
It is possible with depending on type of load.

Say, we are writing 5 files. With "flush", basically, flush a file for each a write. Because filesystem doesn't know whether user writes 4 more files or not. And then, directory and metadata will be written 5 times.

In contrast, in no "flush" option case, directory and metadata are also cached and flushed at once time.

This would be main reason of why. And unfortunately, heuristic (to detect more files) of "flush" option is quite not sophisticated that applied to FAT.
Comment 5 pezcurrel 2018-01-30 11:29:14 UTC
Thank you for your answer :)
I did some more tests on my laptop (previously I tested on my desktop pc).
Turns out on my laptop writing one big file (1 gb) to the pendrive and unmounting it soon after that takes almost exactly the same time with or without the "flush" option. I don't know why on my desktop pc it takes double the time with "flush" than without.
Moreover, I tried copying many little files (many mp3 files for a total of 1.6 gb). On this test, writing to the pendrive mounted *with* the "flush" option proved to be much faster than without, and this seems to me contradictory with what you explained in your previous comment.
So, I'm lost :))
Comment 6 OGAWA Hirofumi 2018-01-30 11:58:32 UTC
Thanks you for testing.

Note You need to log in before you can comment on or make changes to this bug.