Skip to content

Decrease memory footprint of JVM-based apps by setting MALLOC_ARENA_MAX #316

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

giner
Copy link
Contributor

@giner giner commented Apr 8, 2025

Set MALLOC_ARENA_MAX to 2 by default and introduce environment variable SPLICE_MALLOC_ARENA_MAX as an option to override this value. This can decrease resident memory footprint for JVM process reduce unnecessary OOM kills by the OS.

Here are the details:

  • By default on 64-bit systems the limit for number of arenas in glibc malloc is determined as 8 * num_of_cores (in our case it is the max arenas becomes 8 *16 = 128)
  • Container limits are not respected
  • Each Arena allocates one heap of 64 MiB at the time of creation
  • A new Arena is created each time when malloc is called and all existing Arenas are locked by other threads
  • JVM based software tends to create a lot of threads, at the same time it has it's own memory management so it doesn't call malloc frequently. Memory waste from a large number of arenas is quite significant on machines with many physical cores and this waste is especially noticeable in smaller apps.

@giner giner force-pushed the stas/jvm_decrease_memory_footprint_by_setting_malloc_arena_max branch from 8eb7286 to 17bfb9a Compare April 8, 2025 06:06
Set MALLOC_ARENA_MAX to 2 by default and introduce environment variable
SPLICE_MALLOC_ARENA_MAX as an option to override this value.  This can
decrease resident memory footprint for JVM process reduce unnecessary
OOM kills by the OS.

Here are the details:
- By default on 64-bit systems the limit for number of arenas in glibc
  malloc is determined as 8 * num_of_cores (in our case it is the max
  arenas becomes 8 *16 = 128)
- Container limits are not respected
- Each Arena allocates one heap of 64 MiB at the time of creation
- A new Arena is created each time when malloc is called and all
  existing Arenas are locked by other threads
- JVM based software tends to create a lot of threads, at the same time
  it has it's own memory management so it doesn't call malloc
  frequently. Memory waste from a large number of arenas is quite
  significant on machines with many physical cores and this waste is
  especially noticeable in smaller apps.

Signed-off-by: Stanislav German-Evtushenko <[email protected]>
@giner giner force-pushed the stas/jvm_decrease_memory_footprint_by_setting_malloc_arena_max branch from 17bfb9a to 78db949 Compare April 8, 2025 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant