Max_heap_size limited to 29 bits?

I am using the +hmax command line option to set the default maximum heap size for processes. For some time after I increased the limit I noticed that the options seemed to have no effect. Now I think I found why. It looks that the max heap size is stored as a 30-bit signed integer value. If I start the system with

+hmax 536870912

then using process_info for any process to find effective limit shows negative number

{max_heap_size,#{error_logger => true,kill => true, size => -536870912}}

For 536870911 it works correctly. The same behaviour can be observed when erlang:system_flag(max_heap_size, Size) is used to set the max size. But setting the max size for an individual process with process_flag(max_heap_size, Size) does not have this limitation.

I could not find any documentation describing this. Is it intentional? If not, can it be fixed?

1 Like

It’s a bug. I also ran into it and fixed it, but forgot to fire a PR (will do soon).

Actual limit for the heap size is 1 bsl 59 - 1 words.

At the time being, the maximum you can do via command line is 4Gb - 1 word. That is, erl +hmax 536870911
(536870911 is 4 * 1024 * 1024 * 1024 / 8 - 1, 4 Gb divided by 8 bytes in the word, minus one word)

3 Likes

Here it is - fix +hmax command line argument to accept > 4 Gb by max-au · Pull Request #6081 · erlang/otp · GitHub

2 Likes

Thank you!

1 Like