Commit 626ad32
authored
Add GC heap hard limit for 32 bit (#101024)
This change enables heap hard limit on 32 bit.
Approach is similar to `DOTNET_GCSegmentSize`
(`GCConfig::GetSegmentSize`), which allows to set size of segment for
SOH/LOH/POH, and guarantees that there's no oveflow during computations
(for example, during `size_t initial_heap_size = soh_segment_size +
loh_segment_size + poh_segment_size;`). When `DOTNET_GCSegmentSize` is
set on 32bit, it's rounded down to power of 2, so largest possible value
of provided segment (SOH) is 2 Gb (`4Mb<=soh_segment_size<=2Gb`). For
LOH/POH same value is divided by 2 and then also rounded down to power
of 2, so largest possible value of LOH/POH segment is 1 Gb
(`4Mb<=loh_segment_size<=1Gb, 0<=poh_segment_size<=1Gb`). So, segment
size for SOH/LOH/POH never overflows, as well as `initial_heap_size`
(except for oveflow of `initial_heap_size` to 0, which will lead to
failed allocation later anyway).
Similar thing happens when `DOTNET_GCHeapHardLimit` or
`DOTNET_GCHeapHardLimitSOH`/`DOTNET_GCHeapHardLimitLOH`/`DOTNET_GCHeapHardLimitPOH`
are set on 32bit. There're limits on these values:
1) for heap-specific limits:
`0 <= (heap_hard_limit = heap_hard_limit_oh[soh] +
heap_hard_limit_oh[loh] + heap_hard_limit_oh[poh]) < 4Gb`
`a) 0 <= heap_hard_limit_oh[soh] < 2Gb, 0 <= heap_hard_limit_oh[loh] <=
1Gb, 0 <= heap_hard_limit_oh[poh] <= 1Gb`
`b) 0 <= heap_hard_limit_oh[soh] <= 1Gb, 0 <= heap_hard_limit_oh[loh] <
2Gb, 0 <= heap_hard_limit_oh[poh] <= 1Gb`
`c) 0 <= heap_hard_limit_oh[soh] <= 1Gb, 0 <= heap_hard_limit_oh[loh] <=
1Gb, 0 <= heap_hard_limit_oh[poh] < 2Gb`
2) for same limit for all heaps:
`0 <= heap_hard_limit <= 1Gb`
These ranges guarantee that calculation of soh_segment_size,
loh_segment_size and poh_segment_size with alignment and round up won't
overflow, as well as calculation of sum of them for allocation (overflow
to 0 is allowed, same as for `DOTNET_GCSegmentSize`). When values
specified by user with env variables don't meet the requirements above,
runtime exits with `CLR_E_GC_BAD_HARD_LIMIT`. When allocation (with
`mmap` on Linux) fails, runtime exits with same error as for large
segment size specified with `DOTNET_GCSegmentSize`.
This patch doesn't enable heap hard limit on 32bit in containers
(`is_restricted_physical_mem`), because current heap hard limit approach
is to reserve one large GC heap segment with size equal to specified
heap hard limit, and no new segments are reserved in future. On 64 bit
in containers by default heap hard limit is set to 75% of total physical
memory available, and this is fine, because virtual address space on 64
bit is much larger than actual physical size on devices. In contrast, on
32 bit virtual address space size might be the same as available
physical size on device (e.g. 4 Gb for both). This means that reserving
75% of total physical mem will reserve 75% of whole virtual address
space, which might be both undesirable (e.g. process later expects more
available memory) and `mmap` on Linux will probably fail anyway.
I've ran release CLR tests on armel Linux with this patch on top of
f84d33 with different limits, there seems to be no issues with
4Mb/8Mb/16Mb and 512Mb heap hard limits (some tests fail with "Out of
memory"/"OOM" and "System.OutOfMemoryException", as expected, or
"System.InvalidOperationException: NoGCRegion mode must be set" when
NoGC region is larger than limit). Same for GCStresss 0xc and 0x3 with 4
Mb heap hard limit, and same for debug CLR tests on armel Linux with 4Mb
heap hard limit.
@Maoni0 @cshung please share what you think. Thank you.1 parent 7ff1082 commit 626ad32
2 files changed
+128
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1989 | 1989 | | |
1990 | 1990 | | |
1991 | 1991 | | |
| 1992 | + | |
1992 | 1993 | | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
1993 | 2002 | | |
1994 | 2003 | | |
1995 | 2004 | | |
| |||
7442 | 7451 | | |
7443 | 7452 | | |
7444 | 7453 | | |
7445 | | - | |
7446 | | - | |
7447 | | - | |
7448 | 7454 | | |
7449 | 7455 | | |
7450 | 7456 | | |
| |||
7587 | 7593 | | |
7588 | 7594 | | |
7589 | 7595 | | |
7590 | | - | |
7591 | | - | |
7592 | | - | |
7593 | 7596 | | |
7594 | 7597 | | |
7595 | 7598 | | |
| |||
14488 | 14491 | | |
14489 | 14492 | | |
14490 | 14493 | | |
| 14494 | + | |
| 14495 | + | |
| 14496 | + | |
| 14497 | + | |
| 14498 | + | |
14491 | 14499 | | |
14492 | 14500 | | |
14493 | 14501 | | |
| |||
21128 | 21136 | | |
21129 | 21137 | | |
21130 | 21138 | | |
21131 | | - | |
| 21139 | + | |
21132 | 21140 | | |
21133 | 21141 | | |
21134 | 21142 | | |
21135 | 21143 | | |
21136 | | - | |
| 21144 | + | |
21137 | 21145 | | |
21138 | 21146 | | |
21139 | 21147 | | |
| |||
21144 | 21152 | | |
21145 | 21153 | | |
21146 | 21154 | | |
21147 | | - | |
| 21155 | + | |
21148 | 21156 | | |
21149 | 21157 | | |
21150 | 21158 | | |
| |||
44159 | 44167 | | |
44160 | 44168 | | |
44161 | 44169 | | |
| 44170 | + | |
| 44171 | + | |
| 44172 | + | |
| 44173 | + | |
| 44174 | + | |
| 44175 | + | |
| 44176 | + | |
| 44177 | + | |
| 44178 | + | |
44162 | 44179 | | |
44163 | 44180 | | |
44164 | 44181 | | |
| |||
49291 | 49308 | | |
49292 | 49309 | | |
49293 | 49310 | | |
| 49311 | + | |
| 49312 | + | |
| 49313 | + | |
| 49314 | + | |
| 49315 | + | |
49294 | 49316 | | |
49295 | 49317 | | |
49296 | 49318 | | |
| |||
49332 | 49354 | | |
49333 | 49355 | | |
49334 | 49356 | | |
| 49357 | + | |
| 49358 | + | |
| 49359 | + | |
| 49360 | + | |
| 49361 | + | |
| 49362 | + | |
| 49363 | + | |
| 49364 | + | |
| 49365 | + | |
49335 | 49366 | | |
49336 | 49367 | | |
49337 | 49368 | | |
49338 | 49369 | | |
49339 | 49370 | | |
| 49371 | + | |
| 49372 | + | |
| 49373 | + | |
| 49374 | + | |
| 49375 | + | |
| 49376 | + | |
| 49377 | + | |
49340 | 49378 | | |
| 49379 | + | |
| 49380 | + | |
| 49381 | + | |
| 49382 | + | |
49341 | 49383 | | |
49342 | 49384 | | |
49343 | 49385 | | |
| |||
53679 | 53721 | | |
53680 | 53722 | | |
53681 | 53723 | | |
| 53724 | + | |
| 53725 | + | |
| 53726 | + | |
| 53727 | + | |
| 53728 | + | |
| 53729 | + | |
| 53730 | + | |
| 53731 | + | |
| 53732 | + | |
| 53733 | + | |
| 53734 | + | |
| 53735 | + | |
| 53736 | + | |
| 53737 | + | |
| 53738 | + | |
| 53739 | + | |
| 53740 | + | |
| 53741 | + | |
| 53742 | + | |
| 53743 | + | |
| 53744 | + | |
| 53745 | + | |
| 53746 | + | |
| 53747 | + | |
| 53748 | + | |
| 53749 | + | |
| 53750 | + | |
53682 | 53751 | | |
53683 | 53752 | | |
53684 | 53753 | | |
53685 | | - | |
| 53754 | + | |
53686 | 53755 | | |
53687 | 53756 | | |
53688 | 53757 | | |
53689 | 53758 | | |
53690 | 53759 | | |
| 53760 | + | |
53691 | 53761 | | |
| 53762 | + | |
53692 | 53763 | | |
53693 | 53764 | | |
53694 | 53765 | | |
| |||
53700 | 53771 | | |
53701 | 53772 | | |
53702 | 53773 | | |
53703 | | - | |
53704 | | - | |
| 53774 | + | |
| 53775 | + | |
| 53776 | + | |
| 53777 | + | |
53705 | 53778 | | |
53706 | 53779 | | |
53707 | 53780 | | |
| |||
53729 | 53802 | | |
53730 | 53803 | | |
53731 | 53804 | | |
53732 | | - | |
53733 | | - | |
| 53805 | + | |
| 53806 | + | |
| 53807 | + | |
| 53808 | + | |
| 53809 | + | |
53734 | 53810 | | |
| 53811 | + | |
| 53812 | + | |
| 53813 | + | |
| 53814 | + | |
| 53815 | + | |
| 53816 | + | |
| 53817 | + | |
| 53818 | + | |
| 53819 | + | |
| 53820 | + | |
53735 | 53821 | | |
53736 | 53822 | | |
53737 | 53823 | | |
| |||
53745 | 53831 | | |
53746 | 53832 | | |
53747 | 53833 | | |
| 53834 | + | |
| 53835 | + | |
| 53836 | + | |
| 53837 | + | |
| 53838 | + | |
| 53839 | + | |
| 53840 | + | |
| 53841 | + | |
53748 | 53842 | | |
53749 | 53843 | | |
53750 | | - | |
| 53844 | + | |
53751 | 53845 | | |
53752 | 53846 | | |
53753 | 53847 | | |
| |||
53772 | 53866 | | |
53773 | 53867 | | |
53774 | 53868 | | |
| 53869 | + | |
53775 | 53870 | | |
53776 | 53871 | | |
53777 | 53872 | | |
53778 | 53873 | | |
53779 | 53874 | | |
53780 | | - | |
53781 | 53875 | | |
53782 | 53876 | | |
53783 | 53877 | | |
| |||
53796 | 53890 | | |
53797 | 53891 | | |
53798 | 53892 | | |
53799 | | - | |
| 53893 | + | |
| 53894 | + | |
| 53895 | + | |
| 53896 | + | |
| 53897 | + | |
| 53898 | + | |
| 53899 | + | |
53800 | 53900 | | |
53801 | 53901 | | |
| 53902 | + | |
| 53903 | + | |
| 53904 | + | |
| 53905 | + | |
| 53906 | + | |
| 53907 | + | |
| 53908 | + | |
| 53909 | + | |
| 53910 | + | |
53802 | 53911 | | |
53803 | 53912 | | |
53804 | 53913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3476 | 3476 | | |
3477 | 3477 | | |
3478 | 3478 | | |
| 3479 | + | |
| 3480 | + | |
3479 | 3481 | | |
3480 | 3482 | | |
3481 | 3483 | | |
| |||
0 commit comments