Hi,

I am running a same program in X86 and MIPS Linux, but with two
different behaviour observed by strace:

program:

cat test.c
main()
{
char *p;
p = malloc(4096);
sleep(1);
p = malloc(4096);
sleep(1);
p = malloc(4096);
sleep(1);
}

LOG in X86:

strace ./t
execve("./t", ["./t"], [/* 34 vars */]) = 0
brk(0) = 0x804a000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or
directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7ef1000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=78183, ...}) = 0
mmap2(NULL, 78183, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7edd000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or
directory)
open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\0` \1\000"...,
512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=1307104, ...}) = 0
mmap2(NULL, 1312164, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE,
3, 0) = 0xb7d9c000
mmap2(0xb7ed7000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
MAP_DENYWRITE, 3, 0x13b) = 0xb7ed7000
mmap2(0xb7eda000, 9636, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
MAP_ANONYMOUS, -1, 0) = 0xb7eda000
close(3) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7d9b000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7d9b6c0, limit:
1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
seg_not_present:0, useable:1}) = 0
mprotect(0xb7ed7000, 4096, PROT_READ) = 0
munmap(0xb7edd000, 78183) = 0
brk(0) = 0x804a000
brk(0x806c000) = 0x806c000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, {1, 0}) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, {1, 0}) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, {1, 0}) = 0
exit_group(0) = ?
Process 8323 detached

LOG in MIPS:

strace ./m
execve("./m", ["./m"], [/* 9 vars */]) = 0
svr4_syscall() = 4122
svr4_syscall() = 4045
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\3 04L\1"...,
1024) = 1024
fstat64(3, {st_mode=S_IFREG|0755, st_size=1786692, ...}) = 0
old_mmap(NULL, 1903056, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) =
0x2ab04000
mprotect(0x2ac8d000, 293328, PROT_NONE) = 0
old_mmap(0x2accc000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|
MAP_FIXED, 3, 0x188000) = 0x2accc000
old_mmap(0x2acd2000, 10704, PROT_READ|PROT_WRITE, MAP_PRIVATE|
MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2acd2000
close(3) = 0
brk(0) = 0x441000
brk(0x442000) = 0x442000
brk(0) = 0x442000
brk(0x443000) = 0x443000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 16) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 16) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 16) = 0
nanosleep({1, 0}, {1, 0}) = 0
brk(0) = 0x443000
brk(0x444000) = 0x444000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 16) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 16) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 16) = 0
nanosleep({1, 0}, {1, 0}) = 0
brk(0) = 0x444000
brk(0x445000) = 0x445000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 16) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 16) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 16) = 0
nanosleep({1, 0}, {1, 0}) = 0
exit_group(0) = ?
Process 784 detached


You can see in MIPS the three malloc() invoke three times brk() which
a small space add so the performance is bad, but in X86 the brk() in
first time is large enough so the succeeding malloc didn't need to
call brk() again. So my question is how to make MIPS glibc's malloc()
behaviour the same as in X86, need to recomplile the glibc or just a
environment var is enough?

Thanks.
Bin