HDD standby/spindown

Status
Not open for further replies.

Ef57uiKnN6

Dabbler
Joined
Mar 25, 2012
Messages
28
Just wrote a small shell script (foobar.sh.txt) as proof of concept for getting all my spindles in standby.

It periodically gathers standby values from the database for every active device and spins them down manually depending on last I/O.
Before investing more time I want to ask if there is a better/simpler way to get all drives (especially the LSI ones) spin down as configured.

My Environment:
- FreeNAS-8.3.1-BETA1-x64 (r12955:12956)
- FreeNAS-9.2.0-RELEASE-x64 (ab098f4) / Since hdd_spindown-0.3
- GIGABYTE F2A85X-D3H
- LSI SAS 9211-4l
- WDC WD20EFRX

Edit:
Removed hyper link to 'foobar.sh.txt and added attachment the way it seems to work (for me)
It's not tested very well AND has a lot room for improvement (like usage information)

What it does:
  • Query all names and standby times for active drives from FreeNAS configuration
  • Loop through all drives and compare current and last (memorized) I/O-transfer count. On difference memorize new value and time.
  • Spin down drives which last activity exceeds time-out
  • Sleep between loop iterations as long as the lowest time-out of any drive would occur.
  • Refresh standby times from FreeNAS after 12 iterations
Some notes about the (sledgehammer) way spinning down is achieved.
Spin down is tried sequentially by camcontrol, atacontrol, ataidle and can easily be extended. The first successfully command is memorized individually per drive for further rounds. If no command ends successful, the drive gets marked to be ignored and will not tried to be span down in the future.

View attachment hdd_spindown-0.4.zip
View attachment hdd_spindown-0.3.zip
View attachment hdd_spindown-0.2.zip
View attachment hdd_spindown-0.1.zip

Changelog
0.4
Previously uploaded 0.4 file contained minor cosmetic issues​
0.4
New: Usage, one-shot mode, initial spin down, version message​
Bugfix: Message severity format on stdout, pass custom parameters on fork​
0.3
Improvement: Added ataidle with absolute path. Because ataidle wants absolute path '$DEV' varaible can be used in command definitions.​
Bugfix: INSTALL file corrected - thx to bulli.uli!​
0.2
Bugfix: Correct array usage and changed position of counter variable​
0.1
Initial release​
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Interesting. I wish I had a test system to check it out. If this works as expected then I'm sure you will have made a few people happy. There are a few other threads out there that deal with spinning down the drives, I would suggest you find a few of those and post a link to this thread asking people to check it out.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Soo.. why not use the built-in spindown options in FreeNAS? This sounds like you took something simple and made it quite complex.

Edit: I'm not trying to discredit your work. But considering the work you put into it I'm guessing there's something I'm missing somewhere.
 

Stephens

Patron
Joined
Jun 19, 2012
Messages
496
I'd guess it's because in some configurations, drives don't spin down with the options included in FreeNAS. Thus he has expanded the options to try to get the drives to spin down in his script (camcontrol, atacontrol, ataidle).
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Actually FreeNAS only uses ataidle unless it has recently changed and ataidle doesn't work for many add-on cards. Camcontrol is typically able to handle add-on card situations but even then it's not 100% certain you will be able to command the drive to idle. There are a few threads on this and I was hitting this pretty hard last year until ataidle was updated and it was implemented properly in FreeNAS. The last thing to be implemented is the command having an immediate affect vice waiting for a reboot of the system. I don't know if that has been included in 8.3.1-BETA1 or not.
 

Kolkrabi

Dabbler
Joined
Sep 15, 2013
Messages
11
Sounds promising. I will give it a try on my system and report how it worked out for me.
 

gaidin

Cadet
Joined
Sep 20, 2013
Messages
4
script is pretty buggy...

hdd_spindown.sh: 98 Syntax error: redirection unexpected

appreciate the gesture though! I haven't been able to get the spindown package really working to a decent standard...
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Actually, it worked just fine until 9.x came out. If you look, this script was ressurected from 9 months ago....
 

gaidin

Cadet
Joined
Sep 20, 2013
Messages
4
Ah yes, good point :)

Why would they deprecate support for scripting code though in a new release...seems strange that a new release wouldn't be backwards compatible???

I need to work out a way of getting spindown working reliably though. My power draw with all disks spun up is 180W, and only 75W at idle... I love FreeNAS and a ZFS solution, but when the wife gets the next power bill I suspect I am headed back to using the Areca RAID controller under Win 2008 unfortunately.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Frankly, I'd say there's about no chance she'll figure out that your computer is responsible for the electric bill.

Even at 180w(full load) 24x7 for a whole month, at 15c per KwH that only adds up to a whopping $20. I doubt she's going to notice that $20 considering the fluctuations between months on your bill.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Ah yes, good point :)

Why would they deprecate support for scripting code though in a new release...seems strange that a new release wouldn't be backwards compatible???

I need to work out a way of getting spindown working reliably though. My power draw with all disks spun up is 180W, and only 75W at idle... I love FreeNAS and a ZFS solution, but when the wife gets the next power bill I suspect I am headed back to using the Areca RAID controller under Win 2008 unfortunately.
Not sure what you mean by deprecating support, iX Systems isn't on the hook to make sure someones script works, it's up to the person running the script to make things right.

You haven't posted any real information about your problem other than a script error. You need to provide data like your complete system hardware setup. When I say complete, that include model numbers of the components. It's damn hard to help when we don't have a clue what we are up against. And I'm not saying that I'd help out, I still haven't used this script only because I leave my drives spinning all the time and I have a very busy life over the past few months, not sure when I could help but someone may.
 

gaidin

Cadet
Joined
Sep 20, 2013
Messages
4
I wasn't suggesting that iX Systems should check that each and every user script should work...but this is just a simple script we're talking about. If I go and write a javascript or vbscript object today then it will retain support in many iterations of IE/Chrome/Firefox for years to come. The fact that this one won't work from FreeNas8 over to FreeNas9 I find very strange. It's not even doing anything particularly rare - it works out the names of the zPools you're running, steps through the SQLite db looking for devices linked to that pool, then queries the device to find out when it was last accessed...and if that is beyond a given timeframe then it spins the device down. Kudos to the author for publishing it so that others could overcome the shortcoming that he/she also encountered.

The fact that a script is actually needed in order to accomplish a function desired by most people running more than 3 or 4 disks is a sad indictment itself...

I understand that you get what you pay for in life and that its rather rude of me to expect support for my particular scenario in a free product, but a little polish to the platform wouldn't go astray! I can have an OpenELEC HTPC up with access to NAS shares and running a dual HD tv tuner within 15 mins. Why can't I set a power profile for my disks in a product that is essentially a file server that you would expect to be full of them?

I'll keep working on re-coding this script (or Millhouse's that aims for the same goal) to be compatible with 9.1 and post back to share it if I have any success :)
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
You do realize that going from FreeNAS8 to FreeNAS9 is like going from XP to Vista. A cubic boatload of stuff broke when Vista came out. It's inevitable. Also, scripts often make alot of assumptions, such as how many disks you have, what type of controller you ahve attached, the location that the script is located in, etc.

Rule #1 for scripts in pretty much all nix's is you should learn scripting so you can check out the script for yourself. Especially to make sure nothing really bad happens, such as deleting directories that it shouldn't be deleting, etc.

Rule #2 for scripts is that you should share what you have created that might be valuable to others.

I've posted a few scripts myself. And although they are very customizable, you definitely will need to edit every single one to make it work for oyur exact configuration.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
The problem is the ataidle command in FreeBSD does not accommodate dare I say most add-on boards which would require a camcontrol command to handle the shutdown. The limitation isn't with FreeNAS. So when you think of it, it's a limitation of compatible hardware. Also I would venture to say that add-on boards like SAS controllers are typically built for server farms (both small and large) and would typically expect the drives to be running all the time to allow for fast access to the data. If you have lets say 4 to 6 hard drives, I would expect them to be connected to the MB SATA connectors so I'm a bit shocked that ataidle doesn't handle it. If you have more drives and using an add-on card, I wouldn't be shocked at all that ataidle doesn't spin those connected drives down.

