External USB Hard Drive On/Off Switch

Steve R.

Retired
Local time
Today, 14:45
Joined
Jul 5, 2006
Messages
5,202
I have an external USB hard drive that must be plunged-in to operate. It actually has an on/off switch. 😲
I have often wondered if there was a need to actually use that switch to turn-off the hard drive before unplugging it. I haven't been using the switch at all. But, there must be a reason for it. It would seem that using the switch would avoid the potential problem that the act of plugging and unplugging the drive would cause power fluctuations that could cause the hard drive to crash. So far, no issues. But now that this question has been posted, the external USB hard drive will be jinxed.;)
 
The reason you don't immediately unplug a USB hard drive has to do with an operating system practice called "write-behind." All I/O is queued to drives, in OR out. This is so that the O/S can let your program proceed while it takes care of the drudgery of I/O processing, which operates at device speeds. If they DIDN'T do this, your code would have to pause for milliseconds after every disk write. For SSDs? No problem, delay is very small, microseconds. For HDDs? Make that milliseconds - which on a modern computer operating at 2.5 GHz - represents 2.5 million instructions per millisecond.

So what happens is that the O/S defers the write-back, allowing the device driver to "get around to" the tedium of data writeback to the disk. BUT if you want to remove the device, you need to make the O/S "get around to it" faster - by EJECTING the device. This prioritizes all pending I/O calls to the device, thus making it "quiescent." That is the term used in driver writing, I didn't make it up, and I personally would have used "quiet" which is a perfectly good description. But the general driver protocol says to "quiesce" the device. Anyway, it's just a fancy way of saying to flush all pending device actions.

Turning off the USB with a switch BEFORE you quiesce the device is just as bad as pulling the USB connection. In either case, if you didn't first EJECT the device, you have the potential of lost data. Power fluctuations have nothing to do with it. Find the device icon and right-click it to see if it has the EJECT option. If it does, use that before removing a USB data storage device.

By the way, this "read-ahead" and "write-behind' I/O style is not unique to Windows. It also happens in UNIX flavors and in OpenVMS. They each have multiple approaches to how they manage all of the potential issues - but they all have the feature.
 
this reminds me of the "eject media" option in Windows that I haven't used one single time in the past 10 years with flash drives. they say it's best to do it, but I never have, and never had a problem
 
I believe the O/P uses Linux, so not sure it does the same?
 
I believe the O/P uses Linux, so not sure it does the same?
Either way, I wouldn't just turn off a button or yank out a drive without letting the operating system know first. Ejecting costs nothing and could save a drive from getting corrupt.
 
The reason you don't immediately unplug a USB hard drive has to do with an operating system practice called "write-behind." All I/O is queued to drives, in OR out. This is so that the O/S can let your program proceed while it takes care of the drudgery of I/O processing, which operates at device speeds. If they DIDN'T do this, your code would have to pause for milliseconds after every disk write. For SSDs? No problem, delay is very small, microseconds. For HDDs? Make that milliseconds - which on a modern computer operating at 2.5 GHz - represents 2.5 million instructions per millisecond.
Before unplugging, I issue the unmount (eject) action. So this aspect is not at issue.
believe the O/P uses Linux, so not sure it does the same?
Yes, using Linux. Before detaching the USB hard drive, I issue the unmount (eject) action.
this reminds me of the "eject media" option in Windows that I haven't used one single time in the past 10 years with flash drives. they say it's best to do it, but I never have, and never had a problem
When using a USB flash drive, there can be a significant delay in completing a write operation. I have a program that does a system backup. Because the system files take-up a lot of space it takes a long time before the write operation is done. It took a while to get used to that delay.
 
When using a USB flash drive, there can be a significant delay in completing a write operation.

At least if you have USB 3.0 capability, the delay is a lot less. But USB 2.0 is a relatively slow little beastie.
 

Users who are viewing this thread

Back
Top Bottom