Utility to automatically suspend the system with low load on Linux. This is useful for saving power on hosts that will temporarily be under heavy load, but cannot automate the suspend process due to the nature of the workload, such as running a Windows build in a guest VM.
https://gitlab.com/brlin/linux-low-load-autosuspend
#linux #suspend-to-ram #power-management #utility #bash
The following features are provided by this utility:
- Accounting for the number of physical CPU cores on the system.
- Monitoring behaviors can be easily customized by environment variables.
- Would bail out when:
- The runtime dependencies are not met.
- Any unhandled error occurs during the monitoring process.
This utility requires a Linux system with the following software installed and their commands available in the command search PATHs:
- GNU AWK (gawk)
For parsing system load information from/proc/loadavg
. - GNU Bash
Provides the runtime where the monitoring program runs in. - GNU bc
For floating-point arithmetic calculations of load thresholds. - GNU coreutils
Provideshead
,sort
,tee
,uniq
, andwc
commands for text processing. - GNU grep
For filtering CPU information from/proc/cpuinfo
. - systemd
Provides thesystemctl
command for system suspend functionality.
The monitoring program must be run as a superuser (root) user, as it needs to call the systemctl suspend
command to suspend the system.
Refer to the following instructions to use this utility:
-
Download the release archive from the Releases page.
-
Extract the release archive to a directory of your choice.
-
Launch a text terminal.
-
In the text terminal, run the following command as root to start the automatic suspend monitoring process:
sudo /path/to/linux-low-load-autosuspend-X.Y.Z/suspend-linux-when-low-load.sh
Replace the
X.Y.Z
placeholder text to the actual version number of the release archive you downloaded.You can customize the monitoring behavior by using the environment variables documented in the "Environment variables that can influence the behavior of the utility" chapter
The following environment variables can be set to influence the behavior of the utility:
The average system load ratio threshold to trigger the suspend process, it is a ratio of the number of CPU physical cores on the system(not accounting virtual cores as a result of hyper-threading-like mechanisms). If the average system load is below this threshold, the system will be suspended.
The default value is 0.5
, which means for a system with 8 physical CPU cores and 16 total threads, the average system load threashold is 4.0
(8 * 0.5).
Time (in seconds) between each load check.
Default value: 300
(5 minutes)
How many consecutive "low load" check results should the monitoring utility give the verict that the system's load is low. This prevents accidental suspend during momentary dips.
Default value: 3
If you encounter any issues with the utility, please check the logs: /var/log/suspend-linux-when-low-load.log.
The following materials are referenced during the development of this project:
- "How do I make a Linux system go to sleep after the average system load is under a certain threshold?" LLM response - HackMD
Provides the initial implementation.
Unless otherwise noted(comment headers/REUSE.toml), this product is licensed under the 3.0 version of the GNU Affero General Public License, or any of its more recent versions of your preference.
This work complies to the REUSE Specification, refer to the REUSE - Make licensing easy for everyone website for info regarding the licensing of this product.