Re: [PATCH 1/2] cgroup: add cpu.stat_percpu

From: Peter Zijlstra
Date: Tue Jan 11 2022 - 07:50:21 EST


On Fri, Jan 07, 2022 at 03:41:37PM -0800, Josh Don wrote:

> + seq_puts(seq, "usage_usec");
> + for_each_possible_cpu(cpu) {
> + cached_bstat = per_cpu_ptr(&cached_percpu_stats, cpu);
> + val = cached_bstat->cputime.sum_exec_runtime;
> + do_div(val, NSEC_PER_USEC);
> + seq_printf(seq, " %llu", val);
> + }
> + seq_puts(seq, "\n");
> +
> + seq_puts(seq, "user_usec");
> + for_each_possible_cpu(cpu) {
> + cached_bstat = per_cpu_ptr(&cached_percpu_stats, cpu);
> + val = cached_bstat->cputime.utime;
> + do_div(val, NSEC_PER_USEC);
> + seq_printf(seq, " %llu", val);
> + }
> + seq_puts(seq, "\n");
> +
> + seq_puts(seq, "system_usec");
> + for_each_possible_cpu(cpu) {
> + cached_bstat = per_cpu_ptr(&cached_percpu_stats, cpu);
> + val = cached_bstat->cputime.stime;
> + do_div(val, NSEC_PER_USEC);
> + seq_printf(seq, " %llu", val);
> + }
> + seq_puts(seq, "\n");

This is an anti-pattern; given enough CPUs (easy) this will trivially
overflow the 1 page seq buffer.

People are already struggling to fix existing ABI, lets not make the
problem worse.