diff options
author | Jason Evans <je@fb.com> | 2011-03-21 07:18:17 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2011-03-21 07:18:17 (GMT) |
commit | 1dcb4f86b23a5760f5a717ace716360b63b33fad (patch) | |
tree | 8bce971a06b3d2a9325e04f748d5dc0591ba5a2d /jemalloc/include | |
parent | 893a0ed7c8c11962524ba6f2adeb304d038be2a9 (diff) | |
download | jemalloc-1dcb4f86b23a5760f5a717ace716360b63b33fad.zip jemalloc-1dcb4f86b23a5760f5a717ace716360b63b33fad.tar.gz jemalloc-1dcb4f86b23a5760f5a717ace716360b63b33fad.tar.bz2 |
Dynamically adjust tcache fill count.
Dynamically adjust tcache fill count (number of objects allocated per
tcache refill) such that if GC has to flush inactive objects, the fill
count gradually decreases. Conversely, if refills occur while the fill
count is depressed, the fill count gradually increases back to its
maximum value.
Diffstat (limited to 'jemalloc/include')
-rw-r--r-- | jemalloc/include/jemalloc/internal/tcache.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/jemalloc/include/jemalloc/internal/tcache.h b/jemalloc/include/jemalloc/internal/tcache.h index 5434d32..da3c68c 100644 --- a/jemalloc/include/jemalloc/internal/tcache.h +++ b/jemalloc/include/jemalloc/internal/tcache.h @@ -45,7 +45,8 @@ struct tcache_bin_s { # ifdef JEMALLOC_STATS tcache_bin_stats_t tstats; # endif - unsigned low_water; /* Min # cached since last GC. */ + int low_water; /* Min # cached since last GC. */ + unsigned lg_fill_div; /* Fill (ncached_max >> lg_fill_div). */ unsigned ncached; /* # of cached objects. */ void **avail; /* Stack of available objects. */ }; @@ -184,6 +185,7 @@ tcache_event(tcache_t *tcache) if (tcache->ev_cnt == tcache_gc_incr) { size_t binind = tcache->next_gc_bin; tcache_bin_t *tbin = &tcache->tbins[binind]; + tcache_bin_info_t *tbin_info = &tcache_bin_info[binind]; if (tbin->low_water > 0) { /* @@ -207,6 +209,20 @@ tcache_event(tcache_t *tcache) #endif ); } + /* + * Reduce fill count by 2X. Limit lg_fill_div such that + * the fill count is always at least 1. + */ + if ((tbin_info->ncached_max >> (tbin->lg_fill_div+1)) + >= 1) + tbin->lg_fill_div++; + } else if (tbin->low_water < 0) { + /* + * Increase fill count by 2X. Make sure lg_fill_div + * stays greater than 0. + */ + if (tbin->lg_fill_div > 1) + tbin->lg_fill_div--; } tbin->low_water = tbin->ncached; @@ -222,10 +238,12 @@ tcache_alloc_easy(tcache_bin_t *tbin) { void *ret; - if (tbin->ncached == 0) + if (tbin->ncached == 0) { + tbin->low_water = -1; return (NULL); + } tbin->ncached--; - if (tbin->ncached < tbin->low_water) + if ((int)tbin->ncached < tbin->low_water) tbin->low_water = tbin->ncached; ret = tbin->avail[tbin->ncached]; return (ret); |