Page MenuHomeFreeBSD

autofs: media: Always use sync option for fat*
ClosedPublic

Authored by manu on Nov 7 2023, 3:41 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 9, 2:31 AM
Unknown Object (File)
Sat, Nov 9, 2:26 AM
Unknown Object (File)
Fri, Nov 8, 10:24 PM
Unknown Object (File)
Tue, Nov 5, 3:15 PM
Unknown Object (File)
Oct 4 2024, 5:47 PM
Unknown Object (File)
Oct 2 2024, 4:59 AM
Unknown Object (File)
Sep 26 2024, 1:10 PM
Unknown Object (File)
Sep 23 2024, 4:35 PM
Subscribers

Details

Summary

Users of autofs for removable media expect to be able to copy files and
directly remove the media without having the need to call sync(8) or umount(8).

Sponsored by: Beckhoff Automation GmbH & Co. KG

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

manu requested review of this revision.Nov 7 2023, 3:41 PM
This revision is now accepted and ready to land.Nov 7 2023, 4:01 PM

I’m not a huge fan of this one tbh. I seem to remember I had it like this for a while, and it was 1. Unbearably slow and 2. Increased flash wear and tear.

How about decreasing the default timeout for autounmountd to eg three seconds instead?

I’m not a huge fan of this one tbh. I seem to remember I had it like this for a while, and it was 1. Unbearably slow and 2. Increased flash wear and tear.

For 1/ yes it will be slower. But safer.
For 2/ I'm not sure tbh, how can you test something like this ?

How about decreasing the default timeout for autounmountd to eg three seconds instead?

That will work if you do everything from the command line and aren't in the /media/XXX directory. But for users using graphical env like a file explorer I suspect that they will right click on the file, copy, move to the media dir, right click, paste and leave the explorer open while they remove the usb thumb stick (a la windows) so that will not help.

In D42494#969894, @manu wrote:

I’m not a huge fan of this one tbh. I seem to remember I had it like this for a while, and it was 1. Unbearably slow and 2. Increased flash wear and tear.

For 1/ yes it will be slower. But safer.

From what I remember it will be _a lot_ slower for eg an SD card. And not that much safer, tbh, because it can still result in a corrupted filesystem - this just reduces the time window for this to occur. To me, it's pessimizing the common case (FreeBSD users tend to understand how to use media) as a partial workaround for... something.

For 2/ I'm not sure tbh, how can you test something like this ?

I seem to remember there was a drama on LWN few years ago "Linux destroying drives" by mounting them sync by default. I don't remember the details though.

How about decreasing the default timeout for autounmountd to eg three seconds instead?

That will work if you do everything from the command line and aren't in the /media/XXX directory. But for users using graphical env like a file explorer I suspect that they will right click on the file, copy, move to the media dir, right click, paste and leave the explorer open while they remove the usb thumb stick (a la windows) so that will not help.

Doesn't unmount(2) syscall sync the filesystem even when it fails to unmount it due to being busy?

In D42494#969894, @manu wrote:

I’m not a huge fan of this one tbh. I seem to remember I had it like this for a while, and it was 1. Unbearably slow and 2. Increased flash wear and tear.

For 1/ yes it will be slower. But safer.

From what I remember it will be _a lot_ slower for eg an SD card. And not that much safer, tbh, because it can still result in a corrupted filesystem - this just reduces the time window for this to occur. To me, it's pessimizing the common case (FreeBSD users tend to understand how to use media) as a partial workaround for... something.

FreeBSD users don't tend to understand how to use media :)

For 2/ I'm not sure tbh, how can you test something like this ?

I seem to remember there was a drama on LWN few years ago "Linux destroying drives" by mounting them sync by default. I don't remember the details though.

How about decreasing the default timeout for autounmountd to eg three seconds instead?

That will work if you do everything from the command line and aren't in the /media/XXX directory. But for users using graphical env like a file explorer I suspect that they will right click on the file, copy, move to the media dir, right click, paste and leave the explorer open while they remove the usb thumb stick (a la windows) so that will not help.

Doesn't unmount(2) syscall sync the filesystem even when it fails to unmount it due to being busy?

Maybe, but unmount will not be called if the user remove the drive before autounmound kicks in.

Sync is probably the best default here given we don't have what we actually want.

IMO, what we actually do want is to fairly aggressively flush dirty buffers to disk and when the disk goes idle to return the on-disk metadata to an unmounted state.

Using this quick and dirty test script : https://dpaste.com/37CL5BKK5
Here is the result :
-----------------------------------------------------------------------------------------------------------------------------+

x + + +*x ++ ++ xxx + + x x x
__________________A_________M_____A____________________________________

+-----------------------------------------------------------------------------------------------------------------------------+

N           Min           Max        Median           Avg        Stddev

x 10 27.8 77.94 49.09 52.032 14.910511
+ 10 35.46 55.44 45.005 45.03 5.4061364
No difference proven at 95.0% confidence

If you start the script with -x and look at the separate time for cp and umount (tbh too lazy to do another script and run that does that) you can clearly see that the time we gain without using sync for copying file we lost it in umount (well for the sync). And this is what we're interested in for autofs and removable media, we want the data to be as soon as possible on the disk so the user can remove it (or click a button that will umount the drive, and do that not in 20-30 secs).
It was run on a Corsair Voyager USB3 thumb drive on a fat32 partition.

Thank you, I think I'm fine with toggling it from "async" to "sync" specifically for msdosfs.

Also, note that simply adding "sync" to /etc/auto_master will probably break automounting cd9660, because it doesn't support the "sync" mount option.

Thank you, I think I'm fine with toggling it from "async" to "sync" specifically for msdosfs.

Also, note that simply adding "sync" to /etc/auto_master will probably break automounting cd9660, because it doesn't support the "sync" mount option.

I will test all the fs and update the review accordingly.

Use sync only for fat/ntfs filesystems.

This revision now requires review to proceed.Dec 1 2023, 9:29 AM
manu retitled this revision from autofs: media: Always use sync option to autofs: media: Always use sync option for fat*.Dec 1 2023, 9:29 AM
This revision was not accepted when it landed; it landed in state Needs Review.Dec 4 2023, 6:52 AM
This revision was automatically updated to reflect the committed changes.