I have a script which writes data to an SD card connected via USB, then umounts it.
The data is several GB in size so it hangs at the umount stage while the writes complete, and I want to give user feedback.
(Note: I have had no luck whatsoever using sync to force the data to sync first, it always returns immediately.)
At the moment I send umount into the background and grep /proc/meminfo for a "Dirty" value which I display, repeating until the umount command closes. This is reliable and fairly meaningful, but because it takes a few minutes is throwing a kernel INFO message into syslog: INFO: task umount:17976 blocked for more than 120 seconds
Ideally I would just wait for writes to complete before even trying to umount, but I can't see a way to do that. Is there a way to determine if (say) /dev/sdc is still busy, and if so how much data is pending? Or any other suggestions?
Current code (modified a bit for clarity in posting): echo -e "\n\nWaiting for writes to complete" sudo umount /dev/sdc[1-9] & while jobs -r | grep 'Running' > /dev/null ; do pending=$(grep -Po 'Dirty: *\K.*' /proc/meminfo) echo -ne "\rBuffer remaining: ~$pending " sleep 1 done echo -e "\rUnmounted - you can now remove the disk. "
If you are just writing large files to it then maybe mounting with sync and noatime will help?
Kind Regards Andrew
On 01/05/2019 16:16, Mark Rogers wrote:
I have a script which writes data to an SD card connected via USB, then umounts it.
The data is several GB in size so it hangs at the umount stage while the writes complete, and I want to give user feedback.
(Note: I have had no luck whatsoever using sync to force the data to sync first, it always returns immediately.)
At the moment I send umount into the background and grep /proc/meminfo for a "Dirty" value which I display, repeating until the umount command closes. This is reliable and fairly meaningful, but because it takes a few minutes is throwing a kernel INFO message into syslog: INFO: task umount:17976 blocked for more than 120 seconds
Ideally I would just wait for writes to complete before even trying to umount, but I can't see a way to do that. Is there a way to determine if (say) /dev/sdc is still busy, and if so how much data is pending? Or any other suggestions?
Current code (modified a bit for clarity in posting): echo -e "\n\nWaiting for writes to complete" sudo umount /dev/sdc[1-9] & while jobs -r | grep 'Running' > /dev/null ; do pending=$(grep -Po 'Dirty: *\K.*' /proc/meminfo) echo -ne "\rBuffer remaining: ~$pending " sleep 1 done echo -e "\rUnmounted - you can now remove the disk. "
On Wed, 1 May 2019 at 17:34, Andrew Hutchings andrew@linuxjedi.co.uk wrote:
If you are just writing large files to it then maybe mounting with sync and noatime will help?
I'm extracting an OS image onto it (from a tar.gz file, not a binary image) so it's lots of small files. I would have thought that sync would slow down the write (but haven't thought to try it).
Never crossed my mind to play with options at the mount stage, so I'll play, thanks. It happens that I am mounting within my script anyway so it's not a big thing to try.
(Still feels like it should be possible to properly monitor whether a device is busy and how much delayed write data is pending, though.)