malloc: unused heap is still kept in heap list
Shuo Wang
wangshuo47@huawei.com
Mon Jan 25 14:15:49 GMT 2021
Hi,
According to heap_trim, heap will be freed from the the
one where the top chunk is located in. (We will call it
last heap below)
static int
heap_trim (heap_info *heap, size_t pad)
{
while (top_chunk == chunk_at_offset (heap, sizeof (*heap)))
{
...
delete_heap();
...
}
}
As shown below, however, when last heap is still used
prev heap will not be freed to os even if there are just
unused chunks in prev heap.
|---------------------| |---------------------|
| top chunk | | |
|---------------------| | |
| allocated chunk | | |
|---------------------| | |
| ... | | free chunk |
|---------------------| | |
| free chunk | | |
|---------------------| | |
| allocated chunk | | |
|---------------------| |---------------------|
| | | |
| heap info | ---> | heap info |
| | | |
|---------------------| |---------------------|
I was wondering if you can explain that why we keep the free heap in heap list.
And how can we free this kind of heap when our service is running.
Cheers,
Shuo
More information about the Libc-alpha
mailing list