@@ -26,8 +26,16 @@ RUN ln -s /usr/share/powershell/pwsh /usr/bin/pwsh
2626# Optional SSH server for Azure App Service SCM access. Installed unconditionally
2727# but NOT started — the entrypoint launches sshd only when CRAFT_SSH_ENABLED=true.
2828# Adds ~12MB to the image. Uses Azure's standard port 2222 and root login.
29+ #
30+ # Also installs libmimalloc — a drop-in malloc replacement that returns freed
31+ # memory to the OS far more aggressively than glibc malloc. PowerShell runspaces
32+ # allocate-and-free in patterns that glibc holds onto indefinitely (per-thread
33+ # arenas + low trim threshold), causing RSS to climb well past the actual live
34+ # working set. Preloading mimalloc typically reclaims 20–40% RSS on long-lived
35+ # .NET-on-Linux hosts that spawn child processes. LD_PRELOAD propagates to
36+ # child pwsh runspaces automatically, which is exactly what we want here.
2937RUN apt-get update \
30- && apt-get install -y --no-install-recommends openssh-server \
38+ && apt-get install -y --no-install-recommends openssh-server libmimalloc2.0 \
3139 && rm -rf /var/lib/apt/lists/* \
3240 && mkdir -p /run/sshd
3341COPY docker/sshd_config /etc/ssh/sshd_config
@@ -47,6 +55,19 @@ ENV IMAGE_TAG=$IMAGE_TAG
4755ENV CRAFT_VERBOSE="false"
4856# SSH is opt-in. Set CRAFT_SSH_ENABLED=true at runtime to start sshd on port 2222.
4957ENV CRAFT_SSH_ENABLED="false"
58+
59+ # ── Memory & runtime tuning ──
60+ # mimalloc preload — see install step above for rationale.
61+ ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libmimalloc.so.2
62+ # Cap glibc per-thread arenas. Even with mimalloc preloaded, anything that
63+ # bypasses LD_PRELOAD (vDSO, some syscalls, statically-linked helpers) still
64+ # uses glibc; capping arenas to 2 prevents fragmentation when that happens.
65+ ENV MALLOC_ARENA_MAX=2
66+ # Suppress PowerShell + .NET CLI background work in every runspace.
67+ ENV POWERSHELL_TELEMETRY_OPTOUT=1
68+ ENV POWERSHELL_UPDATECHECK=Off
69+ ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
70+
5071EXPOSE 8080 2222
5172ENV ASPNETCORE_URLS=http://+:8080
5273
0 commit comments