From 23947535496b21add04d0bca94425a055bdbd0db Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Mon, 1 Apr 2019 22:47:23 +0000 Subject: [PATCH] [build] force Linux to drop cache before calling kvm (#2717) * [vm build] force Linux to drop cache before calling kvm KVM need to allocate 2G memory for this build. The system memory might be occupied by cache at the moment and doesn't have 2G chunk to give out. Forcing Kernel to drop cache to boost the chance of getting 2G memory. Signed-off-by: Ying Xie * [make] add option to enable/disable VS build memory preparation Signed-off-by: Ying Xie --- Makefile.work | 4 ++++ build_kvm_image.sh | 11 ++++++++++- rules/config | 3 +++ slave.mk | 6 ++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Makefile.work b/Makefile.work index 6c4828134a8a..eb71a774cab2 100644 --- a/Makefile.work +++ b/Makefile.work @@ -27,6 +27,9 @@ # * make NOSTRETCH=1 KEEP_SLAVE_ON=yes # * SOURCE_FOLDER: host path to be mount as /var/$(USER)/src, only effective when KEEP_SLAVE_ON=yes # * SONIC_BUILD_JOBS: Specifying number of concurrent build job(s) to run +# * VS_PREPARE_MEM: Prepare memory in VS build (drop cache and compact). +# * Default: yes +# * Values: yes, no # * KERNEL_PROCURE_METHOD: Specifying method of obtaining kernel Debian package: download or build # ############################################################################### @@ -114,6 +117,7 @@ SONIC_BUILD_INSTRUCTION := make \ PASSWORD=$(PASSWORD) \ USERNAME=$(USERNAME) \ SONIC_BUILD_JOBS=$(SONIC_BUILD_JOBS) \ + VS_PREPARE_MEM=$(VS_PREPARE_MEM) \ KERNEL_PROCURE_METHOD=$(KERNEL_PROCURE_METHOD) \ HTTP_PROXY=$(http_proxy) \ HTTPS_PROXY=$(https_proxy) \ diff --git a/build_kvm_image.sh b/build_kvm_image.sh index b08db96f573c..bc0f54e12d5c 100755 --- a/build_kvm_image.sh +++ b/build_kvm_image.sh @@ -1,4 +1,4 @@ -#!/bin/sh -ex +#!/bin/bash -ex # Copyright (C) 2014 Curt Brune # @@ -47,6 +47,15 @@ prepare_installer_disk() create_disk prepare_installer_disk +echo "Prepare memory for KVM build: $vs_build_prepare_mem" +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 + sudo bash -c 'echo 1 > /proc/sys/vm/drop_caches' + sudo bash -c 'echo 1 > /proc/sys/vm/compact_memory' + free -m +fi + /usr/bin/kvm -m $MEM \ -name "onie" \ -boot "order=cd,once=d" -cdrom "$ONIE_RECOVERY_ISO" \ diff --git a/rules/config b/rules/config index 86139c71540f..674280a3ca2c 100644 --- a/rules/config +++ b/rules/config @@ -84,3 +84,6 @@ DEFAULT_KERNEL_PROCURE_METHOD = build # group during installation. FRR_USER_UID = 1000 FRR_USER_GID = 1000 + +# Default VS build memory preparation +DEFAULT_VS_PREPARE_MEM = yes diff --git a/slave.mk b/slave.mk index 93811b43371c..b4b7f8de1f92 100644 --- a/slave.mk +++ b/slave.mk @@ -109,6 +109,10 @@ ifeq ($(SONIC_BUILD_JOBS),) override SONIC_BUILD_JOBS := $(SONIC_CONFIG_BUILD_JOBS) endif +ifeq ($(VS_PREPARE_MEM),) +override VS_PREPARE_MEM := $(DEFAULT_VS_PREPARE_MEM) +endif + ifeq ($(KERNEL_PROCURE_METHOD),) override KERNEL_PROCURE_METHOD := $(DEFAULT_KERNEL_PROCURE_METHOD) endif @@ -155,6 +159,7 @@ $(info "SONIC_DEBUGGING_ON" : "$(SONIC_DEBUGGING_ON)") $(info "SONIC_PROFILING_ON" : "$(SONIC_PROFILING_ON)") $(info "KERNEL_PROCURE_METHOD" : "$(KERNEL_PROCURE_METHOD)") $(info "BUILD_TIMESTAMP" : "$(BUILD_TIMESTAMP)") +$(info "VS_PREPARE_MEM" : "$(VS_PREPARE_MEM)") $(info ) ############################################################################### @@ -163,6 +168,7 @@ $(info ) ############################################################################### export kernel_procure_method=$(KERNEL_PROCURE_METHOD) +export vs_build_prepare_mem=$(VS_PREPARE_MEM) ############################################################################### ## Local targets