Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not run sysctl for vm.max_map_count when its already set #31285

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distribution/packages/src/deb/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ case "$1" in
ulimit -l $MAX_LOCKED_MEMORY
fi

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

Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/rpm/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ start() {
if [ -n "$MAX_LOCKED_MEMORY" ]; then
ulimit -l $MAX_LOCKED_MEMORY
fi
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
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
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
fi

Expand Down
28 changes: 28 additions & 0 deletions qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,31 @@ setup() {
assert_file_exist /var/log/elasticsearch/gc.log.0.current
stop_elasticsearch_service
}

# Ensures that if $MAX_MAP_COUNT is less than the set value on the OS
# it will be updated
@test "[INIT.D] sysctl is run when the value set is too small" {
# intentionally a ridiculously low number
sysctl -q -w vm.max_map_count=100
start_elasticsearch_service
max_map_count=$(sysctl -n vm.max_map_count)
stop_elasticsearch_service

[ $max_map_count = 262144 ]

}

# Ensures that if $MAX_MAP_COUNT is greater than the set vaule on the OS
# we do not attempt to update it this should cover equality as well as I think
# we can trust that equality operators work as intended.
@test "[INIT.D] sysctl is not run when it already has a larger or equal value set" {
# intentionally set to the default +1
sysctl -q -w vm.max_map_count=262145
start_elasticsearch_service
max_map_count=$(sysctl -n vm.max_map_count)
stop_elasticsearch_service

# default value +1
[ $max_map_count = 262145 ]

}