The "too small to fail" memory-allocation rule
The "too small to fail" memory-allocation rule
Posted Dec 24, 2014 9:23 UTC (Wed) by epa (subscriber, #39769)In reply to: The "too small to fail" memory-allocation rule by ibukanov
Parent article: The "too small to fail" memory-allocation rule
Essentially, when you fork() the kernel has no way of knowing that you are just about to call exec() immediately afterwards, so it has to either reserve space for a complete copy of all your process's memory, or end up overcommitting and resorting to an OOM killer if it guessed wrong. If userland can give the kernel a bit more information then the kernel can do its job better.
Posted Dec 24, 2014 9:35 UTC (Wed)
by roc (subscriber, #30627)
[Link] (9 responses)
Also, copy-on-write fork()ing has other valuable uses. In rr we use it to create checkpoints very efficiently.
Posted Dec 24, 2014 9:54 UTC (Wed)
by epa (subscriber, #39769)
[Link] (3 responses)
Posted Dec 25, 2014 18:44 UTC (Thu)
by quotemstr (subscriber, #45331)
[Link]
vfork does what you want. The "child" shares memory with the parent until it calls exec, so you avoid not only the commit charge catastrophe of copy-on-write fork, but also gain a significant performance boost from not having to copy the page tables.
Posted Dec 25, 2014 22:18 UTC (Thu)
by ldo (guest, #40946)
[Link] (1 responses)
Posted Dec 26, 2014 7:33 UTC (Fri)
by epa (subscriber, #39769)
[Link]
vfork() doesn't make a copy of the address space and so doesn't require either over-caution or over-committing. But it has other limitations.
Posted Dec 24, 2014 10:18 UTC (Wed)
by ibukanov (subscriber, #3942)
[Link] (4 responses)
To customize the child before exec one does not need full fork, vfork is enough and does not require overcommit.
Posted Dec 24, 2014 11:34 UTC (Wed)
by pbonzini (subscriber, #60935)
[Link] (3 responses)
Posted Dec 24, 2014 12:31 UTC (Wed)
by ibukanov (subscriber, #3942)
[Link] (1 responses)
Posted Dec 30, 2014 0:04 UTC (Tue)
by klossner (subscriber, #30046)
[Link]
Posted Dec 24, 2014 14:27 UTC (Wed)
by justincormack (subscriber, #70439)
[Link]
The "too small to fail" memory-allocation rule
The "too small to fail" memory-allocation rule
The "too small to fail" memory-allocation rule
That issue was solved a long time ago, which is why the vfork(2) hack is obsolete nowadays.
Re: shouldn't require a complete copy of the parent process's memory
Re: shouldn't require a complete copy of the parent process's memory
The "too small to fail" memory-allocation rule
The "too small to fail" memory-allocation rule
The "too small to fail" memory-allocation rule
The "too small to fail" memory-allocation rule
The "too small to fail" memory-allocation rule