public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* malloc: unused heap is still kept in heap list
@ 2021-01-25 14:15 Shuo Wang
  0 siblings, 0 replies; only message in thread
From: Shuo Wang @ 2021-01-25 14:15 UTC (permalink / raw)
  To: carlos, siddhesh, dj, libc-alpha; +Cc: hushiyuan, liqingqing3, tangqingmei

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-25 14:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 14:15 malloc: unused heap is still kept in heap list Shuo Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).