Might I ask how your drives are connected to your machine? I'm very familiar with ataidle and camcontrol, I have talked to Bruce who wrote the ataidle code as well a few years ago when I was tackling this same problem with FreeNAS 8.0.x not spinning drives down very well. Also where are you installing this script (in a jail or not and location).

The real fix for the entire problem is an updated ataidle program to accommodate this type of issue. Bruce was unwilling to do such an update a few years ago which I believe was because he didn't have the hardware to test these modification on. Of course you could just create a custom version yourself and build that into a FreeNAS distribution for yourself. That would the by far the best way to handle it and if you were able to get enough testing support, maybe you could submit a new version to FreeBSD.org which I would think be awesome.

Hope this helps.
 

gaidin

Cadet
Joined
Sep 20, 2013
Messages
4
Yeah, I agree with both of your thoughts... ;)

I need to stop procrastinating and update this script.

By way of further detail (which I probably should have posted originally) my build is as follows:

FreeNAS 9.1.0 Release (no plugins or jails running because I run a RaspPi for all my media meta management and a OpenELEC HTPC for viewing)
Case: Norco 4224 chassis
M/b: Asus P8B WS
CPU: Intel Xeon E3 1225v2
RAM: 32Gb Kingston ECC 1600
HBA: 2 x IBM M1015 flashed to LSI IT mode
Disk: 16 x 3Tb Hitachi connected to 4 of the SAS backplanes in the Norco (1 M1015 driving two of the backplanes each)

So far I have tried Millhouse's script and found that it was incompatible when trying to call the SQLite DB and return the list of devices - it failed somewhere around there, but this language is new to me so I am fumbling around a little with the syntax!

I have also had a test at using the spindown package...which seems to work the first iteration of spindown, but then once the disks are accessed and fire up again it doesn't want to spin them down a second time.

And then thirdly I found this script here to try.

I guess if I am not making use of any plugins or jails then I won't be missing much in regressing back to v8.3.2 and try running this script there where it "should" be compatible? I haven't actually started copying the content across to the NAS yet as I have been testing the various ZFS solutions for the last month before committing to one :)

My goals in getting the spindown/standby functionality are twofold. Firstly I would like to save some electricity usage and secondly I would hope to get a longer life out of all those disks!
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Yea, I figured you were running add-on cards. As for improving the life of your drive by spinning them down, well it depends on how long they stay down/the frequency they need to spin up. Spinning up a drive too frequently will kill a drive very fast so choose your spindown time appropriately. I use to spin my drives down after 3 hours of inactivity. This was based on several factors as I knew when my drives would typically be accessed (between the hours of 2PM through 2AM and accessing would normally not exceed a 2 hour span with no activity. Now I leave them up because I've read reports which state the drives will last longer. I'm sure there are reports in the other direction to some extent. We will do what we want to do.

So, my advice is to open up a SSH window into the FreeNAS and figure out which command will force a drive down. Do this for each drive. Once you have the commands then you place those into a simple script. This will be customized to you and that is okay. Now all you need to do it run the script. Okay, that was very simplistic of course, but you will need to integrate this into one of the scripts which check to see if the drive is inactive but at least now you have the commands you need. You could use those commands to adjust the script.

As far as the original problem, it's a syntax error on line 98 of your script. Have you looked at it and compared it to the original? It's talking about a redirection so maybe you have a carriage return in there or a tab character? This may be a simple fix.

Check to see what line 98 is, I think it's this one (you need to double check):
Code:
debug "Values from database are syntactically correct: COL1=$COL1, COL2=$COL2"

You just need to figure out what is wrong with this statement and why is changed from 8.x to 9.x.

EDIT: Since this is a debug command, just change it to read something like "debug "Lucy something is wrong here." and see what happens. Assuming this really is the 98th line in the code.
 

silverback1

Cadet
Joined
Jun 21, 2013
Messages
6
Hello to all,

Given the widespread use of the M1015 HBA on Freenas machines, is there any chance the developers can make spindown functional for the HBA
from the GUI.

Thanks,

Seth
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
I'm sure it's possible but I doubt they would entertain this. You could submit a feature request and see what happens. Even better, create an application solution and submit that. It's work on your part but many of us do this kind of work to help ourselves and help others, and it's educational. :)
 

