PVE HDD Sleep (Suspend)

From WikiMLT
Revision as of 10:18, 3 September 2022 by Spas (talk | contribs) (Text replacement - "I/O Monitoring and Analyze" to "Linux I/O Monitoring and Analyze")

In or­der to force HDDs to sin down when they are idle at my sys­tem I was per­fumed few steps. Note at the sys­tem The HDDs are used on­ly for me­dia and back­up files, so all LVM par­ti­tions (where the vir­tu­al ma­chines and con­tain­ers are lo­cat­ed) are on SS­Ds and pvs­can doesn't need to touch them.

Set­up Home­made Script

The first at­tempt was by a home­made script. This ap­proach have a par­tic­u­lar suc­cess (be­cause pvs­can must be set­up as it is shown be­low) and it is not the most prop­er way to push the HDDs to sleep (be­cause it the script is trig­gered by Cron and doen't check does the dri­ve is ac­tu­al­ly in use). How­ev­er the script de­tects which of the at­tached stor­age de­vices are HDDs prop­er­ly.

nano /usr/local/bin/hdd-sleep.sh
#!/bin/bash
# @author:     Spas Z. Spasov <spas.z.spasov@metalevel.tech>
# @name:       hdd-sleep.sh
# @decription: Detect the HDDs on the system and push them to sleep.

main() {
    for sdX in /sys/block/sd*
    do
        if [[ $(cat "${sdX}/queue/rotational") == 1 ]]
        then
            sdX="${sdX//sys\/block/dev}"
            echo -n "Device:"
    
            if /usr/sbin/hdparm -C "$sdX" | grep -q 'active'
            then
                /usr/sbin/hdparm -y "$sdX"
            else
                /usr/sbin/hdparm -C "$sdX"
            fi
    
            echo ''
        fi
    done
    echo 'OK'
}
main #>/dev/null 2>&1
crontab -e
# Turn off HDDs
*/30 * * * * /usr/local/bin/hdd-sleep.sh > /var/log/cron.hdd-sleep.log 2>&1
watch cat /var/log/cron.hdd-sleep.log

man hd­parm: Get/​​​Set SATA/IDE de­vice pa­ra­me­ters.

#Hd­parm hints
sudo hdparm -B /dev/sda          # Get SSD AMP level
sudo hdparm -B 127 /dev/sda      # SET SSD AMP level
sudo hdparm -t /dev/sda          # SSD Timing buffered disk reads
sudo hdparm -t --direct /dev/sd  # SSD Timing buffered disk reads direct
sudo hdparm -S 1 /dev/sdb /dev/sdc /dev/sdd  # Set multiple devices to sleep

Set­up Prox­mox Vgscan/​​​Pvestatd

nano /etc/lvm/lvm.conf
devices {
    # added by pve-manager to avoid scanning ZFS zvols
    # global_filter=["r|/dev/zd.*|"]
    # added by Spas Z. Spasov
    global_filter=["r|/dev/zd.*|", "r|/dev/sdc.*|", "r|/dev/sdd.*|", "r|/dev/sdf.*|", "r|/dev/sdg.*|", "r|/dev/sdh.*|"]
}
vgscan

In­stall and Set­up Hd-idle

wget https://github.com/adelolmo/hd-idle/releases/download/v1.16/hd-idle_1.16_amd64.deb
dpkg -i hd-idle_1.16_amd64.deb
nano /etc/default/hd-idle
#START_HD_IDLE=false
START_HD_IDLE=true
#HD_IDLE_OPTS="-i 180 -l /var/log/hd-idle.log"
HD_IDLE_OPTS="-i 60 -l /var/log/hd-idle.log"

The same steps are done at the gust vir­tu­al ma­chines, which have di­rect ac­cess to the HDDs.

Get Sta­tis­tic of a Da­ta Dri­ve Us­age

apt install dstat
dstat -D sdc -ta --top-bio
----system---------total-cpu-usage-------dsk/sdc------net/total------paging-------system--------most-expensive--------
     time      | usr sys idl wai stl | read   writ | recv   send |  in   out  | int   csw  |  block     i/o   process
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
02-04 09:25:42 |  2   0  97   0   0  | 160k   208k |   0      0  | 170B  835B | 1951  7955 | systemd    1285k 1569k
02-04 09:25:43 |  2   1  97   0   0  |   0      0  |  66k    57k |   0     0  | 2614  5033 | pvestatd   1280k    0
02-04 09:25:44 |  2   1  98   0   0  |   0      0  |  16k    21k |   0     0  | 2830  7131 | kvm           0    32k
02-04 09:25:45 |  2   1  98   0   0  |   0      0  |  45k    54k |   0     0  | 2347  5187 | kvm           0   320k
02-04 09:25:46 |  3   1  96   0   0  |   0      0  |  24k    29k |   0     0  | 2686  8578 | ceph-mon      0    64k

Ref­er­ences