Skip to content

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

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

Merged
Show file tree
Hide file tree
Changes from 2 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 != 100 ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be okay with us asserting that this is 262144.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally do not think it would be better as if the defaults change this is one more test to update and if its not 100 and the previous command did not error (which I assume would trigger a failed build) it should essentially be the same but if you feel otherwise I can certainly change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, today we want to ensure that the value is set to what we specify: 262144. It's not much overhead to have to change this if we were to make a change to the default here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k, will update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


}

# 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 ]

}