mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 19:38:41 +03:00
put segment cache behind an option and disable by default
This commit is contained in:
parent
038e8fd7d6
commit
b86c851cca
3 changed files with 10 additions and 7 deletions
|
@ -228,6 +228,7 @@ typedef enum mi_option_e {
|
||||||
mi_option_eager_commit,
|
mi_option_eager_commit,
|
||||||
mi_option_eager_region_commit,
|
mi_option_eager_region_commit,
|
||||||
mi_option_large_os_pages, // implies eager commit
|
mi_option_large_os_pages, // implies eager commit
|
||||||
|
mi_option_segment_cache,
|
||||||
mi_option_page_reset,
|
mi_option_page_reset,
|
||||||
mi_option_cache_reset,
|
mi_option_cache_reset,
|
||||||
mi_option_reset_decommits,
|
mi_option_reset_decommits,
|
||||||
|
|
|
@ -65,6 +65,7 @@ static mi_option_desc_t options[_mi_option_last] =
|
||||||
{ 1, UNINIT, MI_OPTION(eager_region_commit) },
|
{ 1, UNINIT, MI_OPTION(eager_region_commit) },
|
||||||
#endif
|
#endif
|
||||||
{ 0, UNINIT, MI_OPTION(large_os_pages) }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
|
{ 0, UNINIT, MI_OPTION(large_os_pages) }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's
|
||||||
|
{ 0, UNINIT, MI_OPTION(segment_cache) }, // cache N segments per thread
|
||||||
{ 0, UNINIT, MI_OPTION(page_reset) },
|
{ 0, UNINIT, MI_OPTION(page_reset) },
|
||||||
{ 0, UNINIT, MI_OPTION(cache_reset) },
|
{ 0, UNINIT, MI_OPTION(cache_reset) },
|
||||||
{ 0, UNINIT, MI_OPTION(reset_decommits) } // note: cannot enable this if secure is on
|
{ 0, UNINIT, MI_OPTION(reset_decommits) } // note: cannot enable this if secure is on
|
||||||
|
|
|
@ -236,8 +236,6 @@ static void mi_segment_os_free(mi_segment_t* segment, size_t segment_size, mi_se
|
||||||
|
|
||||||
|
|
||||||
// The thread local segment cache is limited to be at most 1/8 of the peak size of segments in use,
|
// The thread local segment cache is limited to be at most 1/8 of the peak size of segments in use,
|
||||||
// and no more than 4.
|
|
||||||
#define MI_SEGMENT_CACHE_MAX (4)
|
|
||||||
#define MI_SEGMENT_CACHE_FRACTION (8)
|
#define MI_SEGMENT_CACHE_FRACTION (8)
|
||||||
|
|
||||||
// note: returned segment may be partially reset
|
// note: returned segment may be partially reset
|
||||||
|
@ -253,15 +251,18 @@ static mi_segment_t* mi_segment_cache_pop(size_t segment_size, mi_segments_tld_t
|
||||||
return segment;
|
return segment;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool mi_segment_cache_full(mi_segments_tld_t* tld) {
|
static bool mi_segment_cache_full(mi_segments_tld_t* tld)
|
||||||
if (tld->cache_count < MI_SEGMENT_CACHE_MAX
|
{
|
||||||
&& tld->cache_count < (1 + (tld->peak_count / MI_SEGMENT_CACHE_FRACTION))
|
if (tld->count == 1 && tld->cache_count==0) return false; // always cache at least the final segment of a thread
|
||||||
) { // always allow 1 element cache
|
size_t max_cache = mi_option_get(mi_option_segment_cache);
|
||||||
|
if (tld->cache_count < max_cache
|
||||||
|
&& tld->cache_count < (1 + (tld->peak_count / MI_SEGMENT_CACHE_FRACTION)) // at least allow a 1 element cache
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// take the opportunity to reduce the segment cache if it is too large (now)
|
// take the opportunity to reduce the segment cache if it is too large (now)
|
||||||
// TODO: this never happens as we check against peak usage, should we use current usage instead?
|
// TODO: this never happens as we check against peak usage, should we use current usage instead?
|
||||||
while (tld->cache_count > MI_SEGMENT_CACHE_MAX ) { //(1 + (tld->peak_count / MI_SEGMENT_CACHE_FRACTION))) {
|
while (tld->cache_count > max_cache) { //(1 + (tld->peak_count / MI_SEGMENT_CACHE_FRACTION))) {
|
||||||
mi_segment_t* segment = mi_segment_cache_pop(0,tld);
|
mi_segment_t* segment = mi_segment_cache_pop(0,tld);
|
||||||
mi_assert_internal(segment != NULL);
|
mi_assert_internal(segment != NULL);
|
||||||
if (segment != NULL) mi_segment_os_free(segment, segment->segment_size, tld);
|
if (segment != NULL) mi_segment_os_free(segment, segment->segment_size, tld);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue