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

Roland devzero at web.de
Thu Feb 29 09:46:49 CET 2024


oh, and shouldn't we also add that to total and free_memory calculation,
even chances are less that the limit is hit there ?

total=`awk '/^MemTotal:/ {print $2}' /proc/meminfo`

free_memory () {
     awk '/^(MemFree|Buffers|Cached):/ {free += $2}; END {print free}' \
                 /proc/meminfo
}

Am 25.01.24 um 11:56 schrieb Stefan Lendl:
> 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



More information about the pve-devel mailing list