Ef57uiKnN6

Dabbler
Joined
Mar 25, 2012
Messages
28
Finally found the time to start my (originally as replacement planned) 2nd FreeNAS server to see how current version of FreeNAS feels.
After successful upgrade to 9.2 i noticed that no deposited comand was able to spindown the ada* drives.
There were two issues:
  1. ataidle was not found anymore in the respective path environment and had to be used with absolute path
  2. ataidle wants the path to device as well.
I've fixed the first by just adding commands with absolute path
The second has been fixed by supporting varaible evaluation:
Code:
SPINDOWN_CMD+=('/usr/local/sbin/ataidle -s /dev/$DEV')


Unfortunately I didn't encounter the previously mentioned syntax error. Except the mentioned issues everything works fine:

Code:
Jan 11 21:03:15 freenas2 hdd_spindown[6465]: Configured HDD standby times will be refreshed after every '12' checks
Jan 11 21:03:15 freenas2 hdd_spindown[6466]: Initial check does not spin down any drive
Jan 11 21:03:15 freenas2 hdd_spindown[6471]: Drive da0 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6472]: Drive da1 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6473]: Drive da2 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6474]: Drive ada0 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6475]: Drive ada1 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6477]: Drive ada2 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6479]: Drive ada3 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6481]: Drive ada4 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6482]: Drive ada5 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6484]: Drive ada6 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6486]: Drive ada7 is configured to be spun down after '300' seconds of inactivity
Jan 11 21:03:15 freenas2 hdd_spindown[6558]: Sleeping '300' seconds till next check. '11' checks left to next update of HDD standby times.
Jan 11 21:08:16 freenas2 hdd_spindown[6919]: Spinning down drive by command 'camcontrol stop ada7' failed
Jan 11 21:08:16 freenas2 hdd_spindown[6922]: Spinning down drive by command 'atacontrol spindown ada7' failed
Jan 11 21:08:16 freenas2 hdd_spindown[6925]: Spinning down drive by command 'ataidle -s /dev/ada7' failed
Jan 11 21:08:16 freenas2 hdd_spindown[6929]: Drive 'ada7' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada7'
Jan 11 21:08:16 freenas2 hdd_spindown[6932]: Spinning down drive by command 'camcontrol stop ada6' failed
Jan 11 21:08:16 freenas2 hdd_spindown[6935]: Spinning down drive by command 'atacontrol spindown ada6' failed
Jan 11 21:08:16 freenas2 hdd_spindown[6938]: Spinning down drive by command 'ataidle -s /dev/ada6' failed
Jan 11 21:08:17 freenas2 hdd_spindown[6941]: Drive 'ada6' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada6'
Jan 11 21:08:17 freenas2 hdd_spindown[6944]: Spinning down drive by command 'camcontrol stop ada5' failed
Jan 11 21:08:17 freenas2 hdd_spindown[6947]: Spinning down drive by command 'atacontrol spindown ada5' failed
Jan 11 21:08:17 freenas2 hdd_spindown[6950]: Spinning down drive by command 'ataidle -s /dev/ada5' failed
Jan 11 21:08:17 freenas2 hdd_spindown[6953]: Drive 'ada5' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada5'
Jan 11 21:08:17 freenas2 hdd_spindown[6956]: Spinning down drive by command 'camcontrol stop ada4' failed
Jan 11 21:08:17 freenas2 hdd_spindown[6959]: Spinning down drive by command 'atacontrol spindown ada4' failed
Jan 11 21:08:17 freenas2 hdd_spindown[6962]: Spinning down drive by command 'ataidle -s /dev/ada4' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6966]: Drive 'ada4' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada4'
Jan 11 21:08:18 freenas2 hdd_spindown[6969]: Spinning down drive by command 'camcontrol stop ada3' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6972]: Spinning down drive by command 'atacontrol spindown ada3' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6975]: Spinning down drive by command 'ataidle -s /dev/ada3' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6978]: Drive 'ada3' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada3'
Jan 11 21:08:18 freenas2 hdd_spindown[6981]: Spinning down drive by command 'camcontrol stop ada2' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6984]: Spinning down drive by command 'atacontrol spindown ada2' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6987]: Spinning down drive by command 'ataidle -s /dev/ada2' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6990]: Drive 'ada2' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada2'
Jan 11 21:08:18 freenas2 hdd_spindown[6993]: Spinning down drive by command 'camcontrol stop ada1' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6996]: Spinning down drive by command 'atacontrol spindown ada1' failed
Jan 11 21:08:18 freenas2 hdd_spindown[6999]: Spinning down drive by command 'ataidle -s /dev/ada1' failed
Jan 11 21:08:19 freenas2 hdd_spindown[7003]: Drive 'ada1' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada1'
Jan 11 21:08:19 freenas2 hdd_spindown[7006]: Spinning down drive by command 'camcontrol stop ada0' failed
Jan 11 21:08:19 freenas2 hdd_spindown[7009]: Spinning down drive by command 'atacontrol spindown ada0' failed
Jan 11 21:08:19 freenas2 hdd_spindown[7012]: Spinning down drive by command 'ataidle -s /dev/ada0' failed
Jan 11 21:08:19 freenas2 hdd_spindown[7015]: Drive 'ada0' successfully spun down by command '/usr/local/sbin/ataidle -s /dev/ada0'
Jan 11 21:08:20 freenas2 hdd_spindown[7019]: Drive 'da2' successfully spun down by command 'camcontrol stop da2'
Jan 11 21:08:21 freenas2 hdd_spindown[7022]: Drive 'da1' successfully spun down by command 'camcontrol stop da1'
Jan 11 21:08:21 freenas2 hdd_spindown[7025]: Drive 'da0' successfully spun down by command 'camcontrol stop da0'
Jan 11 21:08:21 freenas2 hdd_spindown[7029]: Sleeping '300' seconds till next check. '10' checks left to next update of HDD standby times.
 

Ef57uiKnN6

Dabbler
Joined
Mar 25, 2012
Messages
28
script is pretty buggy...

hdd_spindown.sh: 98 Syntax error: redirection unexpected

appreciate the gesture though! I haven't been able to get the spindown package really working to a decent standard...

Even if I can't reproduce the issue, you might want give these varaitions a try (not tested):
Code:
--- hdd_spindown.sh.orig    2013-01-11 19:21:56.000000000 +0100
+++ hdd_spindown.sh    2014-01-11 21:48:19.783856667 +0100
@@ -95,7 +95,7 @@
    info "Drive ${DISK_DEV[$CNT]} is configured to be spun down after '${DISK_TIMEOUT[$CNT]}' seconds of inactivity"
    ((CNT++))
  done <<- EOT
-    $(query_db <<< $(print_sql_devices))
+    $(query_db <<< "$(print_sql_devices)")
    EOT
}

Code:
--- hdd_spindown.sh.orig    2013-01-11 19:21:56.000000000 +0100
+++ hdd_spindown.sh    2014-01-11 21:54:06.540767609 +0100
@@ -95,7 +95,7 @@
    info "Drive ${DISK_DEV[$CNT]} is configured to be spun down after '${DISK_TIMEOUT[$CNT]}' seconds of inactivity"
    ((CNT++))
  done <<- EOT
-    $(query_db <<< $(print_sql_devices))
+    $(echo "$(print_sql_devices)" | query_db)
    EOT
}
 
Status
Not open for further replies.
Top