Hi Godbach,

On Fri, Jul 19, 2013 at 04:02:17PM +0800, Godbach wrote:
> 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;
> }

I agree and can confirm your results here. Also, if I replace the
calloc with a malloc, I still see mmap and we don't have the 300M
RSS anymore :

willy@pcw:~$ ps auxw|grep a.out
willy    31956  0.0  0.0   2880   632 pts/4    S+   07:36   0:00 strace ./a.out
willy    31957  0.0  0.0 308764   320 pts/4    S+   07:36   0:00 ./a.out

So... it's becoming increasingly likely that we have a bug in haproxy
or at least that we're overlooking something. That said I don't see
what the issue could be considering that we're initializing fdinfo and
fdtab with a calloc() just at one place. There's not even a realloc().

Best regards,
Willy


Reply via email to