From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,6ef7c3e5f8e99111,start X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2002-08-27 03:37:19 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: janne@nevdull.nu (Jan Sundberg) Newsgroups: comp.unix.tru64 Subject: Returning memory to system after a free Date: 27 Aug 2002 03:37:19 -0700 Organization: http://groups.google.com/ Message-ID: NNTP-Posting-Host: 212.209.164.98 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1030444639 9004 127.0.0.1 (27 Aug 2002 10:37:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 27 Aug 2002 10:37:19 GMT Xref: archiver1.google.com comp.unix.tru64:8497 Hi. I'm trying to return memory segments to kernel after a free. This har been tested and verified by using the malloc tuning values on both 4.0 and 5.1: __delayed_free = 0; __madvisor = 1; __minshrinkfactor = 0.0; __minshrink = 1; in a test program (mem) using malloc and free and checking the process RSS with ps on the side. Running example: ~> mem 2 10000000 20004864 / -33264 where the figures show the break returned by sbrk(0) compared to program start value: - after a first allocation of (2 blocks of 10000000 bytes), and - after free of these blocks (i e it shrunk a bit) The RSS was verified during program run (with inserted sleeps): utvsrv1 ~> ps -o rss -p 32297 RSS 152K utvsrv1 ~> ps -o rss -p 32297 RSS 19M utvsrv1 ~> ps -o rss -p 32297 RSS 136K Now, trying different sizes and number of blocks yields: n=$((16*1024*1024)) # 16 M in different ways d=1 while [[ n -ge 10 ]]; do echo -n $d $n " : " ./mem $d $n n=$(($n/2)) d=$(($d*2)) done 1 16777216 : 16785408 / -33264 // 1 block of 16 M 2 8388608 : 16793600 / -33264 // 2 blocks of 8 M 4 4194304 : 16809984 / -33264 // and so on... 8 2097152 : 16842752 / -25072 16 1048576 : 16908288 / -25072 32 524288 : 17039360 / -25072 64 262144 : 16760832 / -25072 128 131072 : 16850944 / -25072 256 65536 : 16809984 / -25072 512 32768 : 16793600 / -25072 1024 16384 : 16785408 / -25072 2048 8192 : 21078016 / 21078016 // hmmm... 4096 4096 : 21094400 / 21094400 8192 2048 : 21061632 / 21061632 ... No memory is returned using smaller blocks than 16k ! Further testing yielded: utvsrv1 ~> mem 128 10233 1351680 / -25056 // returned ! utvsrv1 ~> mem 128 10232 1351680 / 1351680 // not returned ! How come segments smaller than a certain size (10233) never are returned to the kernel !?!? This is a major drawback since most segments are relatively small (e g malloc (sizeof (TYPE))). Sincerely. / Jan Sundberg