From 89a21c6a4667f02542e7889c23fef24461cdf236 Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Tue, 21 Apr 2015 14:04:00 -0400 Subject: [PATCH] disable dynamic mmap threshold that leads to fragmentation - see M_MMAP_THRESHOLD in "man mallopt" - https://sourceware.org/bugzilla/show_bug.cgi?id=11044 - allow disabling tuning by setting JBP_NO_MALLOC_TUNING env --- .../component/base_component.rb | 6 ++++ spec/bin/release_spec.rb | 30 +++++++++++++++++++ spec/integration_helper.rb | 1 + 3 files changed, 37 insertions(+) diff --git a/lib/java_buildpack/component/base_component.rb b/lib/java_buildpack/component/base_component.rb index 8ae0963307..02b480459a 100644 --- a/lib/java_buildpack/component/base_component.rb +++ b/lib/java_buildpack/component/base_component.rb @@ -93,8 +93,14 @@ def command_environment # Resolve the environment that's passed on the command line def resolve_command_environment + return if ENV['JBP_NO_MALLOC_TUNING'] && ENV['JBP_NO_MALLOC_TUNING'] != '0' # set MALLOC_ARENA_MAX by default @default_command_environment['MALLOC_ARENA_MAX'] = 2 unless ENV.key? 'MALLOC_ARENA_MAX' + # disable dynamic mmap threshold, see M_MMAP_THRESHOLD in "man mallopt" + @default_command_environment['MALLOC_MMAP_THRESHOLD_'] = 131_072 unless ENV.key? 'MALLOC_MMAP_THRESHOLD_' + @default_command_environment['MALLOC_TRIM_THRESHOLD_'] = 131_072 unless ENV.key? 'MALLOC_TRIM_THRESHOLD_' + @default_command_environment['MALLOC_TOP_PAD_'] = 131_072 unless ENV.key? 'MALLOC_TOP_PAD_' + @default_command_environment['MALLOC_MMAP_MAX_'] = 65_536 unless ENV.key? 'MALLOC_MMAP_MAX_' end # Downloads an item with the given name and version from the given URI, then yields the resultant file to the diff --git a/spec/bin/release_spec.rb b/spec/bin/release_spec.rb index 23e9f8af91..dcfa6411cc 100644 --- a/spec/bin/release_spec.rb +++ b/spec/bin/release_spec.rb @@ -41,4 +41,34 @@ expect(YAML.load(stdout.string)['default_process_types']['web']).to match(/^MALLOC_ARENA_MAX=2 .*/) end end + + it 'allow disabling malloc tuning', + app_fixture: 'integration_valid' do + + ENV['JBP_NO_MALLOC_TUNING'] = '1' + run("bin/release #{app_dir}") do |status| + expect(status).to be_success + expect(YAML.load(stdout.string)['default_process_types']['web']).not_to match(/^MALLOC_ARENA_MAX.*/) + end + end + + it 'do malloc tuning when JBP_NO_MALLOC_TUNING=0', + app_fixture: 'integration_valid' do + + ENV['JBP_NO_MALLOC_TUNING'] = '0' + run("bin/release #{app_dir}") do |status| + expect(status).to be_success + expect(YAML.load(stdout.string)['default_process_types']['web']).to match(/^MALLOC_ARENA_MAX=2 .*/) + end + end + + it 'when env contains value, don\'t include it to the command line', + app_fixture: 'integration_valid' do + + ENV['MALLOC_ARENA_MAX'] = '4' + run("bin/release #{app_dir}") do |status| + expect(status).to be_success + expect(YAML.load(stdout.string)['default_process_types']['web']).not_to match(/^MALLOC_ARENA_MAX.*/) + end + end end diff --git a/spec/integration_helper.rb b/spec/integration_helper.rb index e768cf46b5..90e5bdf372 100644 --- a/spec/integration_helper.rb +++ b/spec/integration_helper.rb @@ -40,6 +40,7 @@ after do FileUtils.rm_rf buildpack_dir + ENV.delete('JBP_NO_MALLOC_TUNING') end def run(command)