KSMTUNED(8)

NAME
ksmtuned - dynamically tune Kernel Samepage Merging (KSM) for qemu workloads

SYNOPSIS
ksmtuned

DESCRIPTION
ksmtuned is a background tuning daemon implemented as a shell script. It periodically estimates memory pressure from running qemu processes and adjusts Linux KSM aggressiveness by writing to sysfs controls.

At startup, the daemon optionally sources /etc/ksmtuned.conf and computes:

•   Total RAM from /proc/meminfo.

•   A memory threshold based on KSM_THRES_COEF and KSM_THRES_CONST.

•   A sleep interval for KSM scans derived from total memory and KSM_SLEEP_MSEC.

Every KSM_MONITOR_INTERVAL seconds, it:

1.  Sums RSS for running qemu processes.

2.  Checks available memory (MemFree + Buffers + Cached).

3.  Stops KSM when memory pressure is low.

4.  Otherwise starts KSM and updates pages_to_scan using boost/decay logic.

The daemon traps SIGUSR1 while running; this wakes the wait cycle so the next adjustment can happen promptly after VM start/stop events.

OPTIONS
ksmtuned has no command-line options. Behavior is configured through environment/configuration variables.

CONFIGURATION VARIABLES
The following variables may be set in /etc/ksmtuned.conf:

KSM_MONITOR_INTERVAL
    Seconds between tuning passes (default: 60).

KSM_NPAGES_BOOST
    Increment applied to pages_to_scan when free memory is below threshold (default: 300).

KSM_NPAGES_DECAY
    Adjustment applied when free memory is above threshold (default: -50).

KSM_NPAGES_MIN
    Minimum pages_to_scan (default: 64).

KSM_NPAGES_MAX
    Maximum pages_to_scan (default: 1250).

KSM_SLEEP_MSEC
    Base sleep millisecs used to compute /sys/kernel/mm/ksm/sleep_millisecs (default: 10).

KSM_THRES_COEF
    Percent of total memory used in threshold calculation (default: 20).

KSM_THRES_CONST
    Minimum threshold in KiB (default: 2048).

PIDFILE
    Path to write daemon PID (default: /var/run/ksmtune.pid).

DEBUG
    If non-empty, enable debug logging.

LOGFILE
    Optional log destination used when DEBUG is set.

FILES

/etc/ksmtuned.conf
    Optional runtime configuration.

/proc/meminfo
    Source for total/free memory data.

/sys/kernel/mm/ksm/run
    Enable/disable KSM.

/sys/kernel/mm/ksm/pages_to_scan
    Tune KSM scan intensity.

/sys/kernel/mm/ksm/sleep_millisecs
    Tune pause between KSM scans.

/var/run/ksmtune.pid
    Default PID file for the spawned loop process.

SEE ALSO
ksmctl(1), systemd(1), proc(5), ksm(7)