I won't apply this version, please send v4 with the changes below.

On Thu, 29 Oct 2026 11:16:05 +0100, Vladimir Riabchun 
<[email protected]> wrote:
> nproc code uses sched_getaffinity syscall under the hood[1].
> It appears that this syscall returned complete nonsence when
> called from VE - we ignored both num_online_vcpus and
> cgroup cpuset limitations.

The code of patch 1 is right. What to change for v4:

1. Patch 1: add a Fixes tag for 87211cbff4b4 ("sched: Return only
   virtual cpus in sched_getaffinity()") and the Feature line of that
   commit, "sched: virtualize CT cpu affinity management".

2. Patch 1: fix the message. bitmap_fill() fills whole unsigned
   longs, not integers. Say what a CT sees now: the first
   min(vCPUs, CPUs of its cpuset) bits, with the vCPU limit of the
   target task. nproc can then be lower than /proc/cpuinfo and
   /sys/devices/system/cpu/online, say that this is intended.

3. Patch 1: the code comment says setaffinity is "not available"
   inside a CT. sched_setaffinity() returns 0 there and does nothing,
   write that.

4. Patch 2: loop to CPU_SETSIZE in get_nth_cpu().

5. Patch 2: include <sys/mman.h>, as you promised in the v2 reply,
   and add a Feature: line.

6. Cover letter:
   - The old code did use num_online_vcpus(), the bug was the
     rounding. Ignoring the cpuset was the design of 87211cbff4b4.
   - "64 no matter what" holds up to 64 vCPUs, above that it was 128.
   - Typos: "nonsence", "insted".
   - Link [1] points at a line of gnulib master, which will drift.
     Name the function instead.

Separate patches, not needed for this series; I created a task for
it:

1. task_nr_cpus() reads nr_cpus of the task's own cpu cgroup, while
   vzctl --cpus sets it on the CT root cgroup only. In a nested cpu
   cgroup inside a CT (docker in a CT, a systemd unit with CPUQuota=)
   nproc, /proc/cpuinfo and the sysfs cpu lists show the host CPU
   count. tg_nr_cpus() in cpuacct.c already goes through
   ve_root_tg(), task_nr_cpus() should do the same.
   https://virtuozzo.atlassian.net/browse/VSTOR-154938

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to