From 86afa69cd1a01e16eadaf71a10657e4818613a9c Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Wed, 7 Feb 2018 23:14:38 -0500 Subject: [PATCH] cache: release lock before clearing Clearing the FD cache could trigger a lot of inode evicts in the kernel, which will block the cache entry destructors called by map::clear(). This prevents any cache lookups or new file opens while it happens. Move the map to an auto variable and destroy it after releasing the mutex lock. This probably has the same net result (all the bees threads will be blocked in the kernel instead of on a bees mutex), but at least the problem is outside of userspace now. Signed-off-by: Zygo Blaxell --- include/crucible/cache.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/crucible/cache.h b/include/crucible/cache.h index beff086..7eec776 100644 --- a/include/crucible/cache.h +++ b/include/crucible/cache.h @@ -122,7 +122,7 @@ namespace crucible { // Splice new node into list Value *last_bp = m_last->bp; THROW_CHECK0(runtime_error, last_bp); - // New elemnt points to both ends of list + // New element points to both ends of list vp->fp = m_last; vp->bp = last_bp; // Insert vp as fp from the end of the list @@ -158,8 +158,10 @@ namespace crucible { void LRUCache::clear() { + // Move the map onto the stack, then destroy it after we've released the lock. + decltype(m_map) new_map; unique_lock lock(m_mutex); - m_map.clear(); + m_map.swap(new_map); m_last = nullptr; }