diff options
Diffstat (limited to 'src/third_party/wiredtiger/src/include/cache.i')
-rw-r--r-- | src/third_party/wiredtiger/src/include/cache.i | 119 |
1 files changed, 84 insertions, 35 deletions
diff --git a/src/third_party/wiredtiger/src/include/cache.i b/src/third_party/wiredtiger/src/include/cache.i index 0c976800b38..31bae1ac679 100644 --- a/src/third_party/wiredtiger/src/include/cache.i +++ b/src/third_party/wiredtiger/src/include/cache.i @@ -91,6 +91,48 @@ __wt_cache_dirty_inuse(WT_CACHE *cache) } /* + * __wt_cache_status -- + * Return if the cache usage exceeds the eviction or dirty targets. + */ +static inline void +__wt_cache_status(WT_SESSION_IMPL *session, int *evictp, int *dirtyp) +{ + WT_CONNECTION_IMPL *conn; + WT_CACHE *cache; + uint64_t bytes_inuse, bytes_max, dirty_inuse; + + conn = S2C(session); + cache = conn->cache; + + /* + * There's an assumption "evict" overrides "dirty", that is, if eviction + * is required, we no longer care where we are with respect to the dirty + * target. + * + * Avoid division by zero if the cache size has not yet been set in a + * shared cache. + */ + bytes_max = conn->cache_size + 1; + if (evictp != NULL) { + bytes_inuse = __wt_cache_bytes_inuse(cache); + if (bytes_inuse > (cache->eviction_target * bytes_max) / 100) { + *evictp = 1; + return; + } + *evictp = 0; + } + if (dirtyp != NULL) { + dirty_inuse = __wt_cache_dirty_inuse(cache); + if (dirty_inuse > + (cache->eviction_dirty_target * bytes_max) / 100) { + *dirtyp = 1; + return; + } + *dirtyp = 0; + } +} + +/* * __wt_eviction_check -- * Wake the eviction server if necessary. */ @@ -108,50 +150,30 @@ __wt_eviction_check(WT_SESSION_IMPL *session, int *fullp, int wake) * If we're over the maximum cache, shut out reads (which include page * allocations) until we evict to back under the maximum cache. * Eviction will keep pushing out pages so we don't run on the edge all - * the time. Avoid division by zero if the cache size has not yet been - * in a shared cache. + * the time. + * + * Avoid division by zero if the cache size has not yet been set in a + * shared cache. */ bytes_inuse = __wt_cache_bytes_inuse(cache); - dirty_inuse = __wt_cache_dirty_inuse(cache); bytes_max = conn->cache_size + 1; - /* Calculate the cache full percentage. */ + /* Return the cache full percentage. */ *fullp = (int)((100 * bytes_inuse) / bytes_max); - - /* Wake eviction when we're over the trigger cache size. */ - if (wake && - (bytes_inuse > (cache->eviction_trigger * bytes_max) / 100 || - dirty_inuse > (cache->eviction_dirty_target * bytes_max) / 100)) - WT_RET(__wt_evict_server_wake(session)); - - return (0); -} - -/* - * __wt_session_can_wait -- - * Return if a session available for a potentially slow operation. - */ -static inline int -__wt_session_can_wait(WT_SESSION_IMPL *session) -{ - /* - * Return if a session available for a potentially slow operation; - * for example, used by the block manager in the case of flushing - * the system cache. - */ - if (!F_ISSET(session, WT_SESSION_CAN_WAIT)) + if (!wake) return (0); /* - * LSM sets the no-cache-check flag when holding the LSM tree lock, - * in that case, or when holding the schema lock, we don't want to - * highjack the thread for eviction. + * Wake eviction if we're over the trigger cache size or there are too + * many dirty pages. */ - if (F_ISSET(session, - WT_SESSION_NO_CACHE_CHECK | WT_SESSION_LOCKED_SCHEMA)) - return (0); - - return (1); + if (bytes_inuse <= (cache->eviction_trigger * bytes_max) / 100) { + dirty_inuse = __wt_cache_dirty_inuse(cache); + if (dirty_inuse <= + (cache->eviction_dirty_trigger * bytes_max) / 100) + return (0); + } + return (__wt_evict_server_wake(session)); } /* @@ -196,3 +218,30 @@ __wt_cache_full_check(WT_SESSION_IMPL *session) return (__wt_cache_wait(session, full)); } + +/* + * __wt_session_can_wait -- + * Return if a session available for a potentially slow operation. + */ +static inline int +__wt_session_can_wait(WT_SESSION_IMPL *session) +{ + /* + * Return if a session available for a potentially slow operation; + * for example, used by the block manager in the case of flushing + * the system cache. + */ + if (!F_ISSET(session, WT_SESSION_CAN_WAIT)) + return (0); + + /* + * LSM sets the no-cache-check flag when holding the LSM tree lock, + * in that case, or when holding the schema lock, we don't want to + * highjack the thread for eviction. + */ + if (F_ISSET(session, + WT_SESSION_NO_CACHE_CHECK | WT_SESSION_LOCKED_SCHEMA)) + return (0); + + return (1); +} |