diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2015-02-18 12:53:41 +1100 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2015-02-18 12:53:41 +1100 |
commit | bf3ee2cd064b46cf0175d75950c825aa1f42c694 (patch) | |
tree | fcd0b362363074fa91fcf1ac823ed9dc42d440fd /src | |
parent | 3037fc93a25f8191fc2acbb0407ef2615cfbcb08 (diff) | |
download | mongo-bf3ee2cd064b46cf0175d75950c825aa1f42c694.tar.gz |
Flip cache overhead to apply to the allocated bytes rather than the total size. Include the overhead in stats so that tools (e.g., mongostat) report accurate cache full and dirty percentages. This also makes eviction triggers and targets meaningful: with the default trigger of 95% and overhead 8%, eviction was previously never triggered until the cache was completely full.
Diffstat (limited to 'src')
-rw-r--r-- | src/conn/conn_cache.c | 9 | ||||
-rw-r--r-- | src/evict/evict_lru.c | 16 | ||||
-rw-r--r-- | src/include/cache.h | 2 | ||||
-rw-r--r-- | src/include/cache.i | 33 | ||||
-rw-r--r-- | src/include/connection.h | 1 |
5 files changed, 39 insertions, 22 deletions
diff --git a/src/conn/conn_cache.c b/src/conn/conn_cache.c index b278d7a6b8a..c513d46137c 100644 --- a/src/conn/conn_cache.c +++ b/src/conn/conn_cache.c @@ -29,8 +29,6 @@ __wt_cache_config(WT_SESSION_IMPL *session, const char *cfg[]) if (!F_ISSET(conn, WT_CONN_CACHE_POOL)) { WT_RET(__wt_config_gets(session, cfg, "cache_size", &cval)); conn->cache_size = (uint64_t)cval.val; - WT_RET(__wt_config_gets(session, cfg, "cache_overhead", &cval)); - conn->cache_overhead = (int)cval.val; } else { WT_RET(__wt_config_gets( session, cfg, "shared_cache.reserve", &cval)); @@ -40,6 +38,9 @@ __wt_cache_config(WT_SESSION_IMPL *session, const char *cfg[]) cache->cp_reserved = (uint64_t)cval.val; } + WT_RET(__wt_config_gets(session, cfg, "cache_overhead", &cval)); + cache->overhead_pct = (u_int)cval.val; + WT_RET(__wt_config_gets(session, cfg, "eviction_target", &cval)); cache->eviction_target = (u_int)cval.val; @@ -145,9 +146,9 @@ __wt_cache_stats_update(WT_SESSION_IMPL *session) WT_STAT_SET(stats, cache_bytes_max, conn->cache_size); WT_STAT_SET(stats, cache_bytes_inuse, __wt_cache_bytes_inuse(cache)); - WT_STAT_SET(stats, cache_overhead, conn->cache_overhead); + WT_STAT_SET(stats, cache_overhead, cache->overhead_pct); WT_STAT_SET(stats, cache_pages_inuse, __wt_cache_pages_inuse(cache)); - WT_STAT_SET(stats, cache_bytes_dirty, cache->bytes_dirty); + WT_STAT_SET(stats, cache_bytes_dirty, __wt_cache_dirty_inuse(cache)); WT_STAT_SET(stats, cache_eviction_maximum_page_size, cache->evict_max_page_size); WT_STAT_SET(stats, cache_pages_dirty, cache->pages_dirty); diff --git a/src/evict/evict_lru.c b/src/evict/evict_lru.c index c6b962f9f5d..06ace2d4e7d 100644 --- a/src/evict/evict_lru.c +++ b/src/evict/evict_lru.c @@ -398,7 +398,7 @@ __evict_has_work(WT_SESSION_IMPL *session, uint32_t *flagsp) * target or the dirty target. */ bytes_inuse = __wt_cache_bytes_inuse(cache); - dirty_inuse = cache->bytes_dirty; + dirty_inuse = __wt_cache_dirty_inuse(cache); bytes_max = conn->cache_size; /* Check to see if the eviction server should run. */ @@ -435,9 +435,9 @@ __evict_pass(WT_SESSION_IMPL *session) WT_CACHE *cache; WT_CONNECTION_IMPL *conn; WT_EVICT_WORKER *worker; - int loop; + uint64_t pages_evicted; uint32_t flags; - uint64_t bytes_inuse, dirty_target_size, pages_evicted, target_size; + int loop; conn = S2C(session); cache = conn->cache; @@ -469,13 +469,7 @@ __evict_pass(WT_SESSION_IMPL *session) * Start a worker if we have capacity and we haven't reached * the eviction targets. */ - bytes_inuse = __wt_cache_bytes_inuse(cache); - target_size = (conn->cache_size * cache->eviction_target) / 100; - dirty_target_size = - (conn->cache_size * cache->eviction_dirty_target) / 100; - if ((bytes_inuse > target_size || - cache->bytes_dirty > dirty_target_size) && - conn->evict_workers < conn->evict_workers_max) { + if (LF_ISSET(WT_EVICT_PASS_ALL | WT_EVICT_PASS_DIRTY)) { WT_RET(__wt_verbose(session, WT_VERB_EVICTSERVER, "Starting evict worker: %"PRIu32"\n", conn->evict_workers)); @@ -488,7 +482,7 @@ __evict_pass(WT_SESSION_IMPL *session) WT_RET(__wt_verbose(session, WT_VERB_EVICTSERVER, "Eviction pass with: Max: %" PRIu64 " In use: %" PRIu64 " Dirty: %" PRIu64, - conn->cache_size, bytes_inuse, cache->bytes_dirty)); + conn->cache_size, cache->bytes_inmem, cache->bytes_dirty)); WT_RET(__evict_lru_walk(session, flags)); WT_RET(__evict_server_work(session)); diff --git a/src/include/cache.h b/src/include/cache.h index de6faad608a..5006c828d7c 100644 --- a/src/include/cache.h +++ b/src/include/cache.h @@ -82,6 +82,8 @@ struct __wt_cache { u_int eviction_target; /* Percent to end eviction */ u_int eviction_dirty_target; /* Percent to allow dirty */ + u_int overhead_pct; /* Cache percent adjustment */ + /* * LRU eviction list information. */ diff --git a/src/include/cache.i b/src/include/cache.i index 4bceb5c0d6c..f952f1bf698 100644 --- a/src/include/cache.i +++ b/src/include/cache.i @@ -62,7 +62,32 @@ __wt_cache_pages_inuse(WT_CACHE *cache) static inline uint64_t __wt_cache_bytes_inuse(WT_CACHE *cache) { - return (cache->bytes_inmem); + uint64_t bytes_inuse; + + /* Adjust the cache size to take allocation overhead into account. */ + bytes_inuse = cache->bytes_inmem; + if (cache->overhead_pct != 0) + bytes_inuse += + (bytes_inuse * (uint64_t)cache->overhead_pct) / 100; + + return (bytes_inuse); +} + +/* + * __wt_cache_dirty_inuse -- + * Return the number of dirty bytes in use. + */ +static inline uint64_t +__wt_cache_dirty_inuse(WT_CACHE *cache) +{ + uint64_t dirty_inuse; + + dirty_inuse = cache->bytes_dirty; + if (cache->overhead_pct != 0) + dirty_inuse += + (dirty_inuse * (uint64_t)cache->overhead_pct) / 100; + + return (dirty_inuse); } /* @@ -87,13 +112,9 @@ __wt_eviction_check(WT_SESSION_IMPL *session, int *fullp, int wake) * in a shared cache. */ bytes_inuse = __wt_cache_bytes_inuse(cache); - dirty_inuse = cache->bytes_dirty; + dirty_inuse = __wt_cache_dirty_inuse(cache); bytes_max = conn->cache_size + 1; - /* Adjust the cache size to take allocation overhead into account. */ - if (conn->cache_overhead != 0) - bytes_max -= (bytes_max * (uint64_t)conn->cache_overhead) / 100; - /* Calculate the cache full percentage. */ *fullp = (int)((100 * bytes_inuse) / bytes_max); diff --git a/src/include/connection.h b/src/include/connection.h index ff5e401fadd..90151d917ec 100644 --- a/src/include/connection.h +++ b/src/include/connection.h @@ -227,7 +227,6 @@ struct __wt_connection_impl { uint32_t hazard_max; /* Hazard array size */ WT_CACHE *cache; /* Page cache */ - int cache_overhead; /* Cache percent adjustment */ uint64_t cache_size; /* Configured cache size */ WT_TXN_GLOBAL txn_global; /* Global transaction state */ |