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).
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).
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?)
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.
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.
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 :))
Thanks you for testing.