Bug 49840 - apr_allocator_max_free_set is broken with most malloc() implementations
Summary: apr_allocator_max_free_set is broken with most malloc() implementations
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-29 03:55 UTC by Stefan Fritsch
Modified: 2010-08-29 04:27 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Fritsch 2010-08-29 03:55:23 UTC
Due to the way pools allocate and free memory from the allocator, the blocks that are allocated last (and therefore have the highest addresses) tend to be freed first. However, if max_free_index is set, the allocator will keep the blocks that have been freed first in the free list and return the blocks that have been freed last to libc with free(). This means that the memory blocks with the highest addresses tend to stick in the free list. Therefore libc malloc() implementations that use brk/sbrk can never return much memory to the OS, because there are always blocks at the top of the address space still in use.

An additional problem is that once a larger block has been put into the free list, it can be kept there basically forever if this block size is not used anymore. (The overwhelming majority of used blocks is 8k.) Therefore if such a block has a relatively high address, it will prevent libc's malloc from returning memory to the OS.


I haven't had a good idea yet how to solve this. One could use double linked lists for the free lists and always free() blocks from the back end of the list. But this would enlarge the overhead even in the case where max_free is set to unlimited.
Comment 1 William A. Rowe Jr. 2010-08-29 04:27:28 UTC
There are additional complications.

The complete fix involves addressing MaxFragmentation, but we are a far ways away from dealing with that problem set :(