Skip to content

Commit

Permalink
bugfix: cgroup v2 /proc/stat cpu count greater then cpu.max
Browse files Browse the repository at this point in the history
Signed-off-by: Hongbo Yin <[email protected]>
  • Loading branch information
hongbo-bd committed Jul 10, 2023
1 parent 0dbe340 commit 95047f0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/proc_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
size_t linelen = 0, total_len = 0;
int curcpu = -1; /* cpu numbering starts at 0 */
int physcpu = 0;
int max_cpu = 0;
uint64_t user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0,
softirq = 0, steal = 0, guest = 0, guest_nice = 0;
uint64_t user_sum = 0, nice_sum = 0, system_sum = 0, idle_sum = 0,
Expand Down Expand Up @@ -979,6 +980,8 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
lxcfs_v("proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat");
}

max_cpu = max_cpu_count(cg);

while (getline(&line, &linelen, f) != -1) {
ssize_t l;
char cpu_char[10]; /* That's a lot of cores */
Expand Down Expand Up @@ -1011,6 +1014,9 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,

curcpu++;

if (max_cpu > 0 && (curcpu + 1 > max_cpu))
continue;

if (cgroup_ops->can_use_cpuview(cgroup_ops) && opts && opts->use_cfs)
cpu_to_render = curcpu;
else
Expand Down

0 comments on commit 95047f0

Please sign in to comment.