Skip to content

Commit bfdbfb3

Browse files
committed
replace memory allocator
1 parent c891a24 commit bfdbfb3

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

build/Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ RUN ln -s /usr/share/powershell/pwsh /usr/bin/pwsh
2525

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.
28+
# Also installs libmimalloc; see Dockerfile.release for the full rationale.
2829
RUN apt-get update \
29-
&& apt-get install -y --no-install-recommends openssh-server \
30+
&& apt-get install -y --no-install-recommends openssh-server libmimalloc2.0 \
3031
&& rm -rf /var/lib/apt/lists/* \
3132
&& mkdir -p /run/sshd
3233
COPY docker/sshd_config /etc/ssh/sshd_config
@@ -46,6 +47,14 @@ ENV IMAGE_TAG=$IMAGE_TAG
4647
ENV CRAFT_VERBOSE="false"
4748
# SSH is opt-in. Set CRAFT_SSH_ENABLED=true at runtime to start sshd on port 2222.
4849
ENV CRAFT_SSH_ENABLED="false"
50+
51+
# ── Memory & runtime tuning (kept in sync with Dockerfile.release) ──
52+
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libmimalloc.so.2
53+
ENV MALLOC_ARENA_MAX=2
54+
ENV POWERSHELL_TELEMETRY_OPTOUT=1
55+
ENV POWERSHELL_UPDATECHECK=Off
56+
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
57+
4958
EXPOSE 8080 2222
5059
ENV ASPNETCORE_URLS=http://+:8080
5160

build/Dockerfile.release

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
2937
RUN 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
3341
COPY docker/sshd_config /etc/ssh/sshd_config
@@ -47,6 +55,19 @@ ENV IMAGE_TAG=$IMAGE_TAG
4755
ENV CRAFT_VERBOSE="false"
4856
# SSH is opt-in. Set CRAFT_SSH_ENABLED=true at runtime to start sshd on port 2222.
4957
ENV 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+
5071
EXPOSE 8080 2222
5172
ENV ASPNETCORE_URLS=http://+:8080
5273

0 commit comments

Comments
 (0)