Bug #21944
closed"Cannot allocate memory" with M:N threads or Ractors on a low RAM Linux machine
Description
Linux default overcommit policy (vm.overcommit_memory=0) will fail for allocations which are "obvious overcommits" (https://www.kernel.org/doc/html/latest/mm/overcommit-accounting.html). Under M:N threading (including under Ractors) we allocate a ~512MB section of RAM to use (the physical pages are lazily mapped in when used). This caused the following exception on a machine with <512 MB of RAM.
Thread#initialize': can't create Thread: Cannot allocate memory (ThreadError)
This can be solved by initially mapping the region of memory in as protected, and only enabling read/write the first time a stack is used. We already added a guard page the first time a stack was used, so this just inverts that mprotect call (it also makes two calls instead of one, but since these are only used the first time a stack is used, I think that simplicity is worth the extra syscall).