Question about MADV_FREE range in tiny_free_no_lock.
Question about MADV_FREE range in tiny_free_no_lock.
- Subject: Question about MADV_FREE range in tiny_free_no_lock.
- From: cee1 <email@hidden>
- Date: Wed, 07 Jan 2015 22:16:57 +0800
Hi all,
http://www.opensource.apple.com/source/libmalloc/libmalloc-53.1.1/src/magazine_malloc.c,
in function tiny_free_no_lock():
"""
size_t free_header_size = sizeof(free_list_t) + sizeof(msize_t);
uintptr_t safe_ptr = (uintptr_t)ptr + free_header_size;
uintptr_t round_safe = round_page_quanta(safe_ptr);
// Calcuate the last page in the coalesced block that would be safe to
mark MADV_FREE
size_t free_tail_size = sizeof(msize_t);
uintptr_t safe_extent = (uintptr_t)ptr + TINY_BYTES_FOR_MSIZE(msize) -
free_tail_size;
uintptr_t trunc_extent = trunc_page_quanta(safe_extent);
// The newly freed block may complete a span of bytes that cover a
page. Mark it with MADV_FREE.
if (round_safe < trunc_extent) { // Coalesced area covers a page (perhaps many)
// Extend the freed block by the free region header and tail
sizes to include pages
// we may have coalesced that no longer host free region tails
and headers.
// This may extend over in-use ranges, but the MIN/MAX
clamping below will fix that up.
uintptr_t lo = trunc_page_quanta((uintptr_t)original_ptr -
free_tail_size);
uintptr_t hi = round_page_quanta((uintptr_t)original_ptr +
original_size + free_header_size);
uintptr_t free_lo = MAX(round_safe, lo);
uintptr_t free_hi = MIN(trunc_extent, hi);
"""
Here 'ptr' == previous_free_block_if_exists + 'original_ptr' +
next_free_block_if_exists, hence a possible bigger block. IMHO,
MADV_FREE pages within this block(except the header and tail) should
be ok, why we need to shrink the range with MAX and MIN? Also it
should always be lo >= round_safe, trunc_extent >= hi?
BTW, we release the lock while doing MADV_FREE:
"""
SZONE_MAGAZINE_PTR_UNLOCK(szone, tiny_mag_ptr);
madvise_free_range(szone, region, free_lo, free_hi, &szone->last_tiny_advise);
SZONE_MAGAZINE_PTR_LOCK(szone, tiny_mag_ptr);
"""
Does that mean the MADV_FREE operation will spend much time?
--
Regards,
- cee1
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden