The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/361
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Implementation is debatable and minimal, but this was required to have at least `/proc/stat`, `/proc/cpuinfo`, `/proc/meminfo`, and `/sys/devices/system/cpu/online` behave under a unified layout.
From 9844eea7390fe24fdca9c315e1cb6cb69ad1a798 Mon Sep 17 00:00:00 2001 From: Jonathan Calmels <jbjcalm...@gmail.com> Date: Sat, 7 Mar 2020 02:48:14 -0800 Subject: [PATCH 1/2] proc_cpuview: add minimal support for unified cgroup layout Signed-off-by: Jonathan Calmels <jbjcalm...@gmail.com> --- src/cgroups/cgfsng.c | 2 +- src/proc_cpuview.c | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cgroups/cgfsng.c b/src/cgroups/cgfsng.c index 1fcd115..98d8ca6 100644 --- a/src/cgroups/cgfsng.c +++ b/src/cgroups/cgfsng.c @@ -768,7 +768,7 @@ static bool cgfsng_can_use_cpuview(struct cgroup_ops *ops) struct hierarchy *cpu, *cpuacct; if (pure_unified_layout(ops)) - return false; + return true; cpu = ops->get_hierarchy(ops, "cpu"); if (!cpu || is_unified_hierarchy(cpu)) diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c index 1d37b5d..4d8ead5 100644 --- a/src/proc_cpuview.c +++ b/src/proc_cpuview.c @@ -421,13 +421,19 @@ static bool read_cpu_cfs_param(const char *cg, const char *param, int64_t *value { __do_free char *str = NULL; char file[11 + 6 + 1]; /* cpu.cfs__us + quota/period + \0 */ + bool first = true; - snprintf(file, sizeof(file), "cpu.cfs_%s_us", param); + if (!pure_unified_layout(cgroup_ops)) { + snprintf(file, sizeof(file), "cpu.cfs_%s_us", param); + } else { + strcpy(file, "cpu.max"); + first = !strcmp(param, "quota"); + } if (!cgroup_ops->get(cgroup_ops, "cpu", cg, file, &str)) return false; - if (sscanf(str, "%"PRId64, value) != 1) + if (sscanf(str, first ? "%"PRId64 : "%*"PRId64" %"PRId64, value) != 1) return false; return true; @@ -443,11 +449,8 @@ static double exact_cpu_count(const char *cg) int nprocs; int64_t cfs_quota, cfs_period; - if (!read_cpu_cfs_param(cg, "quota", &cfs_quota)) - return 0; - - if (!read_cpu_cfs_param(cg, "period", &cfs_period)) - return 0; + read_cpu_cfs_param(cg, "quota", &cfs_quota); + read_cpu_cfs_param(cg, "period", &cfs_period); if (cfs_quota <= 0 || cfs_period <= 0) return 0; @@ -473,11 +476,8 @@ int max_cpu_count(const char *cg) int64_t cfs_quota, cfs_period; int nr_cpus_in_cpuset = 0; - if (!read_cpu_cfs_param(cg, "quota", &cfs_quota)) - return 0; - - if (!read_cpu_cfs_param(cg, "period", &cfs_period)) - return 0; + read_cpu_cfs_param(cg, "quota", &cfs_quota); + read_cpu_cfs_param(cg, "period", &cfs_period); cpuset = get_cpuset(cg); if (cpuset) From a2632da98db1b2250a4d19ec1fcc75550b60a33f Mon Sep 17 00:00:00 2001 From: Jonathan Calmels <jbjcalm...@gmail.com> Date: Sat, 7 Mar 2020 02:50:41 -0800 Subject: [PATCH 2/2] proc_fuse: fix meminfo with unified cgroup layout Signed-off-by: Jonathan Calmels <jbjcalm...@gmail.com> --- src/proc_fuse.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/proc_fuse.c b/src/proc_fuse.c index 43e4a7f..b62d6e4 100644 --- a/src/proc_fuse.c +++ b/src/proc_fuse.c @@ -203,14 +203,18 @@ static unsigned long get_memlimit(const char *cgroup, bool swap) { __do_free char *memlimit_str = NULL; unsigned long memlimit = -1; + char *ptr; int ret; if (swap) ret = cgroup_ops->get_memory_swap_max(cgroup_ops, cgroup, &memlimit_str); else ret = cgroup_ops->get_memory_max(cgroup_ops, cgroup, &memlimit_str); - if (ret > 0) - memlimit = strtoul(memlimit_str, NULL, 10); + if (ret > 0) { + memlimit = strtoul(memlimit_str, &ptr, 10); + if (ptr == memlimit_str) + memlimit = -1; + } return memlimit; } @@ -226,6 +230,8 @@ static unsigned long get_min_memlimit(const char *cgroup, bool swap) return log_error_errno(0, ENOMEM, "Failed to allocate memory"); retlimit = get_memlimit(copy, swap); + if (retlimit == -1) + retlimit = 0; while (strcmp(copy, "/") != 0) { char *it = copy;
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel