fix(force_shutdown): add some comments for the range of max_heap_size

This commit is contained in:
Shawn 2021-08-12 22:05:58 +08:00 committed by turtleDeng
parent 844133c7c5
commit 1245020ec0
1 changed files with 5 additions and 2 deletions

View File

@ -224,15 +224,18 @@ tune_heap_size(#{max_heap_size := MaxHeapSize}) ->
}); });
tune_heap_size(undefined) -> ok. tune_heap_size(undefined) -> ok.
%% We multiply the size with factor ?OOM_FACTOR, to give the
%% process a chance to suicide by `check_oom/1`
must_kill_heap_size(Size) -> must_kill_heap_size(Size) ->
%% We set the max allowed heap size by `erlang:process_flag(max_heap_size, #{size => Size})`,
%% where the `Size` cannot be set to an integer lager than `(1 bsl 59) - 1` on a 64-bit system,
%% or `(1 bsl 27) - 1` on a 32-bit system.
MaxAllowedSize = case erlang:system_info(wordsize) of MaxAllowedSize = case erlang:system_info(wordsize) of
8 -> % arch_64 8 -> % arch_64
(1 bsl 59) - 1; (1 bsl 59) - 1;
4 -> % arch_32 4 -> % arch_32
(1 bsl 27) - 1 (1 bsl 27) - 1
end, end,
%% We multiply the size with factor ?OOM_FACTOR, to give the
%% process a chance to suicide by `check_oom/1`
case ceil(Size * ?OOM_FACTOR) of case ceil(Size * ?OOM_FACTOR) of
Size0 when Size0 >= MaxAllowedSize -> MaxAllowedSize; Size0 when Size0 >= MaxAllowedSize -> MaxAllowedSize;
Size0 -> Size0 Size0 -> Size0