Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Keeping hard drive from spinning down

33 views
Skip to first unread message

DFS

unread,
Oct 1, 2022, 10:40:19 AM10/1/22
to
Got a new mobo and chip: AMD 5600G (w/ integrated graphics). Windows
10. Was having a weird issue: my SATA HDD was spinning up every time I
needed to read or write a file.

Couldn't hear it spin down, but it must have because it almost always
made a high-pitched whine accompanied by a short system hang when I
tried to open or save a file after some minutes.

The drive is old but not nearly full, and passed all SMART tests.

To keep it spinning I wrote a little program to read/access a file every
so often. This program runs continuously until killed.

Note: it writes a tiny file to the directory it resides in.

========================================================================
DriveAlive.c
========================================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>


//usage:
//for testing: $ progname N (where N is seconds between 15 and 300)
// or
//for production, run program in background
// $ progname N & (Linux, view in top)



//flag: 0 for production, 1 for testing (testing outputs messages to
terminal)
//NOTE:if you run the program in test mode in the background, it's a
pain to stop it,
//so just delete the DriveAlive.txt file and it'll abort within 10 seconds
int appstatus = 0;


int main(int argc, char *argv[]) {

//vars
char *tmpfile = "DriveAlive.txt";
FILE *ftmp;

//interval from command line
int interval = atoi(argv[1]);
while(interval < 15 || interval > 300)
{
printf("Enter file check interval in seconds (15 to 300): ");
scanf("%d", &interval);
}


//testing uses 10sec interval
if(appstatus == 1) { interval = 10; }


//write temp file
time_t t;
time(&t);
ftmp = fopen(tmpfile, "w");
fprintf(ftmp,"This file was created by DriveAlive on %s",ctime(&t));
fclose(ftmp);
if(appstatus == 1) { printf("DriveAlive was started in test mode.\n"); }



//program runs continuously
//testing: show countdown between file checks
int cnt = interval;
while (1) {
for (int i = 0; i < interval; i++) {

//testing
if(appstatus == 1) {
printf("\r%d seconds until next file access ",cnt);
fflush(stdout);
}

//pause then decrement countdown counter
sleep(1);
cnt--;

//access file at end of countdown
if(cnt == 0) {
cnt = interval;
ftmp = fopen(tmpfile, "r");
if(ftmp == NULL){
printf("\nDriveAlive stopped: failed to open DriveAlive.txt\n");
return -1;
}
fclose(ftmp);
if(appstatus == 1) { printf("\rtesting: file was opened \n"); }
}
}
}


return(0);

}


========================================================================



Thoughts on the code?

Other strategies for keeping the disk from spinning down?

Thanks


Jens Stuckelberger

unread,
Oct 1, 2022, 3:00:09 PM10/1/22
to
On Sat, 1 Oct 2022 10:40:04 -0400, DFS wrote:

> Got a new mobo and chip: AMD 5600G (w/ integrated graphics). Windows
> 10. Was having a weird issue: my SATA HDD was spinning up every time I
> needed to read or write a file.
>
> Couldn't hear it spin down, but it must have because it almost always
> made a high-pitched whine accompanied by a short system hang when I
> tried to open or save a file after some minutes.
>
> The drive is old but not nearly full, and passed all SMART tests.
>
> To keep it spinning I wrote a little program to read/access a file every
> so often. This program runs continuously until killed.

Doesn't Windows have something similar to the Unix touch command?

rbowman

unread,
Oct 1, 2022, 3:11:32 PM10/1/22
to
You can change the timestamps in PowerShell but I don't know if it would
be any easier.

Scott Lurndal

unread,
Oct 1, 2022, 3:28:06 PM10/1/22
to
All touch does is update the last accessed date in the inode. Which may
never be flushed from the in-memory cache until the filesystem is sync'd.

Ben Bacarisse

unread,
Oct 1, 2022, 4:37:44 PM10/1/22
to
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> This is comp.lang.c.

Yes, and this thread is a great example of why posting in the wrong
group is unhelpful. The OP needs to be directed to a group that can
explain how to get either the OS or the drive to do what's wanted. I
can't do that because I don't know any technically proficient Windows
groups.

(On Linux, I used to use the hdparm command, but that was years ago
before I had SSDs.)

> So here is a quick attempt at a "touch"
> that's supposed to change the modification time of an existing
> file "example.txt":

This might work or it might not. But even if it does work, it's not
really the right way to do it.

--
Ben.

olcott

unread,
Oct 1, 2022, 4:55:21 PM10/1/22
to
On 10/1/2022 9:40 AM, DFS wrote:
> Got a new mobo and chip: AMD 5600G (w/ integrated graphics).  Windows
> 10.  Was having a weird issue: my SATA HDD was spinning up every time I
> needed to read or write a file.
>

Control Panel
search for "power"
under edit power plan choose
Change advanced power settings
Hard disk
Turn off hard disk after
Setting (Minutes): 20 // mine is set to 20 minutes

