On 5/8/26 1:30 PM, zwtop wrote:
> count_cpu_cores__() allocates the CPU affinity mask based on the
> number of online CPUs returned by sysconf(_SC_NPROCESSORS_ONLN).
> On Linux, sched_getaffinity() returns EINVAL if the supplied mask is
> smaller than the kernel affinity mask.
> 
> This can happen when the possible CPU range exceeds the online CPU
> count, for example on systems or VMs configured for CPU hotplug.  In
> that case OVS falls back to the online CPU count and may ignore the
> process affinity mask when sizing handler threads.
> 
> Retry sched_getaffinity() with larger dynamically allocated CPU masks
> on EINVAL, while preserving the existing fallback behavior for other
> failures.  This follows the sched_getaffinity(2) guidance for large
> CPU affinity masks: probe with dynamically allocated masks of increasing
> size until the call no longer fails with EINVAL.

Hi, zwtop.  This is indeed a valid issue.  Though I think the solution
should be different.  The core of the problem is that we're using the
_SC_NPROCESSORS_ONLN and not the _SC_NPROCESSORS_CONF for the initial
check.  This is done in order to reduce duplication with the non-Linux
cases, but there isn't really much duplication here.  We should use
the _SC_NPROCESSORS_CONF for the Linux case and _SC_NPROCESSORS_ONLN for
the non-Linux cases.  I assume, that will solve the problem, right?

> 
> Testing:
> - Ran make check TESTSUITEFLAGS=-j4: 2751 tests passed, 6 skipped.
> - Built an Open vSwitch RPM with this patch.
> - Installed the RPM on a Rocky Linux 9.7 VM running Linux 6.6.119,
>   with CPUs 0-159 possible, CPUs 0-19 online, and ovs-vswitchd
>   limited to CPUs 6-9; verified that per-cpu handler threads dropped
>   from 20 to 5 after restart, following the process affinity mask.
> 
> Assisted-by: GPT-5, Codex
> Signed-off-by: zwtop <[email protected]>

Note: for the future, please, provide the sign-off tag in the following
format, if possible:

  Signed-off-by: Full Name <[email protected]>

Best regards, Ilya Maximets.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to