[pve-devel] [PATCH ksm-control-daemon] ksmtuned: fix large number processing

Stefan Lendl s.lendl at proxmox.com
Thu Jan 25 11:56:59 CET 2024


awk internally uses float for every calculation, printing a large float
with awk results in 1.233e+09 format which causes the script to fail afterwards.
Instead I am printing the float without decimals.

Signed-off-by: Stefan Lendl <s.lendl at proxmox.com>
---
 debian/patches/awk-printf.diff | 16 ++++++++++++++++
 debian/patches/series          |  1 +
 2 files changed, 17 insertions(+)
 create mode 100644 debian/patches/awk-printf.diff

diff --git a/debian/patches/awk-printf.diff b/debian/patches/awk-printf.diff
new file mode 100644
index 0000000..11a957f
--- /dev/null
+++ b/debian/patches/awk-printf.diff
@@ -0,0 +1,16 @@
+--- ksm-control-scripts/ksmtuned	2024-01-25 11:33:03.485039813 +0100
++++ ksm-control-scripts.new/ksmtuned	2024-01-25 11:37:40.544751316 +0100
+@@ -72,11 +72,11 @@
+     # calculate how much memory is committed to running qemu processes
+     local progname
+     progname=${1:-kvm}
+-    ps -C "$progname" -o vsz= | awk '{ sum += $1 }; END { print sum }'
++    ps -C "$progname" -o vsz= | awk '{ sum += $1 }; END { printf ("%.0f", sum) }'
+ }
+ 
+ free_memory () {
+-    awk '/^(MemFree|Buffers|Cached):/ {free += $2}; END {print free}' \
++    awk '/^(MemFree|Buffers|Cached):/ {free += $2}; END { printf ("%.0f", free) }' \
+                 /proc/meminfo
+ }
+ 
diff --git a/debian/patches/series b/debian/patches/series
index 7aaec2c..63aba40 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@ init-script.diff
 ksmtuned.diff
 adjust-ksm-slepp.diff
 use-vsz-instead-of-rsz.diff
+awk-printf.diff
-- 
2.43.0





More information about the pve-devel mailing list