--
Copyright 2022 Pete Olcott "Talent hits a target no one else can hit;
Genius hits a target no one else can see." Arthur Schopenhauer


Manfred

unread,
Oct 1, 2022, 9:17:12 PM10/1/22
to
On 10/1/2022 4:40 PM, DFS wrote:
[...]
> Thoughts on the code?
>
> Other strategies for keeping the disk from spinning down?
>
> Thanks

As Ben mentioned, the code is the wrong solution for the problem.
The main problem is that you appear to have the timings of powersave
mode wrong .
This is controlled by the OS and BIOS, so that's where to look for a
solution.
One wild guess: see that Windows and the BIOS correctly identify the
drive as HDD, not SSD.

Incidentally, this has nothing to do with the C language.
Or, it may be considered pertinent wrt the assumption of C being
considered a synonym for IT.


olcott

unread,
Oct 1, 2022, 9:41:43 PM10/1/22
to
On 10/1/2022 8:16 PM, Manfred wrote:
> On 10/1/2022 4:40 PM, DFS wrote:
> [...]
>> Thoughts on the code?
>>
>> Other strategies for keeping the disk from spinning down?
>>
>> Thanks
>
> As Ben mentioned, the code is the wrong solution for the problem.
> The main problem is that you appear to have the timings of powersave
> mode wrong .
> This is controlled by the OS and BIOS, so that's where to look for a
> solution.
> One wild guess: see that Windows and the BIOS correctly identify the
> drive as HDD, not SSD.

Paul

unread,
Oct 2, 2022, 5:04:39 AM10/2/22
to
On 10/1/2022 10:40 AM, DFS wrote:
> Got a new mobo and chip: AMD 5600G (w/ integrated graphics).  Windows 10.  Was having a weird issue: my SATA HDD was spinning up every time I needed to read or write a file.
>
> Couldn't hear it spin down, but it must have because it almost always made a high-pitched whine accompanied by a short system hang when I tried to open or save a file after some minutes.
>
> The drive is old but not nearly full, and passed all SMART tests.
>
> To keep it spinning I wrote a little program to read/access a file every so often.  This program runs continuously until killed.
>
> Note: it writes a tiny file to the directory it resides in.
>
> ========================================================================
> DriveAlive.c
> ========================================================================
>
> Other strategies for keeping the disk from spinning down?
>
> Thanks

http://disablehddapm.blogspot.com/p/1.html

https://linux.die.net/man/8/hdparm

I'm not convinced these things always work, as the
power management on some drive firmwares is quite
busted. AAM was the subject of some legal
action years ago, which is why it is such a mess.
It's not clear how they decide what to do with APM.

https://www.engadget.com/2009-12-29-ex-seagate-employee-claims-the-company-stole-mit-research-tried.html

I don't really know if the APM indicator is reliable
or not, or is programmable when you want it to be programmed.

[Picture]

https://i.postimg.cc/52qPGfmr/disk-sampler.gif

*******

Switching to an SSD, you won't hear a thing. If they
go through PM states, it likely won't take long.
With nothing to spin, there's nothing to spin up.

"Idle wake up time, microseconds"

https://images.anandtech.com/graphs/graph12165/pm-wake-up.png

Paul


olcott

unread,
Oct 2, 2022, 11:13:39 AM10/2/22
to

Chris M. Thomasson

unread,
Oct 2, 2022, 3:33:51 PM10/2/22
to
On 10/2/2022 2:04 AM, Paul wrote:
> On 10/1/2022 10:40 AM, DFS wrote:
>> Got a new mobo and chip: AMD 5600G (w/ integrated graphics).  Windows
>> 10.  Was having a weird issue: my SATA HDD was spinning up every time
>> I needed to read or write a file.
>>
>> Couldn't hear it spin down, but it must have because it almost always
>> made a high-pitched whine accompanied by a short system hang when I
>> tried to open or save a file after some minutes.
>>
>> The drive is old but not nearly full, and passed all SMART tests.
>>
>> To keep it spinning I wrote a little program to read/access a file
>> every so often.  This program runs continuously until killed.
>>
>> Note: it writes a tiny file to the directory it resides in.
>>
>> ========================================================================
>> DriveAlive.c
>> ========================================================================
>>
>> Other strategies for keeping the disk from spinning down?
>>
>> Thanks
>
> http://disablehddapm.blogspot.com/p/1.html
>
> https://linux.die.net/man/8/hdparm
>
> I'm not convinced these things always work, as the
> power management on some drive firmwares is quite
> busted. AAM was the subject of some legal
> action years ago, which is why it is such a mess.
> It's not clear how they decide what to do with APM.
[...]

I cannot remember right now, but I think the ALOM on a Sun server would
work with the hard drives? I had a SunFire T2000 server for a while,
then I sold it. I won it for a CoolThreads contest.


0 new messages