diff --git a/src/emqx_misc.erl b/src/emqx_misc.erl index 75db4227f..eb6a25377 100644 --- a/src/emqx_misc.erl +++ b/src/emqx_misc.erl @@ -224,15 +224,18 @@ tune_heap_size(#{max_heap_size := MaxHeapSize}) -> }); 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) -> + %% 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 8 -> % arch_64 (1 bsl 59) - 1; 4 -> % arch_32 (1 bsl 27) - 1 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 Size0 when Size0 >= MaxAllowedSize -> MaxAllowedSize; Size0 -> Size0