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.

Not sure if should post this on Android SE because I don't think this is directly related to the Android OS. On my system I manually mount and umount my HTC device with these options in /etc/fstab:

UUID=3465-3762 /mnt/htc auto gid=100,umask=002,noauto,user,rw,exec 0 0

This works fine when modifying small amounts of data on the SD card, but whenever I copy e.g. a couple of music albums encoded in FLAC from another device - unmounting the SD card seems to take forever:

$ time umount /mnt/htc/
real    1m17.195s
user    0m0.000s
sys     0m0.237s

Is this time proportional to the amount of data modified? Should it take this long to unmount it anyway?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

That's to do with the kernel doing a lot of buffering, including buffering writes to your device.

If you issue:

cp large_file /mnt/htc/

cp will return as soon as it has finished writeing the data, but (for reasonably "slow" devices/connections) well before that data has actually been written. (Unless cp or the tool you use itself issues fsync or similar calls to wait for the actual data to have hit the drive - some graphical file managers do this, some tools have options you can use to control whether they do or not.)

unmount flushes the write buffers before it "detaches" the device so that you don't lose data. It can take a lot of time if the kernel buffered a lot of data, and the actual writes are slow.

Try to run something like iostat 2 (part of the sysstat) in a terminal while you do the copy and the unmount, you should see write I/O up until the point unmount returns.

share|improve this answer
    
So this also has to do with the speed of the device connection/bus right? I'm using the standard micro USB 2.0 cable so this should be sufficient for transfering maybe smaller files. –  Herman Torjussen Jan 15 '12 at 14:01
    
Yes, it has a lot do do with how fast the data goes to the device. Say you copy a 1MB file. The kernel can (probably) cache all that, so cp will return instantly. If your device (or the bus you're using) only does 1KB/s transfers, unmount will take approx 1024s to complete. If your device is a fast disk system with a high bandwidth bus (says SAS), the writeout will be done before you're finished typing unm. –  Mat Jan 15 '12 at 14:12
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.