ksmtuned-4.20150325build1/0000775000000000000000000000000012504614431011742 5ustar ksmtuned-4.20150325build1/debian/0000775000000000000000000000000013260672034013167 5ustar ksmtuned-4.20150325build1/debian/rules0000775000000000000000000000062512504614431014247 0ustar #!/usr/bin/make -f CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS) CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS) LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) %: dh $@ --with systemd ksmctl: ksmctl.c gcc $< -O2 -g $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ build-arch: ksmctl dh $@ --with systemd build: build-arch build-indep binary: binary-arch binary-indep binary-arch: install ksmtuned-4.20150325build1/debian/install0000664000000000000000000000020512504614431014552 0ustar ksm etc/default *.service lib/systemd/system ksmctl usr/sbin ksmtuned usr/sbin ksmtuned.conf etc ksmtuned-4.20150325build1/debian/changelog0000664000000000000000000000207413260672034015044 0ustar ksmtuned (4.20150325build1) bionic; urgency=high * No change rebuild to pick up -fPIE compiler default -- Balint Reczey Tue, 03 Apr 2018 12:31:24 +0000 ksmtuned (4.20150325) unstable; urgency=medium * [176bc5ab] Merge branch 'master' of github.com:bzed/debian-ksmtuned * [84945d0d] Let build-arch depend on ksmctl. Thanks to Aaron M. Ucko (Closes: #781144) -- Bernd Zeimetz Wed, 25 Mar 2015 21:22:32 +0100 ksmtuned (3.20150205) unstable; urgency=medium * Uploading to Debian (Closes: #776681) * [54df18ef] Better Section and Description. * [97dda18a] Use hardening build flags. -- Bernd Zeimetz Thu, 05 Feb 2015 00:02:47 +0100 ksmtuned (2.20150201) unstable; urgency=medium * [5b967237] Fix ksmtuned for debian * [1dfd1f80] Use architecture: any. ksmctl is not limited to KVM. -- Bernd Zeimetz Sun, 01 Feb 2015 13:12:48 +0100 ksmtuned (1.20150131) unstable; urgency=medium * Initial release. -- Bernd Zeimetz Fri, 30 Jan 2015 23:37:24 +0100 ksmtuned-4.20150325build1/debian/clean0000664000000000000000000000000712504614431014166 0ustar ksmctl ksmtuned-4.20150325build1/debian/control0000664000000000000000000000167413260672034014602 0ustar Source: ksmtuned Section: kernel Priority: optional Maintainer: Ubuntu Developers XSBC-Original-Maintainer: Bernd Zeimetz Build-Depends: debhelper (>= 9), dh-systemd Standards-Version: 3.9.6 Homepage: https://git.centos.org/summary/rpms!qemu-kvm Vcs-Browser: https://github.com/bzed/debian-ksmtuned Vcs-Git: https://github.com/bzed/debian-ksmtuned.git Package: ksmtuned Architecture: any Multi-Arch: foreign Depends: ${misc:Depends}, ${shlibs:Depends} Recommends: qemu-kvm Description: enables and tunes Kernel Samepage Merging This package ships the ksm and ksmtuned services to control Kernel Samepage Merging. KSM is a memory-saving de-duplication feature, that merges anonymous (private) pages (not pagecache ones). . While the ksm service is only able to start and stop the KSM kernel thread, ksmtuned controls and tunes KSM according to the used memory of running qemu KVM instances. ksmtuned-4.20150325build1/debian/compat0000664000000000000000000000000212504614431014362 0ustar 9 ksmtuned-4.20150325build1/debian/copyright0000664000000000000000000000127012504614431015117 0ustar Upstream sources: https://git.centos.org/summary/rpms!qemu-kvm ksmtuned: Copyright 2009 Red Hat, Inc. and/or its affiliates. Released under the GPL Author: Dan Kenigsberg ksmctl.c: Start/stop KSM, for systemd. Copyright (C) 2009, 2011 Red Hat, Inc. Written by Paolo Bonzini . Based on the original sysvinit script by Dan Kenigsberg This file is distributed under the GNU General Public License, version 2 or later. debian/*: Copyright (C) 2015 Bernd Zeimetz License: GPLv2 or later On Debian systems, the full text of the GPL license can be found in /usr/share/common-licenses/GPL. ksmtuned-4.20150325build1/ksm0000664000000000000000000000025012504614431012454 0ustar # The maximum number of unswappable kernel pages # which may be allocated by ksm (0 for unlimited) # If unset, defaults to half of total memory # KSM_MAX_KERNEL_PAGES= ksmtuned-4.20150325build1/ksm.service0000664000000000000000000000040612504614431014116 0ustar [Unit] Description=Kernel Samepage Merging ConditionPathExists=/sys/kernel/mm/ksm [Service] Type=oneshot RemainAfterExit=yes EnvironmentFile=-/etc/default/ksm ExecStart=/usr/sbin/ksmctl start ExecStop=/usr/sbin/ksmctl stop [Install] WantedBy=multi-user.target ksmtuned-4.20150325build1/ksmtuned.service0000664000000000000000000000034512504614431015160 0ustar [Unit] Description=Kernel Samepage Merging (KSM) Tuning Daemon After=ksm.service Requires=ksm.service [Service] ExecStart=/usr/sbin/ksmtuned ExecReload=/bin/kill -USR1 $MAINPID Type=forking [Install] WantedBy=multi-user.target ksmtuned-4.20150325build1/ksmtuned0000775000000000000000000000656512504614431013536 0ustar #!/bin/bash # # Copyright 2009 Red Hat, Inc. and/or its affiliates. # Released under the GPL # # Author: Dan Kenigsberg # # ksmtuned - a simple script that controls whether (and with what vigor) ksm # should search for duplicated pages. # # starts ksm when memory commited to qemu processes exceeds a threshold, and # make ksm work harder and harder untill memory load falls below that # threshold. # # send SIGUSR1 to this process right after a new qemu process is started, or # following its death, to retune ksm accordingly # # needs testing and ironing. contact danken@redhat.com if something breaks. if [ -f /etc/ksmtuned.conf ]; then . /etc/ksmtuned.conf fi debug() { if [ -n "$DEBUG" ]; then s="`/bin/date`: $*" [ -n "$LOGFILE" ] && echo "$s" >> "$LOGFILE" || echo "$s" fi } KSM_MONITOR_INTERVAL=${KSM_MONITOR_INTERVAL:-60} KSM_NPAGES_BOOST=${KSM_NPAGES_BOOST:-300} KSM_NPAGES_DECAY=${KSM_NPAGES_DECAY:--50} KSM_NPAGES_MIN=${KSM_NPAGES_MIN:-64} KSM_NPAGES_MAX=${KSM_NPAGES_MAX:-1250} # millisecond sleep between ksm scans for 16Gb server. Smaller servers sleep # more, bigger sleep less. KSM_SLEEP_MSEC=${KSM_SLEEP_MSEC:-10} KSM_THRES_COEF=${KSM_THRES_COEF:-20} KSM_THRES_CONST=${KSM_THRES_CONST:-2048} total=`awk '/^MemTotal:/ {print $2}' /proc/meminfo` debug total $total npages=0 sleep=$[KSM_SLEEP_MSEC * 16 * 1024 * 1024 / total] [ $sleep -le 10 ] && sleep=10 debug sleep $sleep thres=$[total * KSM_THRES_COEF / 100] if [ $KSM_THRES_CONST -gt $thres ]; then thres=$KSM_THRES_CONST fi debug thres $thres KSMCTL () { case x$1 in xstop) echo 0 > /sys/kernel/mm/ksm/run ;; xstart) echo $2 > /sys/kernel/mm/ksm/pages_to_scan echo $3 > /sys/kernel/mm/ksm/sleep_millisecs echo 1 > /sys/kernel/mm/ksm/run ;; esac } committed_memory () { local pidlist pidlist=$(pgrep -f -d ' ' '^qemu-system.*-enable-kvm') if [ -n "$pidlist" ]; then ps -p "$pidlist" -o rsz= fi | awk '{ sum += $1 }; END { print 0+sum }' } free_memory () { awk '/^(MemFree|Buffers|Cached):/ {free += $2}; END {print free}' \ /proc/meminfo } increase_npages() { local delta delta=${1:-0} npages=$[npages + delta] if [ $npages -lt $KSM_NPAGES_MIN ]; then npages=$KSM_NPAGES_MIN elif [ $npages -gt $KSM_NPAGES_MAX ]; then npages=$KSM_NPAGES_MAX fi echo $npages } adjust () { local free committed free=`free_memory` committed=`committed_memory` debug committed $committed free $free if [ $[committed + thres] -lt $total -a $free -gt $thres ]; then KSMCTL stop debug "$[committed + thres] < $total and free > $thres, stop ksm" return 1 fi debug "$[committed + thres] > $total, start ksm" if [ $free -lt $thres ]; then npages=`increase_npages $KSM_NPAGES_BOOST` debug "$free < $thres, boost" else npages=`increase_npages $KSM_NPAGES_DECAY` debug "$free > $thres, decay" fi KSMCTL start $npages $sleep debug "KSMCTL start $npages $sleep" return 0 } function nothing () { : } loop () { trap nothing SIGUSR1 while true do sleep $KSM_MONITOR_INTERVAL & wait $! adjust done } PIDFILE=${PIDFILE-/var/run/ksmtune.pid} if touch "$PIDFILE"; then loop & echo $! > "$PIDFILE" fi ksmtuned-4.20150325build1/ksmtuned.conf0000664000000000000000000000073612504614431014451 0ustar # Configuration file for ksmtuned. # How long ksmtuned should sleep between tuning adjustments # KSM_MONITOR_INTERVAL=60 # Millisecond sleep between ksm scans for 16Gb server. # Smaller servers sleep more, bigger sleep less. # KSM_SLEEP_MSEC=10 # KSM_NPAGES_BOOST=300 # KSM_NPAGES_DECAY=-50 # KSM_NPAGES_MIN=64 # KSM_NPAGES_MAX=1250 # KSM_THRES_COEF=20 # KSM_THRES_CONST=2048 # uncomment the following if you want ksmtuned debug info # LOGFILE=/var/log/ksmtuned # DEBUG=1 ksmtuned-4.20150325build1/ksmctl.c0000664000000000000000000000327412504614431013411 0ustar /* Start/stop KSM, for systemd. * Copyright (C) 2009, 2011 Red Hat, Inc. * Written by Paolo Bonzini . * Based on the original sysvinit script by Dan Kenigsberg * This file is distributed under the GNU General Public License, version 2 * or later. */ #include #include #include #include #include #include #define KSM_MAX_KERNEL_PAGES_FILE "/sys/kernel/mm/ksm/max_kernel_pages" #define KSM_RUN_FILE "/sys/kernel/mm/ksm/run" char *program_name; int usage(void) { fprintf(stderr, "Usage: %s {start|stop}\n", program_name); return 1; } int write_value(uint64_t value, char *filename) { FILE *fp; if (!(fp = fopen(filename, "w")) || fprintf(fp, "%llu\n", (unsigned long long) value) == EOF || fflush(fp) == EOF || fclose(fp) == EOF) return 1; return 0; } uint64_t ksm_max_kernel_pages() { char *var = getenv("KSM_MAX_KERNEL_PAGES"); char *endptr; uint64_t value; if (var && *var) { value = strtoll(var, &endptr, 0); if (value < LLONG_MAX && !*endptr) return value; } /* Unless KSM_MAX_KERNEL_PAGES is set, let KSM munch up to half of * total memory. */ return sysconf(_SC_PHYS_PAGES) / 2; } int start(void) { if (access(KSM_MAX_KERNEL_PAGES_FILE, R_OK) >= 0) write_value(ksm_max_kernel_pages(), KSM_MAX_KERNEL_PAGES_FILE); return write_value(1, KSM_RUN_FILE); } int stop(void) { return write_value(0, KSM_RUN_FILE); } int main(int argc, char **argv) { program_name = argv[0]; if (argc < 2) { return usage(); } else if (!strcmp(argv[1], "start")) { return start(); } else if (!strcmp(argv[1], "stop")) { return stop(); } else { return usage(); } } ksmtuned-4.20150325build1/README.md0000664000000000000000000000023012504614431013214 0ustar # debian-ksmtuned Debian packaging of ksmtuned. Sources taken from the RedHat/CentOS quemu-kvm packaging: https://git.centos.org/summary/rpms!qemu-kvm