From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,6ef7c3e5f8e99111 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2002-08-28 01:08:00 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: emmanuel.choquet@hp.com (Emmanuel Choquet) Newsgroups: comp.unix.tru64 Subject: Re: Returning memory to system after a free Date: 28 Aug 2002 01:08:00 -0700 Organization: http://groups.google.com/ Message-ID: <7aabdf42.0208280008.8ac9925@posting.google.com> References: NNTP-Posting-Host: 161.114.126.50 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1030522080 23140 127.0.0.1 (28 Aug 2002 08:08:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 28 Aug 2002 08:08:00 GMT Xref: archiver1.google.com comp.unix.tru64:8504 " > "Jan Sundberg" wrote in message > news:e7875f7.0208270237.4e0ba29e@posting.google.com... > > 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: malloc has actually to do only with virtual memory, IE address space. roughly, the process is the following, in the VM space of the process : if the malloc space asked is new - has never been asked - the Mach kernel and Unix VM algorithm will map the space in your process - free() will not unmap the space, Mach and Unix level, VSize of the process will remain the same. In a next malloc call, within the size of the first call, Mach kernel and Unix memory allocation have nothing to do, the new space can be on overlap with the former freed space, VM and Physical. Now in the physical memory side, you first have 2 cases : - 'normal' process, address space is created at malloc call, and Zero-filled pages will be created at 1st access, making the RSS growing. if you free, nothing happens, or at least nothing is different compared to not freeing. RSS can remain the same, and Vsize will obviously remain the same. To get back memory to free list - shrinking the RSS-, the standard memory allocation algorithm applies : possibily paging out if free list is under vm_page_free_min or swapped out if free list under vm_page_free_optimal and no process thread has been runnable for the last 20/30 seconds. - Process attributes include locking page in memory -(Real time option). In this case all physical pages are created at malloc call, not at access time. The strange thing is that pages will not be paged out, but process can be swapped out ! This behavior is *very* efficient for standard malloc usage, and -trade off- very poor for huge mallocs, followed by free(). Long process inactivity which can lead to long swapout time of useless data. Paging out these inconsistent pages is painful as well. Emmanuel