Let's say we want to allocate a block from the heap by using
malloc. When allocating a a large size of memory,
mmap internally and for a small size allocation,
Note that the heap is continuous when use
Let say my allocation is relative medium size and
let's say I call
malloc(small); malloc(medium); free(medium)
according to this article The history of Unix's confusing set of low-level ways to allocate memory
If you free()d the right things to create a block of unused space at the top of the break, malloc() and company might eventually call
sbrk()to shrink the program's break and give the memory back to the OS.
since the free medium block is the last one(the small allocated block is the second last one), so the memory will be given back to OS.
Below is my questions:
My understanding about the statement "the memory will be given back to OS" is: the free block's mappings between virtual memory and physical memory are dropped, other processes can use the physical memory that was originally occupied by this free block. Is my understanding correct?
this time I call
malloc(medium); malloc(small); free(medium)Since there is still an allocated block in the end, does the free block's mapping between virtual memory and physical memory still exist? can other processes use this free block's physical memory?