From c1a37d9577042baaa6f4bffe011a58450821127a Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 28 Nov 2021 21:47:04 -0600 Subject: [PATCH] docker: set MALLOC_ARENA_MAX=2. Setting MALLOC_ARENA_MAX=2 is claimed to reduce memory bloat caused by fragmentation. Jemalloc 3.x is also claimed to reduce memory bloat, but modern distros only ship Jemalloc 5.x, and supposedly only 3.x works. https://devcenter.heroku.com/articles/tuning-glibc-memory-behavior https://bugs.ruby-lang.org/issues/14718 https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html --- config/docker/Dockerfile.danbooru | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/docker/Dockerfile.danbooru b/config/docker/Dockerfile.danbooru index 4e5eb13b9..e65e0e8ea 100644 --- a/config/docker/Dockerfile.danbooru +++ b/config/docker/Dockerfile.danbooru @@ -3,6 +3,10 @@ FROM ubuntu:21.04 AS base WORKDIR /danbooru ENV PATH="/root/.asdf/bin:/root/.asdf/shims:$PATH:/usr/lib/postgresql/14/bin" +# Reduces memory usage at the cost of higher thread contention. +# https://bugs.ruby-lang.org/issues/14718 +ENV MALLOC_ARENA_MAX=2 + COPY config/docker/build-base-image.sh . RUN \