Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 12-21-2010, 12:28 AM   #1
Registered: Mar 2007
Posts: 44

Rep: Reputation: 16
mmap question

I am working on the webkit open source code. I see a small function like this

void TCMalloc_SystemRelease(void* start, size_t length)
void* newAddress = mmap(start, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);


This function TCMalloc_SystemRelease() is supposed to release the memory back to the system, but it is calling mmap() function instead of free or delete. My understanding is that mmap is used to allocate the resources. That is it creates a new mapping in the virtual address space of the calling process.

Please can any one let me know is mmap can be used to release the memory back to the system also.

Sorry if I sound stupid
Please help

Thanks in advance
Old 01-20-2011, 04:41 AM   #2
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
I recommend you report your thread and move it into programming.

As for mmap:
Old 01-20-2011, 08:33 AM   #3
LQ Guru
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Originally Posted by Manjunath1847 View Post
is mmap can be used to release the memory back to the system also.
I'm not certain, but I think so.

Note the important phrase in the documentation H_TexMex_H linked:

The mapping established by mmap() shall replace any previous mappings for those whole pages containing any part of the address space of the process starting at pa and continuing for len bytes.

I think that means the previous mapping is first unmapped even if it is the same as the new mapping. In the case of ordinary anonymous memory, unmapping it would release the memory. Then you might expect mapping it would reallocate the memory, but it doesn't.

Mapping anonymous memory only "commits" that memory. It doesn't actually allocate each page of that memory until the process reads or writes that page.

So I think a process could keep a large range of memory mapped but unallocated, so each page of that memory is automatically allocated on first use. Then it might be able to revert all that memory back to being mapped but unallocated simply by mapping it again (I'm not certain that remapping trick would work, but I think so).

Last edited by johnsfine; 01-20-2011 at 08:44 AM.


memory, memory management, mmap

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mmap 1mela Programming 2 02-05-2010 05:50 AM
Question on using mmap to access physical memory Gnu2Linux2 Linux - Embedded & Single-board computer 1 10-05-2009 03:54 AM
mmap busyfire Linux - Newbie 0 03-16-2009 06:19 AM
Newbie question about usage of mmap justin8086 Linux - Hardware 1 11-22-2005 01:10 PM
using mmap AngryLlama Programming 1 02-09-2005 08:53 AM

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration