From 78cc0adfc8190c744d8500a67f64426dcdf86a71 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Wed, 11 Jan 2017 15:02:34 +0800 Subject: [PATCH] os/bluestore: use Best-Effort policy when evicting onode from cache We want a precise control of cache usage, and BE can achieve this goal in a better way. Signed-off-by: xie xingguo --- src/common/config_opts.h | 1 + src/os/bluestore/BlueStore.cc | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 85121c1180e4..48354c2ea561 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -1045,6 +1045,7 @@ OPTION(bluestore_extent_map_shard_min_size, OPT_U32, 150) OPTION(bluestore_extent_map_shard_target_size_slop, OPT_DOUBLE, .2) OPTION(bluestore_extent_map_inline_shard_prealloc_size, OPT_U32, 256) OPTION(bluestore_cache_trim_interval, OPT_DOUBLE, .1) +OPTION(bluestore_cache_trim_max_skip_pinned, OPT_U32, 64) // skip this many onodes pinned in cache before we give up OPTION(bluestore_cache_type, OPT_STR, "2q") // lru, 2q OPTION(bluestore_2q_cache_kin_ratio, OPT_DOUBLE, .5) // kin page slot size / max page slot size OPTION(bluestore_2q_cache_kout_ratio, OPT_DOUBLE, .5) // number of kout page slot / total number of page slot diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 6816e5d718db..ff3600b6a851 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -642,13 +642,26 @@ void BlueStore::LRUCache::_trim(uint64_t onode_max, uint64_t buffer_max) auto p = onode_lru.end(); assert(p != onode_lru.begin()); --p; + int skipped = 0; + int max_skipped = g_conf->bluestore_cache_trim_max_skip_pinned; while (num > 0) { Onode *o = &*p; int refs = o->nref.load(); if (refs > 1) { dout(20) << __func__ << " " << o->oid << " has " << refs - << " refs; stopping with " << num << " left to trim" << dendl; - break; + << " refs, skipping" << dendl; + if (++skipped >= max_skipped) { + dout(20) << __func__ << " maximum skip pinned reached; stopping with " + << num << " left to trim" << dendl; + break; + } + + if (p == onode_lru.begin()) { + break; + } else { + p--; + continue; + } } dout(30) << __func__ << " rm " << o->oid << dendl; if (p != onode_lru.begin()) { @@ -895,13 +908,26 @@ void BlueStore::TwoQCache::_trim(uint64_t onode_max, uint64_t buffer_max) auto p = onode_lru.end(); assert(p != onode_lru.begin()); --p; + int skipped = 0; + int max_skipped = g_conf->bluestore_cache_trim_max_skip_pinned; while (num > 0) { Onode *o = &*p; int refs = o->nref.load(); if (refs > 1) { dout(20) << __func__ << " " << o->oid << " has " << refs - << " refs; stopping with " << num << " left to trim" << dendl; - break; + << " refs; skipping" << dendl; + if (++skipped >= max_skipped) { + dout(20) << __func__ << " maximum skip pinned reached; stopping with " + << num << " left to trim" << dendl; + break; + } + + if (p == onode_lru.begin()) { + break; + } else { + p--; + continue; + } } dout(30) << __func__ << " trim " << o->oid << dendl; if (p != onode_lru.begin()) { -- 2.47.3