Why does Fedora show ‘writing in progress’ when I eject a USB storage device, and if I pull out the USB at this point, files will be lost (even though the copy operation has been going on for a while)? Is it really still sitting in RAM after the copy finishes? Is there a way to stop it from only writing to the device when I eject it?
With all modern operating systems, linux/windows/macos, the writing of data goes via caches in the kernel for performance reasons. The kernel then writes out the cached data to the device in the background.
You need to the select the eject/safe-eject of your operating system and wait for the confirmation its safe to pull the device out.
But on Windows, this process is so fast that you can almost eject the device as soon as copying is done, so sometimes I just pull out the device without clicking eject (wrong move)
It will depend on how you have been doing the copying of the files.
Some tools will wait for the file to be written out to the device others will let the kernel do its back ground writes.
Typically command line tools will not wait.
Some GUI file managers will wait. I recall that a recent change was made to KDE plasmas Dolphin to wait.
In the end there will be a wait either before a tool says complete or waiting for the eject to say safe.
Many things affect the time it takes to save a file to a USB device: filesystem, USB version, process scheduling, etc. Are you comparing times on the same hardware or 2 different systems?
Depends on how often this fsync command runs to flush buffers to the device - that is the arbiter of “when does the copy process finish according to the kernel”.
Of course at that point, you still have no idea of the device has actually flushed IT’S buffers to the flash ram, and USB stuff is cheap, and relatively lowly quality so that time can vary considerably, from device to device and two “identical” devices from the same supplier.
This was discussed at length as month or two ago, here.
As I understand it the kernel does not need a sync syscall to write out cached buffers. It will get on with writing buffer in the background.
The various sync syscalls priorities what is written out first.
For example an app that cares that the file is persisted on the device can call syncfs(2) for example.