Why does processes no longer run on first cpu when cpu affinity is changed by sched_setaffinity() syscall and cpumask contains multiple cpus?
Issue
- Why does processes no longer run on first cpu when cpu affinity is changed by sched_setaffinity() syscall and cpumask contains multiple cpus?
OLD BEHAVIOR
# cat /sys/devices/system/cpu/isolated
1-3,5-7
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[1] 4116
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[2] 4639
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[3] 4689
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[4] 4716
# ps -o pid,psr,comm -p `pidof sha1sum`
PID PSR COMMAND
4116 1 sha1sum
4639 1 sha1sum
4689 1 sha1sum
4716 1 sha1sum
NEW BEHAVIOR
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[1] 5061
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[2] 5062
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[3] 5063
# taskset -c 1-3,5-7 sha1sum /dev/zero &
[4] 5064
# ps -o pid,psr,comm -p `pidof sha1sum`
PID PSR COMMAND
5061 5 sha1sum
5062 6 sha1sum
5063 7 sha1sum
5064 1 sha1sum
- In above snippets we can see that with
new behaviorthe tasks are distributed across provided cpuset, whereas withold behaviorall the tasks got affinity as first cpu in the cpuset IE cpu#1.
Environment
- RHEL8.4
- kernel-4.18.0-305.el8.x86_64 and above
- kernel-rt-4.18.0-305.rt7.72.el8.x86_64 and above
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.