[ruby-core:124933] [Ruby Bug#21944] "Cannot allocate memory" with M:N threads or Ractors on a low RAM Linux machine
Issue #21944 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #21944: "Cannot allocate memory" with M:N threads or Ractors on a low RAM Linux machine https://bugs.ruby-lang.org/issues/21944 * Author: jhawthorn (John Hawthorn) * Status: Open * Assignee: ractor * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: REQUIRED ---------------------------------------- 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). https://github.com/ruby/ruby/pull/16232 -- https://bugs.ruby-lang.org/
participants (1)
-
jhawthorn (John Hawthorn)