Skip to content

brlin-tw/linux-low-load-autosuspend

Repository files navigation

Linux automatic low system load suspend utility

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
The GitLab CI pipeline status badge of the project's main branch GitHub Actions workflow status badge pre-commit enabled badge REUSE Specification compliance badge
#linux #suspend-to-ram #power-management #utility #bash

Features ✨

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.

Prerequisites ⚙️

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
    Provides head, sort, tee, uniq, and wc commands for text processing.
  • GNU grep
    For filtering CPU information from /proc/cpuinfo.
  • systemd
    Provides the systemctl 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.

Usage 📖

Refer to the following instructions to use this utility:

  1. Download the release archive from the Releases page.

  2. Extract the release archive to a directory of your choice.

  3. Launch a text terminal.

  4. 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

Environment variables that can influence the behavior of the utility 🔧

The following environment variables can be set to influence the behavior of the utility:

LOAD_THRESHOLD_RATIO

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).

CHECK_INTERVAL

Time (in seconds) between each load check.

Default value: 300 (5 minutes)

CONSECUTIVE_CHECKS_REQUIRED

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

Troubleshooting 🐞

If you encounter any issues with the utility, please check the logs: /var/log/suspend-linux-when-low-load.log.

References 📚

The following materials are referenced during the development of this project:

Licensing 📄

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.

About

Utility service to automatically suspend devices with low load on Linux.

Topics

Resources

Stars

Watchers

Forks

Languages