Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've copied a large file to a USB disk mounted on a Linux system with async. This returns to a command prompt relatively quickly, but when I type sync, of course, it all has to go to disk, and that takes a long time.

I understand that it's going to be slow, but is there somewhere where I can watch a counter go down to zero? Watching buffers in top doesn't help.

share|improve this question
add comment

2 Answers

up vote 15 down vote accepted

Looking at /proc/meminfo will show the "Dirty" number shrinking over time as all the data spools out; some of it may spill into "Writeback" as well. That will be a summary against all devices, but in the cases where one device on the system is much slower than the rest you'll usually end up where everything in that queue is related to it. You'll probably find the Dirty number large when you start and the sync finished about the same time it approaches 0. Try this to get an interactive display:

watch grep -e Dirty: -e Writeback: /proc/meminfo

With regular disks I can normally ignore Writeback, but I'm not sure if it's involved more often in the USB transfer path. If it just bounces up and down without a clear trend to it, you can probably just look at the Dirty number.

share|improve this answer
    
On my system, writeback stays at a few megs until right near the end, when Dirty is empty, at which point it starts going down too. –  mattdm Oct 8 '12 at 2:02
add comment

You can look at the /sys/block/<device>/stat file for the appropriate device while you're syncing. The 9th column will indicate the number of in-flight requests on the device, which should go down to zero when the sync is done.
Don't know of a way to translate that to a number of bytes, but it should give you a rough idea of how much "stuff" is still pending.

See the stat.txt file in the kernel documentation for a bit more information. (There's also an inflight file in that directory on my system which looks like it could contain read and write in-flight requests, but I can't find docs for that.)

share|improve this answer
    
Just for handy reference, combining an idea from another answer: watch -t -n1 'awk "{ print \$9 }" /sys/block/sdd/stat' –  mattdm Oct 8 '12 at 1:59
    
For my usb stick, this tends to hover around 150 throughout the duration of the copy operation and the sync afterwards. It does go to 0, but only at the very end. That makes the other answer more useful for impatiently watching progress. –  mattdm Oct 8 '12 at 2:01
    
(Even though in theory I like looking at just the appropriate device rather than the systemwide info.) –  mattdm Oct 8 '12 at 2:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.