From 6b578e7f252a25d39a0cd7e55beac1ec002b4243 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 12 Dec 2016 11:54:48 +0000 Subject: [PATCH] mds: release pool allocator memory after exceeding size limit Usually we like keeping the memory in our pools, but in circumstances where we have violated our self-imposed inode count cap, we should shrink our usage of system memory afterwards. Fixes: http://tracker.ceph.com/issues/18225 Signed-off-by: John Spray --- src/mds/MDCache.cc | 20 ++++++++++++++++++++ src/mds/MDCache.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index e30bd9af5c414..89c8068bcfa65 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -179,6 +179,7 @@ public: MDCache::MDCache(MDSRank *m) : mds(m), filer(m->objecter, m->finisher), + exceeded_size_limit(false), recovery_queue(m), stray_manager(m) { @@ -280,6 +281,10 @@ void MDCache::add_inode(CInode *in) if (in->is_base()) base_inodes.insert(in); } + + if (get_num_inodes() > g_conf->mds_cache_size * 1.5) { + exceeded_size_limit = true; + } } void MDCache::remove_inode(CInode *o) @@ -7378,6 +7383,21 @@ void MDCache::check_memory_usage() mds->server->recall_client_state(ratio); } } + + // If the cache size had exceeded its limit, but we're back in bounds + // now, free any unused pool memory so that our memory usage isn't + // permanently bloated. + if (exceeded_size_limit + && get_num_inodes() <= g_conf->mds_cache_size * 1.5) { + // Only do this once we are back in bounds: otherwise the releases would + // slow down whatever process caused us to exceed bounds to begin with + dout(2) << "check_memory_usage: releasing unused space from pool allocators" + << dendl; + CInode::pool.release_memory(); + CDir::pool.release_memory(); + CDentry::pool.release_memory(); + exceeded_size_limit = false; + } } diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index a31964846227d..9304f94df2a6d 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -139,6 +139,8 @@ class MDCache { Filer filer; + bool exceeded_size_limit; + public: void advance_stray() { stray_index = (stray_index+1)%NUM_STRAY; -- 2.39.5