RuntimePart 2
A 2 GiB Container Gives the GC 1.5 GiB, and a 24 MiB One Gives 20
The GC's default hard limit was the larger of 20 MiB and 75% of the cgroup limit across six memory levels, and TotalAvailableMemoryBytes reports it.

In short
- On .NET 10.0.12 in a Linux arm64 container, TotalAvailableMemoryBytes was 1610612736 at --memory 2g, which is 75% of the cgroup limit, and the same 75% held at 1g, 512m, 256m and 128m.
- At --memory 24m the reported limit was 20971520 bytes, a 20 MiB floor above the 18874368 bytes that 75% would give, and the collection counters in the test workload rose from 45/4/2 to 54/35/17.
- An explicit GCHeapHardLimitPercent of 50 replaced the default at every level, including 24m, where it gave 12582912 bytes and no floor; the value 50 written without a prefix was read as hexadecimal and gave 80%.
- The number to plan against is the one the runtime reports, read from GC.GetGCMemoryInfo().TotalAvailableMemoryBytes, not a figure computed from the manifest.
In a container started with --memory 2g, the GC reported a hard limit of 1610612736 bytes, 1.5 GiB. In one started with --memory 24m it reported 20971520 bytes, 20 MiB, which is more than three quarters of 24 MiB.
Measured on .NET 10.0.12, the default limit was the larger of 20 MiB and 75% of memory.max, at all six memory levels tested. That figure, not the number given to --memory, is what GC.GetGCMemoryInfo().TotalAvailableMemoryBytes returns and what the heap is planned around. It is the memory counterpart of what How Many CPUs a Container Tells the Runtime It Has found for processors: the runtime derives a figure from the cgroup instead of passing the cgroup value through.
The default is three quarters of the limit
One container was started per cell, each running a small console program that read TotalAvailableMemoryBytes at startup, before any load. The memory.max column is the cgroup limit Docker set, and the last column is the number of gen0, gen1 and gen2 collections in a fixed allocation workload on workstation GC:
--memory memory.max TotalAvailableMemoryBytes gen0/1/2
2g 2147483648 1610612736 45/4/2
1g 1073741824 805306368 45/4/2
512m 536870912 402653184 45/4/2
256m 268435456 201326592 45/4/2
128m 134217728 100663296 45/4/2
24m 25165824 20971520 54/35/17Five of the six rows are exactly 75% of memory.max. Server GC reported the same values at every level. A related threshold hung off the cgroup limit and not off the hard limit: HighMemoryLoadThresholdBytes was 1932735283 at 2g, which is 90% of 2147483648.
At 24 MiB the floor took over
A 20 MiB floor can only show where 75% of the limit falls below 20 MiB, and 20 MiB divided by 0.75 is about 26.7 MiB. The 24m level was the only one tested below that line. Three quarters of 25165824 is 18874368; the reported figure was 20971520, exactly 2 MiB higher, and the runtime started and finished normally.
The counters changed with it. From 2g to 128m the workload, a 4 MiB live set in 8 KiB arrays followed by 256 MiB of 8 KiB allocations, produced 45 gen0, 4 gen1 and 2 gen2 collections every time. At 24m the same program produced 54, 35 and 17. Giving the 24m container DOTNET_GCHeapHardLimit of 64 MiB, which is larger than the cgroup itself, brought the counts back to 43/3/3 and the process still exited 0, so the jump followed the limit the GC was handed, not the cgroup ceiling.
An explicit percentage replaced the default
DOTNET_GCHeapHardLimitPercent is the setting that changes the fraction. Set to 0x32, which is 50 written in hexadecimal, it gave 1073741824 bytes at 2g and 12582912 bytes at 24m, in both cases exactly half of memory.max. At 24m that is 8 MiB under the figure the default produced, and no 20 MiB floor appeared. The runtime reads this variable as hexadecimal, so the value 50 without a prefix meant 0x50, which is 80%: it gave 20132659 bytes at 24m and 1717986918 at 2g.
The page for the setting, last updated on 9 February 2026 and read on 1 October 2026, says this about the default (GC configuration settings):
If running in a memory-constrained environment (e.g., a container) and this value is unset, the default value is either 20 MB or the heap hard limit percent of the container limit, whichever is larger.
The measurement is what 10.0.12 reported on this platform. The floor was seen only in runs where no limit setting was given, and the runs above do not extend further than that.
What this changes
- Read the limit instead of computing it.
TotalAvailableMemoryByteswas the figure the runtime itself held, and the arithmetic from the manifest would have been 2 MiB wrong at 24m. - Treat any explicit limit setting as a replacement for the default and not as a tweak to it. Every variable tried took over at every level.
- Check the value after setting it. A hexadecimal reading turned a requested 50% into 80% with no error.
GC.GetConfigurationVariables()listedGCHeapHardLimitPercentas 80 and the reported limit showed the same 80%.
To confirm a given container, print TotalAvailableMemoryBytes at startup and divide it by the contents of memory.max.
Measured on .NET SDK 10.0.401 / runtime 10.0.12, Linux (Ubuntu 24.04) arm64, in the project’s Docker sandbox: Docker Desktop 29.8.1 on an Apple M4 Pro, a VM with 12 CPUs and 8319238144 bytes of memory, kernel 7.0.14-linuxkit, cgroup v2. The levels were --memory 2g, 1g, 512m, 256m, 128m and 24m, one container per run and one run per cell, with --network none --cap-drop ALL --security-opt no-new-privileges --user 501:20 --pids-limit 512; build and restore ran in a separate container with no limit, so only the measured process lived inside the limited cgroup. All 30 runs of the official sweep, six levels by five configurations, exited 0. The program is a configuration probe: it reads TotalAvailableMemoryBytes at startup and then runs the fixed allocation workload described above, so BenchmarkDotNet was not used and no timing or pause-time claim is made. Server GC collection counts are not cited. What the harness cannot see: Kubernetes limits, cgroup v1, x64, Windows containers, swap settings other than Docker’s default, what the kernel does when a process nears memory.max, and any runtime other than 10.0.12.
Frequently asked
Questions this raises
What hard heap limit does the .NET GC derive from a container memory limit?
On .NET 10.0.12 with no limit setting given, TotalAvailableMemoryBytes equalled the larger of 20 MiB and 75% of memory.max at all six levels tested, from 2g down to 24m, for workstation and Server GC alike.
Does the 20 MiB floor apply when GCHeapHardLimitPercent is set?
Not in the measurement, which was .NET 10.0.12 in a Linux arm64 container. With DOTNET_GCHeapHardLimitPercent set to 50 in a 24 MiB container the reported limit was 12582912 bytes, exactly 50% of memory.max, and no floor was visible. The floor appeared only when no limit setting was given.
How is the GC hard limit read from inside a running process?
GC.GetGCMemoryInfo().TotalAvailableMemoryBytes returns it. In the sweep it was read once at startup, before any allocation load, and it matched the expected value at every memory level where no limit setting was given.


