From 37720061ff91684371851008a6b8c19740d0d85c Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 20 Jan 2016 14:54:51 -0800 Subject: [PATCH] osd/: make heap properties settable via admin socket Signed-off-by: Samuel Just --- src/osd/OSD.cc | 33 ++++++++++++++++++++++++++ src/perfglue/disabled_heap_profiler.cc | 5 ++++ src/perfglue/heap_profiler.cc | 8 +++++++ src/perfglue/heap_profiler.h | 2 ++ 4 files changed, 48 insertions(+) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 23328b5746a6f..1685839aa18da 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1781,6 +1781,30 @@ bool OSD::asok_command(string command, cmdmap_t& cmdmap, string format, f->close_section(); } else if (command == "get_latest_osdmap") { get_latest_osdmap(); + } else if (command == "set_heap_property") { + string property; + int64_t value = 0; + string error; + bool success = false; + if (!cmd_getval(cct, cmdmap, "property", property)) { + error = "unable to get property"; + success = false; + } else if (!cmd_getval(cct, cmdmap, "value", value)) { + error = "unable to get value"; + success = false; + } else if (value < 0) { + error = "negative value not allowed"; + success = false; + } else if (!ceph_heap_set_numeric_property(property.c_str(), (size_t)value)) { + error = "invalid property"; + success = false; + } else { + success = true; + } + f->open_object_section("result"); + f->dump_string("error", error); + f->dump_bool("success", success); + f->close_section(); } else if (command == "get_heap_property") { string property; size_t value = 0; @@ -2089,6 +2113,14 @@ void OSD::final_init() "the mon"); assert(r == 0); + r = admin_socket->register_command("set_heap_property", + "set_heap_property " \ + "name=property,type=CephString " \ + "name=value,type=CephInt", + asok_hook, + "update malloc extension heap property"); + assert(r == 0); + r = admin_socket->register_command("get_heap_property", "get_heap_property " \ "name=property,type=CephString", @@ -2408,6 +2440,7 @@ int OSD::shutdown() cct->get_admin_socket()->unregister_command("dump_watchers"); cct->get_admin_socket()->unregister_command("dump_reservations"); cct->get_admin_socket()->unregister_command("get_latest_osdmap"); + cct->get_admin_socket()->unregister_command("set_heap_property"); cct->get_admin_socket()->unregister_command("get_heap_property"); delete asok_hook; asok_hook = NULL; diff --git a/src/perfglue/disabled_heap_profiler.cc b/src/perfglue/disabled_heap_profiler.cc index 64a2939098a18..238ab4ad83c73 100644 --- a/src/perfglue/disabled_heap_profiler.cc +++ b/src/perfglue/disabled_heap_profiler.cc @@ -34,5 +34,10 @@ bool ceph_heap_get_numeric_property(const char *property, size_t *value) return false; } +bool ceph_heap_set_numeric_property(const char *property, size_t value) +{ + return false; +} + void ceph_heap_profiler_handle_command(const std::vector& cmd, ostream& out) { return; } diff --git a/src/perfglue/heap_profiler.cc b/src/perfglue/heap_profiler.cc index a2eeaf1195aa1..685b4be573809 100644 --- a/src/perfglue/heap_profiler.cc +++ b/src/perfglue/heap_profiler.cc @@ -67,6 +67,14 @@ bool ceph_heap_get_numeric_property( value); } +bool ceph_heap_set_numeric_property( + const char *property, size_t value) +{ + return MallocExtension::instance()->SetNumericProperty( + property, + value); +} + bool ceph_heap_profiler_running() { #ifdef HAVE_LIBTCMALLOC diff --git a/src/perfglue/heap_profiler.h b/src/perfglue/heap_profiler.h index 36bc8c18e814a..75fba8ac33820 100644 --- a/src/perfglue/heap_profiler.h +++ b/src/perfglue/heap_profiler.h @@ -45,6 +45,8 @@ void ceph_heap_profiler_dump(const char *reason); bool ceph_heap_get_numeric_property(const char *property, size_t *value); +bool ceph_heap_set_numeric_property(const char *property, size_t value); + void ceph_heap_profiler_handle_command(const std::vector &cmd, ostream& out); -- 2.39.5