Skip to content

Commit e0b8570

Browse files
yxiecatiantianlv
authored andcommitted
[build] force Linux to drop cache before calling kvm (sonic-net#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 0bebd16 commit e0b8570

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
###############################################################################
@@ -114,6 +117,7 @@ SONIC_BUILD_INSTRUCTION := make \
114117
PASSWORD=$(PASSWORD) \
115118
USERNAME=$(USERNAME) \
116119
SONIC_BUILD_JOBS=$(SONIC_BUILD_JOBS) \
120+
VS_PREPARE_MEM=$(VS_PREPARE_MEM) \
117121
KERNEL_PROCURE_METHOD=$(KERNEL_PROCURE_METHOD) \
118122
HTTP_PROXY=$(http_proxy) \
119123
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 = 1000
8686
FRR_USER_GID = 1000
87+
88+
# Default VS build memory preparation
89+
DEFAULT_VS_PREPARE_MEM = yes

slave.mk

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ ifeq ($(SONIC_BUILD_JOBS),)
109109
override SONIC_BUILD_JOBS := $(SONIC_CONFIG_BUILD_JOBS)
110110
endif
111111

112+
ifeq ($(VS_PREPARE_MEM),)
113+
override VS_PREPARE_MEM := $(DEFAULT_VS_PREPARE_MEM)
114+
endif
115+
112116
ifeq ($(KERNEL_PROCURE_METHOD),)
113117
override KERNEL_PROCURE_METHOD := $(DEFAULT_KERNEL_PROCURE_METHOD)
114118
endif
@@ -155,6 +159,7 @@ $(info "SONIC_DEBUGGING_ON" : "$(SONIC_DEBUGGING_ON)")
155159
$(info "SONIC_PROFILING_ON" : "$(SONIC_PROFILING_ON)")
156160
$(info "KERNEL_PROCURE_METHOD" : "$(KERNEL_PROCURE_METHOD)")
157161
$(info "BUILD_TIMESTAMP" : "$(BUILD_TIMESTAMP)")
162+
$(info "VS_PREPARE_MEM" : "$(VS_PREPARE_MEM)")
158163
$(info )
159164

160165
###############################################################################
@@ -163,6 +168,7 @@ $(info )
163168
###############################################################################
164169

165170
export kernel_procure_method=$(KERNEL_PROCURE_METHOD)
171+
export vs_build_prepare_mem=$(VS_PREPARE_MEM)
166172

167173
###############################################################################
168174
## Local targets

0 commit comments

Comments
 (0)