Skip to content

Commit

Permalink
disable dynamic mmap threshold that leads to fragmentation
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
lhotari committed Apr 21, 2015
1 parent 5a93ffd commit 89a21c6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/java_buildpack/component/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/bin/release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

after do
FileUtils.rm_rf buildpack_dir
ENV.delete('JBP_NO_MALLOC_TUNING')
end

def run(command)
Expand Down

0 comments on commit 89a21c6

Please sign in to comment.