Re: fork() failed with ENOMEM, free indicates enough, tune what kernel parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It depends on how big your processes are, and whether or not you have
kernel safety features turned on.

For example, if I have a 500M program that tries to run a program that
fits in 30K of space, I still have to have 500M of free memory to run it.
why?  The way UNIX creates processes is by forking before execing.
Forking creates two IDENTICAL copies of a process, with the only
difference between the ttwo being the return value of fork().  That means
it has to copy the ENTIRE process in order to fork, so you have to have
that much memory available (it doesn't physically copy it - it's got lots
of nifty optimizations including Copy-On-Write, but it has to at least
reserve the space first).  So, if you have a large process trying to run
external commands, that could easily bbe causing your problems.

There's some overcommit setting that you can turn off, but I forget what
this is.

Jon

On Thu, 2 Oct 2003, Tom Stevelt wrote:

>
> We are having issues with fork() failing sporadically -- but we can't
> figure what resource is short supply.
>
> This shows we still have 45 meg of ram available.
>
> rhd </home/tms/src/systest>$ free -m
>              total       used       free     shared    buffers     cached
> Mem:           123        113          9          0          4         30
> -/+ buffers/cache:         78         45
> Swap:          250         19        231
>
> This is the strace output from a test program.  Can anybody suggest how
> to tell which kernel parameter is in short supply?
>
> rhd </home/tms/src/systest>$ strace -f  -ores forktest 3
> fork failed, errno 12
> rhd </home/tms/src/systest>$
> rhd </home/tms/src/systest>$ cat res
> 4042  execve("./forktest", ["forktest", "3"], [/* 26 vars */]) = 0
> 4042  uname({sys="Linux", node="rhd", ...}) = 0
> 4042  brk(0)                            = 0x80497dc
> 4042  open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
> 4042  open("/etc/ld.so.cache", O_RDONLY) = 3
> 4042  fstat64(3, {st_mode=S_IFREG|0644, st_size=48658, ...}) = 0
> 4042  old_mmap(NULL, 48658, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40014000
> 4042  close(3)                          = 0
> 4042  open("/lib/i686/libc.so.6", O_RDONLY) = 3
> 4042  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\260Y\1"..., 512) = 512
> 4042  fstat64(3, {st_mode=S_IFREG|0755, st_size=1452984, ...}) = 0
> 4042  old_mmap(0x42000000, 1290052, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x42000000
> 4042  old_mmap(0x42134000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x134000) = 0x42134000
> 4042  old_mmap(0x42139000, 8004, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x42139000
> 4042  close(3)                          = 0
> 4042  old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40020000
> 4042  munmap(0x40014000, 48658)         = 0
> 4042  mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40021000
> 4042  fork()                            = -1 ENOMEM (Cannot allocate memory)
> 4042  fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
> 4042  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000
> 4042  write(1, "fork failed, errno 12\n", 22) = 22
> 4042  munmap(0x40014000, 4096)          = 0
> 4042  _exit(22)                         = ?
> rhd </home/tms/src/systest>$
>
> Thanks - Tom
>
> -----Tom Stevelt--------------------Victory Wholesale Grocers-----------
>      tms@xxxxxxx                    400 Victory Drive
>      513-746-1742 ext 1224          Springboro, OH 45066
> ------------------------------------------------------------------------
>
>
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list
>


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux