Skip to content

Commit 6f94914

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 c12f3c7 commit 6f94914

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

distribution/packages/src/deb/init.d/elasticsearch

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ case "$1" in
122122
ulimit -l $MAX_LOCKED_MEMORY
123123
fi
124124

125-
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
125+
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
126126
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
127127
fi
128128

distribution/packages/src/rpm/init.d/elasticsearch

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ start() {
9090
if [ -n "$MAX_LOCKED_MEMORY" ]; then
9191
ulimit -l $MAX_LOCKED_MEMORY
9292
fi
93-
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
93+
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
9494
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
9595
fi
9696

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

+28
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,31 @@ setup() {
163163
assert_file_exist /var/log/elasticsearch/gc.log.0.current
164164
stop_elasticsearch_service
165165
}
166+
167+
# Ensures that if $MAX_MAP_COUNT is less than the set value on the OS
168+
# it will be updated
169+
@test "[INIT.D] sysctl is run when the value set is too small" {
170+
# intentionally a ridiculously low number
171+
sysctl -q -w vm.max_map_count=100
172+
start_elasticsearch_service
173+
max_map_count=$(sysctl -n vm.max_map_count)
174+
stop_elasticsearch_service
175+
176+
[ $max_map_count = 262144 ]
177+
178+
}
179+
180+
# Ensures that if $MAX_MAP_COUNT is greater than the set vaule on the OS
181+
# we do not attempt to update it this should cover equality as well as I think
182+
# we can trust that equality operators work as intended.
183+
@test "[INIT.D] sysctl is not run when it already has a larger or equal value set" {
184+
# intentionally set to the default +1
185+
sysctl -q -w vm.max_map_count=262145
186+
start_elasticsearch_service
187+
max_map_count=$(sysctl -n vm.max_map_count)
188+
stop_elasticsearch_service
189+
190+
# default value +1
191+
[ $max_map_count = 262145 ]
192+
193+
}

0 commit comments

Comments
 (0)