Re: [xml] Memory not going away..
- From: Rick Jones <rick jones2 hp com>
- To: xml gnome org
- Subject: Re: [xml] Memory not going away..
- Date: Tue, 08 Mar 2005 15:03:09 -0800
Coincidentally, if I have system with 3 GB of RAM, and I allocate and free
3GB of ram in my process, but then do not exit.. any other processes would
be forced into swap waiting for my process to complete and free up
resources (namely, 3GB of RAM). In Linux, calls to free in the process
return the memory to the OS.
That seems to depend on the size of the malloc/free? I wrote this admittedly
simplistic test program:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
void *pointer;
int i;
struct stat buf;
for (i = 0; i < atoi(argv[1]); i++) {
stat("beforemalloc",&buf);
pointer = malloc(atoi(argv[2]));
if (pointer) {
stat("beforefree",&buf);
free(pointer);
}
else {
perror("malloc");
exit(-1);
}
}
}
and with some values of argv[2] it seems to have stuff between the stat calls
but with others it does not:
with 10 iterations asking for 1024 bytes:
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
brk(0) = 0x804a000
brk(0x806b000) = 0x806b000
brk(0) = 0x806b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
same for 10KB and 100KB. Asking for 1MB at a time gives:
tardy:/home/raj# strace ./test 10 `expr 1024 \* 1024`
execve("./test", ["./test", "10", "1048576"], [/* 17 vars */]) = 0
uname({sys="Linux", node="tardy", ...}) = 0
brk(0) = 0x804a000
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x40017000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=55393, ...}) = 0
old_mmap(NULL, 55393, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40018000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/tls/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\360Y\1"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=1253924, ...}) = 0
old_mmap(NULL, 1260140, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x40026000
old_mmap(0x4014f000, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3,
0x129000) = 0x4014f000
old_mmap(0x40157000, 10860, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40157000
close(3) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015a000
set_thread_area({entry_number:-1 -> 6, base_addr:0x4015a2a0, limit:1048575,
seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0,
useable:1}) = 0
munmap(0x40018000, 55393) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
stat64("beforemalloc", 0xbffffbd4) = -1 ENOENT (No such file or directory)
mmap2(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x4015b000
stat64("beforefree", 0xbffffbd4) = -1 ENOENT (No such file or directory)
munmap(0x4015b000, 1052672) = 0
exit_group(10) = ?
My little test seems to show the cross-over point being around 127KB. Asking
for 127KB had the brk calls, asking for 128KB started the mmap/munmap stuff.
tardy:/home/raj# ldd ./test
libc.so.6 => /lib/tls/libc.so.6 (0x40026000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
tardy:/home/raj# uname -a
Linux tardy 2.6.8-1-686 #1 Thu Nov 25 04:34:30 UTC 2004 i686 GNU/Linux
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]