Skip to content

Instantly share code, notes, and snippets.

@kaspergrubbe
Created July 26, 2022 18:47
Show Gist options
  • Save kaspergrubbe/01a3b15481527f43e4685badf558aee2 to your computer and use it in GitHub Desktop.
Save kaspergrubbe/01a3b15481527f43e4685badf558aee2 to your computer and use it in GitHub Desktop.

Revisions

  1. kaspergrubbe created this gist Jul 26, 2022.
    31 changes: 31 additions & 0 deletions jemalloc5.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # Inspiration: https://twitter.com/wgjordan/status/1440574986264006659

    jemalloc_conf = {
    # Maximum number of arenas to use for automatic multiplexing of threads and arenas.
    # The default is four times the number of CPUs, or one if there is a single CPU.
    narenas: 2,

    # Enabling jemalloc background threads generally improves the tail latency for application threads,
    # since unused memory purging is shifted to the dedicated background threads.
    # In addition, unintended purging delay caused by application inactivity is avoided with background threads.
    #
    # Suggested: background_thread:true when jemalloc managed threads can be allowed.
    background_thread: true, # default false

    # Transparent hugepage (THP) mode.
    # Settings "always", "never" and "default" are available if THP is supported by the operating system.
    # The "always" setting enables transparent hugepage for all user memory mappings with MADV_HUGEPAGE;
    # "never" ensures no transparent hugepage with MADV_NOHUGEPAGE; the default setting "default" makes no changes.
    thp: 'never',

    # Decay time determines how fast jemalloc returns unused pages back to the operating system,
    # and therefore provides a fairly straightforward trade-off between CPU and memory usage.
    # Shorter decay time purges unused pages faster to reduces memory usage
    # (usually at the cost of more CPU cycles spent on purging), and vice versa.
    #
    # Suggested: tune the values based on the desired trade-offs.
    dirty_decay_ms: 1_000, # Default 10_000
    muzzy_decay_ms: 0 # Default 10_000
    }.map {|x| x.join(':')}.join(',')

    # MALLOC_CONF="narenas:2,background_thread:true,thp:never,dirty_decay_ms:1000,muzzy_decay_ms:0"