On 2013/7/19 14:34, Willy Tarreau wrote:
On Fri, Jul 19, 2013 at 01:55:43PM +0800, Godbach wrote:
Hi Willy,
Here is part information about strace during haproxy startup:
open("h.cfg", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1985, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x7fadfa0e0000
read(3, "global\n\tnode vs_1\n\tpidfile /tmp/"..., 4096) = 1985
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7fadfa0e0000, 4096) = 0
brk(0) = 0x164d000
brk(0x166f000) = 0x166f000
mmap(NULL, 41947136, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fadf78c0000
mmap(NULL, 62918656, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fadf3cbf000
mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fadf32be000
mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fadf28bd000
epoll_create(2621472) = 3
mmap(NULL, 31461376, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fadf0abc000
The allocation of memory related to 40Mbytes and 60Mbytes should be in
these two lines:
mmap(NULL, 41947136, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fadf78c0000
mmap(NULL, 62918656, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fadf3cbf000
Yes, as you said, mmap is used to allocate the areas. Is that what you
meant libc has not called memset yet.
Yes exactly. So maybe we should change this. I had a draft a long time
ago involving a "safe_malloc" function that would allocate and clear
an area. Maybe it would be time to switch to using such a thing for all
the critical parts of the initialization code.
Regards,
Willy
Oh, one thing may be forgotten mentioned in my first mail:
Then I run a simple program which also called calloc to alloc 300Mbytes
meomory, and the reuslt as below:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17797 root 20 0 304m 300m 332 S 0.0 7.7 0:00.15 tmem
The RES is 300M just as it supposed to be.
The simple test program 'tmem' I wrote just allocates memory in
300Mbytes by calloc, mmap is also be used to do the allocation, the
strace result is as below:
execve("./tmem", ["./tmem"], [/* 33 vars */]) = 0
brk(0) = 0xd22000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x7fcb67263000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=114390, ...}) = 0
mmap(NULL, 114390, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fcb67247000
close(3) = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3,
"\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\27B\25?\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2076800, ...}) = 0
mmap(0x3f15400000, 3896632, PROT_READ|PROT_EXEC,
MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3f15400000
mprotect(0x3f155ad000, 2097152, PROT_NONE) = 0
mmap(0x3f157ad000, 24576, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ad000) = 0x3f157ad000
mmap(0x3f157b3000, 17720, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3f157b3000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x7fcb67246000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x7fcb67245000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x7fcb67244000
arch_prctl(ARCH_SET_FS, 0x7fcb67245700) = 0
mprotect(0x3f157ad000, 16384, PROT_READ) = 0
mprotect(0x3f14e21000, 4096, PROT_READ) = 0
munmap(0x7fcb67247000, 114390) = 0
mmap(NULL, 314576896, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7fcb54643000
pause(
The last line shows that mmap is used. Since this program can use full
size memory it supposed to, there is a conflict between this result and
the conclusion we talked about before.
The test codes is as below:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MEMSIZE (300 * 1024 * 1024)
int main(int argc, char *argv[])
{
char *p = NULL;
p = calloc(1, MEMSIZE);
pause();
free(p);
return 0;
}
--
Best Regards,
Godbach