From a61a67961a9018501a009d8588002c8b0a8de631 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 29 May 2020 21:33:55 -0700 Subject: [PATCH] ircd::db: Lock database cache extents in RAM if possible. (closes #144) --- ircd/db.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++-- ircd/db_database.h | 2 ++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/ircd/db.cc b/ircd/db.cc index a9936c117..35b987986 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -8,6 +8,7 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. +#include = size); + database::allocator::mlock_current -= size; + } + #endif + + return ret; } #endif @@ -3666,6 +3705,15 @@ noexcept }; #endif + #if defined(HAVE_MLOCK2) + if(database::allocator::mlock_current) + { + syscall(::munlock, ptr, size); + assert(database::allocator::mlock_current >= size); + database::allocator::mlock_current -= size; + } + #endif + return their_hooks.destroy(hooks, ptr, size, committed, arena_ind); } #endif diff --git a/ircd/db_database.h b/ircd/db_database.h index 5dbf38c3e..929f60ba2 100644 --- a/ircd/db_database.h +++ b/ircd/db_database.h @@ -296,6 +296,8 @@ struct ircd::db::database::allocator final :rocksdb::MemoryAllocator { static const size_t ALIGN_DEFAULT; + static const size_t mlock_limit; + static size_t mlock_current; static unsigned cache_arena; database *d {nullptr};