diff options
author | Alex Gorrod <alexg@wiredtiger.com> | 2014-09-09 17:24:20 +1000 |
---|---|---|
committer | Alex Gorrod <alexg@wiredtiger.com> | 2014-09-09 17:24:20 +1000 |
commit | 9f396e9572ce0356505eee6755c11b62f8006a13 (patch) | |
tree | a912753b6b18e30d6a3a6eddbabe3e65cfed0bb8 /src/conn/conn_cache_pool.c | |
parent | 6f440bc359211403acbb4321316db2e987c6a6aa (diff) | |
download | mongo-9f396e9572ce0356505eee6755c11b62f8006a13.tar.gz |
Fix a bug in the shared cache implementation.
We could decrement an unsigned number into negative. Also add
a test case and some better documentation to the source code.
Diffstat (limited to 'src/conn/conn_cache_pool.c')
-rw-r--r-- | src/conn/conn_cache_pool.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/conn/conn_cache_pool.c b/src/conn/conn_cache_pool.c index ab7e2cc48ee..9b540c147d4 100644 --- a/src/conn/conn_cache_pool.c +++ b/src/conn/conn_cache_pool.c @@ -488,26 +488,46 @@ __cache_pool_adjust(WT_SESSION_IMPL *session, if (cache->cp_skip_count > 0 && --cache->cp_skip_count > 0) continue; /* - * TODO: Use __wt_cache_bytes_inuse instead of eviction_target - * which doesn't do the right thing at the moment. + * If the entry is currently allocated less than the reserved + * size, increase it's allocation. This should only happen if: + * - It's the first time we've seen this member + * - The reserved size has been adjusted */ if (entry->cache_size < reserved) { grew = 1; adjusted = reserved - entry->cache_size; + /* + * Conditions for reducing the amount of resources for an + * entry: + * - If we are forcing and this entry has more than the + * minimum amount of space in use. + * - If the read pressure in this entry is below the + * threshold, other entries need more cache, the entry has + * more than the minimum space and there is no available + * space in the pool. + */ } else if ((force && entry->cache_size > reserved) || (read_pressure < WT_CACHE_POOL_REDUCE_THRESHOLD && highest > 1 && entry->cache_size > reserved && cp->currently_used >= cp->size)) { + grew = 0; /* - * If a connection isn't actively using it's assigned - * cache and is assigned a reasonable amount - reduce - * it. + * Shrink by a chunk size if that doesn't drop us + * below the reserved size. */ - grew = 0; - if (entry->cache_size - cp->chunk > reserved) + if (entry->cache_size > cp->chunk + reserved) adjusted = cp->chunk; else adjusted = entry->cache_size - reserved; + /* + * Conditions for increasing the amount of resources for an + * entry: + * - There was some activity across the pool + * - This entry is using less than the entire cache pool + * - The connection is using enough cache to require eviction + * - There is space available in the pool + * - Additional cache would benefit the connection + */ } else if (highest > 1 && entry->cache_size < cp->size && cache->bytes_inmem >= @@ -527,6 +547,9 @@ __cache_pool_adjust(WT_SESSION_IMPL *session, } else { cache->cp_skip_count = WT_CACHE_POOL_REDUCE_SKIPS; + WT_ASSERT(session, + entry->cache_size >= adjusted && + cp->currently_used >= adjusted); entry->cache_size -= adjusted; cp->currently_used -= adjusted; } |