You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2020/03/13 06:50:57 UTC

[kudu] branch master updated: KUDU-3063: Set a ratio as multiplication factor for memkind_malloc_usable_size

This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new de2bf21  KUDU-3063: Set a ratio as multiplication factor for memkind_malloc_usable_size
de2bf21 is described below

commit de2bf2177926c66001853d3de555a297bafa2bb9
Author: yeyuqiang <yu...@intel.com>
AuthorDate: Fri Feb 28 10:23:00 2020 +0800

    KUDU-3063: Set a ratio as multiplication factor for memkind_malloc_usable_size
    
    Due to memkind fragmentation issues, evictions will not happen in
    NVM lru cache. The charge of items in nvm cache calculated by
    memkind_malloc_usable_size will never exceed the capacity.
    The fragmentation can be estimated by
    https://github.com/memkind/memkind/blob/master/test/fragmentation_benchmark_pmem.cpp
    
    Change-Id: Iceb1931f5addbf76774854ca1613b6a085b577e3
    Reviewed-on: http://gerrit.cloudera.org:8080/15313
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <as...@cloudera.com>
---
 src/kudu/util/nvm_cache.cc | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/kudu/util/nvm_cache.cc b/src/kudu/util/nvm_cache.cc
index c4aa09b..e4f0508 100644
--- a/src/kudu/util/nvm_cache.cc
+++ b/src/kudu/util/nvm_cache.cc
@@ -70,11 +70,34 @@ DEFINE_bool(nvm_cache_simulate_allocation_failure, false,
             "for testing.");
 TAG_FLAG(nvm_cache_simulate_allocation_failure, unsafe);
 
+DEFINE_double(nvm_cache_usage_ratio, 1.25,
+             "A ratio to set the usage of nvm cache. The charge of an item in the nvm "
+             "cache is equal to the results of memkind_malloc_usable_size multiplied by "
+             "the ratio.");
+TAG_FLAG(nvm_cache_usage_ratio, advanced);
+
 using std::string;
 using std::unique_ptr;
 using std::vector;
 using strings::Substitute;
 
+static bool ValidateNVMCacheUsageRatio(const char* flagname, double value) {
+  if (value < 1.0) {
+    LOG(ERROR) << Substitute("$0 must be greater than or equal to 1.0, value $1 is invalid.",
+                             flagname, value);
+    return false;
+  }
+  if (value < 1.25) {
+    LOG(WARNING) << Substitute("The value of $0 is $1, it is less than recommended "
+                               "value (1.25). Due to memkind fragmentation, an improper "
+                               "ratio will cause allocation failures while capacity-based "
+                               "evictions are not triggered. Raise --nvm_cache_usage_ratio.",
+                               flagname, value);
+  }
+  return true;
+}
+DEFINE_validator(nvm_cache_usage_ratio, &ValidateNVMCacheUsageRatio);
+
 namespace kudu {
 
 namespace {
@@ -657,8 +680,11 @@ class ShardedLRUCache : public Cache {
         handle->kv_data = &buf[sizeof(LRUHandle)];
         handle->val_length = val_len;
         handle->key_length = key_len;
+        // Multiply the results of memkind_malloc_usable_size by a ratio
+        // due to the fragmentation is not counted in.
         handle->charge = (charge == kAutomaticCharge) ?
-            CALL_MEMKIND(memkind_malloc_usable_size, vmp_, buf) : charge;
+            CALL_MEMKIND(memkind_malloc_usable_size, vmp_, buf) * FLAGS_nvm_cache_usage_ratio :
+            charge;
         handle->hash = HashSlice(key);
         memcpy(handle->kv_data, key.data(), key.size());
         return ph;
@@ -699,6 +725,9 @@ Cache* NewCache<Cache::EvictionPolicy::LRU,
     << "configured capacity " << capacity << " bytes is less than "
     << "the minimum capacity for an NVM cache: " << MEMKIND_PMEM_MIN_SIZE;
 
+  LOG(INFO) << 1 / FLAGS_nvm_cache_usage_ratio * 100 << "% capacity "
+            << "from nvm block cache is available due to memkind fragmentation.";
+
   memkind* vmp;
   int err = CALL_MEMKIND(memkind_create_pmem, FLAGS_nvm_cache_path.c_str(), capacity, &vmp);
   // If we cannot create the cache pool we should not retry.