[kvm] improve the handling of compact_memory during kvm image build (#9184)

Build failed on a Ubuntu 20.04 system with kvm kernel, which does not have the /proc/sys/vm/compact_memory 
Should check if compact_memory is writeable before doing it.

Signed-off-by: Chris Ward <tjcw@uk.ibm.com>
This commit is contained in:
Chris Ward 2021-11-10 16:31:03 +00:00 committed by GitHub
parent 475bfc9625
commit f8688bef8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,7 +59,11 @@ free -m
if [[ "$vs_build_prepare_mem" == "yes" ]]; then
# Force o.s. to drop cache and compact memory so that KVM can get 2G memory
bash -c 'echo 1 > /proc/sys/vm/drop_caches'
bash -c 'echo 1 > /proc/sys/vm/compact_memory'
# Not all kernels support compact_memory
if [[ -w '/proc/sys/vm/compact_memory' ]]
then
bash -c 'echo 1 > /proc/sys/vm/compact_memory'
fi
free -m
fi