Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 3 Apr 2014 00:43:23 -0400
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: malloc & uncommitting memory

On Wed, Apr 02, 2014 at 05:08:05PM -0400, Rich Felker wrote:
> As long as thresholds are chosen right, I don't think this approach
> would be costly from a performance standpoint. But it might have
> consequences for fragmentation. So I'd like to discuss it further, see
> what ideas emerge, and whether it looks reasonable before trying to
> implement anything.

Basically, the way fragmentation can result from having "frozen"
chunks is when small chunks adjacent to them are freed: these free
chunks are unable to be merged with the frozen chunk, so they get
reused for small allocations despite being adjacent to a large free
(albeit frozen) region.

I see several possible ways to reduce or avoid this:

1. Always leave large padding (large enough to stay in bin-63) on both
   sides of the frozen chunk when freezing. This would force adjacent
   freed chunks to get merged into a bin-63 chunk, preventing them
   from getting used for small allocations unless nothing smaller were
   available. However, they could still get used and gradually
   depleted.

2. When a chunk is freed, check if it's a neighbor to a frozen chunk,
   and if so, put it at the end of its bin rather than the beginning,
   so that other free chunks of the appropriate size get used first.
   However this wouldn't help when it's the only chunk of its size but
   another slightly-larger chunk would be a better candidate to split.

3. Allow merging directly into frozen chunks, the same way merging
   into free chunks is done now, with logic to expand the region
   that's PROT_NONE similar to the current logic for expanding the
   MADV_DONTNEED region.

Of these, option 3 looks the most promising.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.