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

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


Hi Stefan,

looks good for me so far and indeed, on very large system when VMs eat
up >2TB this could hit the limit very soon.

but shouldn't we add some newline , as the original "print sum" prints one ?

root at s740:/usr/sbin# seq 1 100000 | awk '{ sum += $1 }; END { print sum }'
5.00005e+09
root at s740:/usr/sbin# seq 1 100000 | awk '{ sum += $1 }; END { printf
("%.0f", sum) }'
5000050000root at s740:/usr/sbin#

# seq 1 100000 | awk '{ sum += $1 }; END { print sum }'|xxd
00000000: 352e 3030 3030 3565 2b30 390a            5.00005e+09.

# seq 1 100000 | awk '{ sum += $1 }; END { printf ("%.0f", sum) }' |xxd
00000000: 3530 3030 3035 3030 3030                 5000050000

# seq 1 100000 | awk '{ sum += $1 }; END { printf ("%.0f\n", sum) }' |xxd
00000000: 3530 3030 3035 3030 3030 0a              5000050000.

regards
Roland



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