Project

General

Profile

Actions

Bug #21944

closed

"Cannot allocate memory" with M:N threads or Ractors on a low RAM Linux machine

Bug #21944: "Cannot allocate memory" with M:N threads or Ractors on a low RAM Linux machine

Added by jhawthorn (John Hawthorn) 1 day ago. Updated 1 day ago.

Status:
Closed
Assignee:
Target version:
-
[ruby-core:124933]

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).

https://github.com/ruby/ruby/pull/16232

Actions

Also available in: PDF Atom