From cfd8864f9a578fd5a316bda0d07c4d74c78e07b6 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Wed, 24 Aug 2022 11:01:23 -0700 Subject: [PATCH] init: Change extra_free_kbytes.sh to add margin relative to the default watermark level extra_free_kbytes.sh accepts a parameter representing the number of KB to add to low and high watermarks. It adds this margin to the current watermark levels, however this is not how /proc/sys/vm/extra_free_kbytes knob that it replaces used to work. The old knob would add the margin relative to the original and not the current level of the watermarks. Change extra_free_kbytes.sh to add the specified margin to the original watermark levels to act as correct replacement of the old knob. Bug: 242837506 Fixes: 642048d96994 ("init: Add extra_free_kbytes.sh script to adjust watermark_scale_factor") Test: repeatedly run 'setprop sys.sysctl.extra_free_kbytes 30375' Signed-off-by: Suren Baghdasaryan Change-Id: I8af603ba00bd4fb8182b80b3c0969fa96cdd7311 --- init/extra_free_kbytes.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/init/extra_free_kbytes.sh b/init/extra_free_kbytes.sh index aeaa91258..a0141be10 100755 --- a/init/extra_free_kbytes.sh +++ b/init/extra_free_kbytes.sh @@ -77,7 +77,19 @@ then exit fi -watermark_scale=`cat /proc/sys/vm/watermark_scale_factor` +# record the original watermark_scale_factor value +watermark_scale=$(getprop "ro.kernel.watermark_scale_factor") +if [ -z "$watermark_scale" ] +then + watermark_scale=$(cat /proc/sys/vm/watermark_scale_factor) + setprop "ro.kernel.watermark_scale_factor" "$watermark_scale" + # On older distributions with no policies configured setprop may fail. + # If that happens, use the kernel default of 10. + if [ -z $(getprop "ro.kernel.watermark_scale_factor") ] + then + watermark_scale=10 + fi +fi # convert extra_free_kbytes to pages page_size=$(getconf PAGESIZE)