Skip to content

Commit be382e9

Browse files
majormosesjasontedor
authored andcommitted
Do not set vm.max_map_count when unnecessary (#31285)
This commit modifies the Sys V init startup scripts to only modify vm.max_map_count if needed. In this case, needed means that the current value is less than our default value of 262144 maps.
1 parent 807545a commit be382e9

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

distribution/deb/src/main/packaging/init.d/elasticsearch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ case "$1" in
147147
ulimit -l $MAX_LOCKED_MEMORY
148148
fi
149149

150-
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
150+
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count -a "$MAX_MAP_COUNT" -ge $(cat /proc/sys/vm/max_map_count) ]; then
151151
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
152152
fi
153153

distribution/rpm/src/main/packaging/init.d/elasticsearch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ start() {
114114
if [ -n "$MAX_LOCKED_MEMORY" ]; then
115115
ulimit -l $MAX_LOCKED_MEMORY
116116
fi
117-
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
117+
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count -a "$MAX_MAP_COUNT" -ge $(cat /proc/sys/vm/max_map_count) ]; then
118118
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
119119
fi
120120

qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,32 @@ setup() {
182182

183183
service elasticsearch stop
184184
}
185+
186+
# Ensures that if $MAX_MAP_COUNT is less than the set value on the OS
187+
# it will be updated
188+
@test "[INIT.D] sysctl is run when the value set is too small" {
189+
# intentionally a ridiculously low number
190+
sysctl -q -w vm.max_map_count=100
191+
start_elasticsearch_service
192+
max_map_count=$(sysctl -n vm.max_map_count)
193+
stop_elasticsearch_service
194+
195+
[ $max_map_count = 262144 ]
196+
197+
}
198+
199+
# Ensures that if $MAX_MAP_COUNT is greater than the set vaule on the OS
200+
# we do not attempt to update it this should cover equality as well as I think
201+
# we can trust that equality operators work as intended.
202+
@test "[INIT.D] sysctl is not run when it already has a larger or equal value set" {
203+
# intentionally set to the default +1
204+
sysctl -q -w vm.max_map_count=262145
205+
start_elasticsearch_service
206+
max_map_count=$(sysctl -n vm.max_map_count)
207+
stop_elasticsearch_service
208+
209+
# default value +1
210+
[ $max_map_count = 262145 ]
211+
212+
}
213+

0 commit comments

Comments
 (0)