Skip to content

Commit 9d6bac5

Browse files
yxiecalguohan
authored andcommitted
[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 <[email protected]> * [make] add option to enable/disable VS build memory preparation Signed-off-by: Ying Xie <[email protected]>
1 parent 6a9491b commit 9d6bac5

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

Makefile.work

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
# * make NOSTRETCH=1 KEEP_SLAVE_ON=yes <any jessie target>
2828
# * SOURCE_FOLDER: host path to be mount as /var/$(USER)/src, only effective when KEEP_SLAVE_ON=yes
2929
# * SONIC_BUILD_JOBS: Specifying number of concurrent build job(s) to run
30+
# * VS_PREPARE_MEM: Prepare memory in VS build (drop cache and compact).
31+
# * Default: yes
32+
# * Values: yes, no
3033
# * KERNEL_PROCURE_METHOD: Specifying method of obtaining kernel Debian package: download or build
3134
#
3235
###############################################################################
@@ -115,6 +118,7 @@ SONIC_BUILD_INSTRUCTION := make \
115118
PASSWORD=$(PASSWORD) \
116119
USERNAME=$(USERNAME) \
117120
SONIC_BUILD_JOBS=$(SONIC_BUILD_JOBS) \
121+
VS_PREPARE_MEM=$(VS_PREPARE_MEM) \
118122
KERNEL_PROCURE_METHOD=$(KERNEL_PROCURE_METHOD) \
119123
HTTP_PROXY=$(http_proxy) \
120124
HTTPS_PROXY=$(https_proxy) \

build_kvm_image.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -ex
1+
#!/bin/bash -ex
22

33
# Copyright (C) 2014 Curt Brune <[email protected]>
44
#
@@ -47,6 +47,15 @@ prepare_installer_disk()
4747
create_disk
4848
prepare_installer_disk
4949

50+
echo "Prepare memory for KVM build: $vs_build_prepare_mem"
51+
free -m
52+
if [[ "$vs_build_prepare_mem" == "yes" ]]; then
53+
# Force o.s. to drop cache and compact memory so that KVM can get 2G memory
54+
sudo bash -c 'echo 1 > /proc/sys/vm/drop_caches'
55+
sudo bash -c 'echo 1 > /proc/sys/vm/compact_memory'
56+
free -m
57+
fi
58+
5059
/usr/bin/kvm -m $MEM \
5160
-name "onie" \
5261
-boot "order=cd,once=d" -cdrom "$ONIE_RECOVERY_ISO" \

rules/config

+3
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ DEFAULT_KERNEL_PROCURE_METHOD = build
8484
# group during installation.
8585
FRR_USER_UID = 300
8686
FRR_USER_GID = 300
87+
88+
# Default VS build memory preparation
89+
DEFAULT_VS_PREPARE_MEM = yes

slave.mk

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ ifeq ($(SONIC_BUILD_JOBS),)
120120
override SONIC_BUILD_JOBS := $(SONIC_CONFIG_BUILD_JOBS)
121121
endif
122122

123+
ifeq ($(VS_PREPARE_MEM),)
124+
override VS_PREPARE_MEM := $(DEFAULT_VS_PREPARE_MEM)
125+
endif
126+
123127
ifeq ($(KERNEL_PROCURE_METHOD),)
124128
override KERNEL_PROCURE_METHOD := $(DEFAULT_KERNEL_PROCURE_METHOD)
125129
endif
@@ -167,6 +171,7 @@ $(info "SONIC_PROFILING_ON" : "$(SONIC_PROFILING_ON)")
167171
$(info "KERNEL_PROCURE_METHOD" : "$(KERNEL_PROCURE_METHOD)")
168172
$(info "BUILD_TIMESTAMP" : "$(BUILD_TIMESTAMP)")
169173
$(info "BLDENV" : "$(BLDENV)")
174+
$(info "VS_PREPARE_MEM" : "$(VS_PREPARE_MEM)")
170175
$(info )
171176

172177
###############################################################################
@@ -175,6 +180,7 @@ $(info )
175180
###############################################################################
176181

177182
export kernel_procure_method=$(KERNEL_PROCURE_METHOD)
183+
export vs_build_prepare_mem=$(VS_PREPARE_MEM)
178184

179185
###############################################################################
180186
## Local targets

0 commit comments

Comments
 (0)