Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #15668

Re: fork() 50 times slower on some Linux kernels?

From Stephen Sprunk <stephen@sprunk.org>
Newsgroups comp.lang.c
Subject Re: fork() 50 times slower on some Linux kernels?
Date 2012-01-09 17:20 -0600
Organization A noiseless patient Spider
Message-ID <jefso9$8mo$1@dont-email.me> (permalink)
References <20147768-1b78-4ac5-84e5-607c1d47c6a6@dp8g2000vbb.googlegroups.com> <jefong$a4q$1@dont-email.me> <20120109140729.280@kylheku.com>

Show all headers | View raw


On 09-Jan-12 16:30, Kaz Kylheku wrote:
> On 2012-01-09, Stephen Sprunk <stephen@sprunk.org> wrote:
>> On 09-Jan-12 14:25, Elmar wrote:
>>> a previous discussion in this group mentioned the problem that fork()
>>> is a resource bottleneck because it needs to (virtually) duplicate a
>>> process' memory space:
>>>
>>> http://groups.google.com/group/comp.lang.c/browse_thread/thread/911978685974e041/bdd37113d7b43e0c
>>> ...
>>> Google didn't help much, so my hope was that one of you has heard of/
>>> encountered this problem, knows which kernels are affected, and when/
>>> how it was solved, maybe there is a configuration trick etc.?
>>
>> Did you read that thread?  The answer is in there, and it has nothing to
>> do with the kernel versions; it's about whether vm overcommitment is
>> enabled (fast but unsafe) or disabled (safe but unfast).
> 
> That's going to be moot in this issue that he's having. Strict overcommit
> accounting only makes a difference to whether a call to mmap succeeds or
> fails. Allocation of the mmaps is still lazy. The OS merely ensures (sort of)
> that it has the "cash" to back the "check" it has written (i.e. that's exactly
> why this is called accounting!) ``If we hand out this virtual space, will there
> later be enough pages available to populate it?'' If the answer is no, then the
> mmap is denied (ENOMEM).

We're not talking about mmap() here; we're talking about fork().

When you fork(), all the pages in the parent process are shared with the
child, with copy-on-write behavior.  When overcommitment is enabled,
there is no backing guaranteed for those potential future copies, and
modifying them (in either process) forces the kernel to find backing at
some unspecified point in the future--which may fail.  Disabling
overcommitment moves that problem to the present by forcing the kernel
to find backing for all those pages during the fork(), and that takes time.

> In any case, did you notice in the original posting that this 1 second
> pause occurs on a system with 8GB of RAM?

That is apparently how long it takes for the kernel on his system to
find backing for all those pages.  I suspect that delay is why
overcommitment is on by default.

S

-- 
Stephen Sprunk         "God does not play dice."  --Albert Einstein
CCIE #3723         "God is an inveterate gambler, and He throws the
K5SSS        dice at every possible opportunity." --Stephen Hawking

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

fork() 50 times slower on some Linux kernels? Elmar <elmar.krieger@gmail.com> - 2012-01-09 12:25 -0800
  Re: fork() 50 times slower on some Linux kernels? Ian Collins <ian-news@hotmail.com> - 2012-01-10 09:41 +1300
  Re: fork() 50 times slower on some Linux kernels? Kaz Kylheku <kaz@kylheku.com> - 2012-01-09 21:32 +0000
    [OT] Re: fork() 50 times slower on some Linux kernels? jt@toerring.de (Jens Thoms Toerring) - 2012-01-09 22:12 +0000
      Re: [OT] Re: fork() 50 times slower on some Linux kernels? Kaz Kylheku <kaz@kylheku.com> - 2012-01-09 22:32 +0000
        Re: [OT] Re: fork() 50 times slower on some Linux kernels? Ian Collins <ian-news@hotmail.com> - 2012-01-10 11:56 +1300
  Re: fork() 50 times slower on some Linux kernels? Stephen Sprunk <stephen@sprunk.org> - 2012-01-09 16:11 -0600
    Re: fork() 50 times slower on some Linux kernels? Kaz Kylheku <kaz@kylheku.com> - 2012-01-09 22:30 +0000
      Re: fork() 50 times slower on some Linux kernels? Stephen Sprunk <stephen@sprunk.org> - 2012-01-09 17:20 -0600
        Re: [OT] fork() 50 times slower on some Linux kernels? jt@toerring.de (Jens Thoms Toerring) - 2012-01-09 23:57 +0000
          Re: [OT] fork() 50 times slower on some Linux kernels? Kaz Kylheku <kaz@kylheku.com> - 2012-01-10 00:22 +0000
            Re: [OT] fork() 50 times slower on some Linux kernels? Stephen Sprunk <stephen@sprunk.org> - 2012-01-09 20:39 -0600
              Re: [OT] fork() 50 times slower on some Linux kernels? William Ahern <william@wilbur.25thandClement.com> - 2012-01-09 19:43 -0800
                Re: [OT] fork() 50 times slower on some Linux kernels? Stephen Sprunk <stephen@sprunk.org> - 2012-01-10 00:31 -0600
          Re: fork() 50 times slower on some Linux kernels? Elmar <elmar.krieger@gmail.com> - 2012-01-11 14:39 -0800
        Re: fork() 50 times slower on some Linux kernels? Nobody <nobody@nowhere.com> - 2012-01-10 23:07 +0000

csiph-web