]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mempool: move to libcommon
authorSage Weil <sage@redhat.com>
Tue, 8 Nov 2016 21:37:25 +0000 (16:37 -0500)
committerSage Weil <sage@redhat.com>
Fri, 11 Nov 2016 19:59:53 +0000 (14:59 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/CMakeLists.txt
src/common/mempool.cc [new file with mode: 0644]
src/global/CMakeLists.txt
src/global/mempool.cc [deleted file]

index 6befb3efe96d94a2b61d95d597ed4cd5e30d91ea..c46cab9ab62793d4e46ed52d9f6502b59a50f29a 100644 (file)
@@ -387,6 +387,7 @@ set(libcommon_files
   common/io_priority.cc
   common/Clock.cc
   common/ceph_time.cc
+  common/mempool.cc
   common/Throttle.cc
   common/Timer.cc
   common/Finisher.cc
diff --git a/src/common/mempool.cc b/src/common/mempool.cc
new file mode 100644 (file)
index 0000000..33ea7be
--- /dev/null
@@ -0,0 +1,112 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 Allen Samuels <allen.samuels@sandisk.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "include/mempool.h"
+#include "include/demangle.h"
+
+
+// default to debug_mode off
+bool mempool::debug_mode = false;
+
+// --------------------------------------------------------------
+
+mempool::pool_t& mempool::get_pool(mempool::pool_index_t ix)
+{
+  // We rely on this array being initialized before any invocation of
+  // this function, even if it is called by ctors in other compilation
+  // units that are being initialized before this compilation unit.
+  static mempool::pool_t table[num_pools];
+  return table[ix];
+}
+
+const char *mempool::get_pool_name(mempool::pool_index_t ix) {
+#define P(x) #x,
+  static const char *names[num_pools] = {
+    DEFINE_MEMORY_POOLS_HELPER(P)
+  };
+#undef P
+  return names[ix];
+}
+
+void mempool::dump(ceph::Formatter *f, size_t skip)
+{
+  for (size_t i = skip; i < num_pools; ++i) {
+    const pool_t &pool = mempool::get_pool((pool_index_t)i);
+    f->open_object_section(get_pool_name((pool_index_t)i));
+    pool.dump(f);
+    f->close_section();
+  }
+}
+
+void mempool::set_debug_mode(bool d)
+{
+  debug_mode = d;
+}
+
+// --------------------------------------------------------------
+// pool_t
+
+size_t mempool::pool_t::allocated_bytes() const
+{
+  ssize_t result = 0;
+  for (size_t i = 0; i < num_shards; ++i) {
+    result += shard[i].bytes;
+  }
+  assert(result >= 0);
+  return (size_t) result;
+}
+
+size_t mempool::pool_t::allocated_items() const
+{
+  ssize_t result = 0;
+  for (size_t i = 0; i < num_shards; ++i) {
+    result += shard[i].items;
+  }
+  assert(result >= 0);
+  return (size_t) result;
+}
+
+void mempool::pool_t::get_stats(
+  stats_t *total,
+  std::map<std::string, stats_t> *by_type) const
+{
+  for (size_t i = 0; i < num_shards; ++i) {
+    total->items += shard[i].items;
+    total->bytes += shard[i].bytes;
+  }
+  if (debug_mode) {
+    std::unique_lock<std::mutex> shard_lock(lock);
+    for (auto &p : type_map) {
+      std::string n = ceph_demangle(p.second.type_name);
+      stats_t &s = (*by_type)[n];
+      s.bytes = p.second.items * p.second.item_size;
+      s.items = p.second.items;
+    }
+  }
+}
+
+void mempool::pool_t::dump(ceph::Formatter *f) const
+{
+  stats_t total;
+  std::map<std::string, stats_t> by_type;
+  get_stats(&total, &by_type);
+  f->dump_object("total", total);
+  if (!by_type.empty()) {
+    for (auto &i : by_type) {
+      f->open_object_section(i.first.c_str());
+      i.second.dump(f);
+      f->close_section();
+    }
+  }
+}
index 4b65e391ee65272782713c80f261d18810e88ae6..90bb2a5e112d0e2e77d76c7b4b8072fd7a9ab1dd 100644 (file)
@@ -1,8 +1,7 @@
 set(libglobal_srcs
   global_init.cc
   pidfile.cc
-  signal_handler.cc
-  mempool.cc)
+  signal_handler.cc)
 set(global_common_files
   global_context.cc)
 add_library(global_common_objs OBJECT ${global_common_files})
diff --git a/src/global/mempool.cc b/src/global/mempool.cc
deleted file mode 100644 (file)
index 33ea7be..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2016 Allen Samuels <allen.samuels@sandisk.com>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-
-#include "include/mempool.h"
-#include "include/demangle.h"
-
-
-// default to debug_mode off
-bool mempool::debug_mode = false;
-
-// --------------------------------------------------------------
-
-mempool::pool_t& mempool::get_pool(mempool::pool_index_t ix)
-{
-  // We rely on this array being initialized before any invocation of
-  // this function, even if it is called by ctors in other compilation
-  // units that are being initialized before this compilation unit.
-  static mempool::pool_t table[num_pools];
-  return table[ix];
-}
-
-const char *mempool::get_pool_name(mempool::pool_index_t ix) {
-#define P(x) #x,
-  static const char *names[num_pools] = {
-    DEFINE_MEMORY_POOLS_HELPER(P)
-  };
-#undef P
-  return names[ix];
-}
-
-void mempool::dump(ceph::Formatter *f, size_t skip)
-{
-  for (size_t i = skip; i < num_pools; ++i) {
-    const pool_t &pool = mempool::get_pool((pool_index_t)i);
-    f->open_object_section(get_pool_name((pool_index_t)i));
-    pool.dump(f);
-    f->close_section();
-  }
-}
-
-void mempool::set_debug_mode(bool d)
-{
-  debug_mode = d;
-}
-
-// --------------------------------------------------------------
-// pool_t
-
-size_t mempool::pool_t::allocated_bytes() const
-{
-  ssize_t result = 0;
-  for (size_t i = 0; i < num_shards; ++i) {
-    result += shard[i].bytes;
-  }
-  assert(result >= 0);
-  return (size_t) result;
-}
-
-size_t mempool::pool_t::allocated_items() const
-{
-  ssize_t result = 0;
-  for (size_t i = 0; i < num_shards; ++i) {
-    result += shard[i].items;
-  }
-  assert(result >= 0);
-  return (size_t) result;
-}
-
-void mempool::pool_t::get_stats(
-  stats_t *total,
-  std::map<std::string, stats_t> *by_type) const
-{
-  for (size_t i = 0; i < num_shards; ++i) {
-    total->items += shard[i].items;
-    total->bytes += shard[i].bytes;
-  }
-  if (debug_mode) {
-    std::unique_lock<std::mutex> shard_lock(lock);
-    for (auto &p : type_map) {
-      std::string n = ceph_demangle(p.second.type_name);
-      stats_t &s = (*by_type)[n];
-      s.bytes = p.second.items * p.second.item_size;
-      s.items = p.second.items;
-    }
-  }
-}
-
-void mempool::pool_t::dump(ceph::Formatter *f) const
-{
-  stats_t total;
-  std::map<std::string, stats_t> by_type;
-  get_stats(&total, &by_type);
-  f->dump_object("total", total);
-  if (!by_type.empty()) {
-    for (auto &i : by_type) {
-      f->open_object_section(i.first.c_str());
-      i.second.dump(f);
-      f->close_section();
-    }
-  }
-}