The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/307
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) === This PR mainly fixes the problem of counting the number of CPUs when using cpuset and cpuset or using cpuset alone. When using only cpuset ``` Docker run -it --rm \ --cpuset-cpus="0-4,6" \ --memory 2048m \ -v /var/run/lxcfs/sys/devices/system/cpu/online:/sys/devices/system/cpu/online \ -v /var/run/lxcfs/proc/cpuinfo:/proc/cpuinfo:rw \ Ningx bash ``` Or when Cpuset and cpu quota are used at the same time, but the number of CPUs that cpuset can use is less than cpu quota. ``` Docker run -it --rm \ --cpu-period=100000 \ --cpu-quota=800000 \ --cpuset-cpus="0-4,6" \ --memory 2048m \ -v /var/run/lxcfs/sys/devices/system/cpu/online:/sys/devices/system/cpu/online \ -v /var/run/lxcfs/proc/cpuinfo:/proc/cpuinfo:rw \ Ningx bash ``` Getting the number of CPUs in the container will be unsatisfactory. Therefore, cpuset is introduced as the basis for the quantity judgment when calculating the maximum available CPU number. This PR can also solve these ISSUE(such as [331](https://github.com/lxc/lxcfs/issues/301)) problems. Signed-off-by: Hongbo Yin <yinhon...@bytedance.com>
From 0ca91394393b2a74910c0f58d3e858ed285c7842 Mon Sep 17 00:00:00 2001 From: Hongbo Yin <yinhon...@bytedance.com> Date: Fri, 27 Sep 2019 18:50:44 +0800 Subject: [PATCH] fix the problem of counting the number of CPUs when using cpuset and cpuset or using cpuset alone Signed-off-by: Hongbo Yin <yinhon...@bytedance.com> --- bindings.c | 16 +++++++++++++++- sysfs_fuse.c | 6 ------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bindings.c b/bindings.c index 89fe28d..ed1b4f9 100644 --- a/bindings.c +++ b/bindings.c @@ -3669,6 +3669,8 @@ int max_cpu_count(const char *cg) { int rv, nprocs; int64_t cfs_quota, cfs_period; + int nr_cpus_in_cpuset = 0; + char *cpuset = NULL; if (!read_cpu_cfs_param(cg, "quota", &cfs_quota)) return 0; @@ -3676,8 +3678,16 @@ int max_cpu_count(const char *cg) if (!read_cpu_cfs_param(cg, "period", &cfs_period)) return 0; - if (cfs_quota <= 0 || cfs_period <= 0) + cpuset = get_cpuset(cg); + if (cpuset) + nr_cpus_in_cpuset = cpu_number_in_cpuset(cpuset); + + if (cfs_quota <= 0 || cfs_period <= 0){ + if(nr_cpus_in_cpuset > 0) + return nr_cpus_in_cpuset; + return 0; + } rv = cfs_quota / cfs_period; @@ -3692,6 +3702,10 @@ int max_cpu_count(const char *cg) if (rv > nprocs) rv = nprocs; + /* use min value in cpu quota and cpuset */ + if(nr_cpus_in_cpuset > 0 && nr_cpus_in_cpuset < rv) + rv = nr_cpus_in_cpuset; + return rv; } diff --git a/sysfs_fuse.c b/sysfs_fuse.c index dc535d7..32a59b7 100644 --- a/sysfs_fuse.c +++ b/sysfs_fuse.c @@ -46,7 +46,6 @@ static int sys_devices_system_cpu_online_read(char *buf, size_t size, bool use_view; int max_cpus = 0; - int max_cpus_in_cpuset = 0; pid_t initpid; ssize_t total_len = 0; @@ -78,11 +77,6 @@ static int sys_devices_system_cpu_online_read(char *buf, size_t size, if (use_view) max_cpus = max_cpu_count(cg); - max_cpus_in_cpuset = cpu_number_in_cpuset(cpuset); - // use min value in cpu quota and cpuset - if (max_cpus_in_cpuset > 0) - max_cpus = max_cpus_in_cpuset > max_cpus ? max_cpus : max_cpus_in_cpuset; - if (max_cpus == 0) return read_file("/sys/devices/system/cpu/online", buf, size, d); if (max_cpus > 1)
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel