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 :)
Thanks in advance
I recommend you report your thread and move it into programming.
As for mmap:
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).
|All times are GMT -5. The time now is 11:36 AM.|