Lowering peak memory with one glibc setting on Graviton2
Applies to: the Eugo image, November 2026.
This page is for people running the Eugo image on AWS Lambda or AWS Fargate on Graviton2 whose program runs out of memory, or pays for more memory than its CPU time needs.
What the image sets
Section titled “What the image sets”The image sets GLIBC_TUNABLES=glibc.malloc.hugetlb=0 as an image environment variable, so every process inherits
it: malloc does not ask the kernel for 2 MiB huge pages.
On large machines the image's start-up script turns huge pages back on, once, when the container starts. It switches
the variable to glibc.malloc.hugetlb=1 (and sets THP_MEM_ALLOC_ENABLE=1, PyTorch's switch for huge pages) only
when all of these hold: the container's memory limit and the machine's memory are both 16 GiB or more, the kernel's
transparent huge pages are enabled with a defrag setting of defer or never, and the kernel's huge page is 2 MiB.
Lambda functions (10 GiB at most) never qualify.
The script leaves the variable alone if you set GLIBC_TUNABLES to a value of your own, or if you set
EUGO_AUTO_HUGEPAGES=0. Any value other than 1 also switches the script off. Setting exactly the image's value,
glibc.malloc.hugetlb=0, counts as the image's, so use EUGO_AUTO_HUGEPAGES=0 to keep it.
The opt-in
Section titled “The opt-in”GLIBC_TUNABLES=glibc.malloc.hugetlb=0:glibc.malloc.arena_max=2arena_max=2 caps the number of heaps (arenas) that malloc keeps at two, instead of glibc's default of up to eight
per CPU core: less memory held, more waiting on shared locks. On Graviton2, in our tests, it roughly halved peak
memory for many threads allocating small blocks, and it made programs that allocate blocks of about 0.3–2.6 MiB
slower and larger. On newer Graviton processors that case took up to about 30% more time, with no memory growth. It
is a trade, so it is not on by default.
Our tests ran a synthetic Python workload on stock Fedora (glibc 2.43), not in the Eugo image, with huge pages left
on (glibc.malloc.hugetlb=1); whether the results carry over to the image's hugetlb=0 was not measured.
Keep glibc.malloc.hugetlb=0 in any value you set.
Setting it
Section titled “Setting it”- AWS Lambda: add
GLIBC_TUNABLESto the function's environment variables. - AWS Fargate: add it to the container's
environmentin the task definition:{"name": "GLIBC_TUNABLES", "value": "glibc.malloc.hugetlb=0:glibc.malloc.arena_max=2"}. - On the Eugo platform: contact Eugo support.
Checking it
Section titled “Checking it”import os; print(os.environ.get("GLIBC_TUNABLES"))glibc reads the variable only when a program starts, so %env in a running notebook does not change the running
kernel.
When not to use it
Section titled “When not to use it”- Your program is limited by time, not memory: no case got faster with it in our tests.
- Your program mostly allocates blocks of about 0.3–2.6 MiB: that case got slower and larger.
Measure your own program
Section titled “Measure your own program”Measure your own program before and after: its peak memory (on Lambda, Max Memory Used in each invocation's
REPORT log line) and its run time, over several runs each way. For comparing two sets of runs fairly, see
pairbench's method.
© 2026 Eugo Inc. · Third-party licenses · LinkedIn (opens in new tab) · YouTube (opens in new tab) · GitHub (opens in new tab)

