]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/util: get_cgroup_memory_limit() helper
authorSage Weil <sage@redhat.com>
Fri, 8 Mar 2019 17:27:20 +0000 (11:27 -0600)
committerSage Weil <sage@redhat.com>
Fri, 8 Mar 2019 22:30:39 +0000 (16:30 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/util.cc
src/include/util.h

index 03e7c878448c5a73f4169d04050601d0d4a417fc..84d413590f9949bbd6039991b911f0cbd96db791 100644 (file)
@@ -135,6 +135,38 @@ static void distro_detect(map<string, string> *m, CephContext *cct)
   }
 }
 
+int get_cgroup_memory_limit(uint64_t *limit)
+{
+  // /sys/fs/cgroup/memory/memory.limit_in_bytes
+
+  // the magic value 9223372036854771712 or 0x7ffffffffffff000
+  // appears to mean no limit.
+  FILE *f = fopen(PROCPREFIX "/sys/fs/cgroup/memory/memory.limit_in_bytes", "r");
+  if (!f) {
+    return -errno;
+  }
+  char buf[100];
+  int ret = 0;
+  long long value;
+  char *line = fgets(buf, sizeof(buf), f);
+  if (!line) {
+    ret = -EINVAL;
+    goto out;
+  }
+  if (sscanf(line, "%lld", &value) != 1) {
+    ret = -EINVAL;
+  }
+  if (value == 0x7ffffffffffff000) {
+    *limit = 0;  // no limit
+  } else {
+    *limit = value;
+  }
+out:
+  fclose(f);
+  return ret;
+}
+
+
 void collect_sys_info(map<string, string> *m, CephContext *cct)
 {
   // version
index 62d4b6f35d59948e09acb08238f7e420060bcf7b..9c377aa1413da7fefe2bf58396f9e2e403216247 100644 (file)
@@ -73,6 +73,9 @@ WRITE_CLASS_ENCODER(ceph_data_stats)
 
 int get_fs_stats(ceph_data_stats_t &stats, const char *path);
 
+/// get memory limit for the current cgroup
+int get_cgroup_memory_limit(uint64_t *limit);
+
 /// collect info from @p uname(2), @p /proc/meminfo and @p /proc/cpuinfo
 void collect_sys_info(map<string, string> *m, CephContext *cct);