With the kernel command line parameter default_affinity, the affinity is not set for all processes
Environment
- Red Hat Enterprise Linux 6.4
initscripts-9.03.38-1.el6_4.1.x86_64
Issue
The file /etc/rc.d/rc.sysinit
from the package initscripts
doesn't correctly set the affinity for all running processes. It only sets the affinity for PID 1 (init
). Any subsequent program invocations later in the script do not inherit the correct affinity. This affects udev
for instance.
Resolution
Update to initscripts-9.03.49-1.el6 or newer. With this update affinity is set for the shell executing rc.sysinit
too. This ensures inheriting the correct affinity by processes forked from this shell after setting the affinity.
Root Cause
rc.sysinit
uses taskset
to set affinity defined on the kernel command line. However, the affinity is set for PID 1 (init
) only. As the shell executing rc.sysinit
is already running by that time, no affinity is set for this shell. Therefore, all processes forked from this shell do not inherit the affinity from init
but inherit no affinity setting from the running shell. As udev
is started later in rc.sysinit
, it has no affinity mask.
Diagnostic Steps
- Take a virtual machine with two core processor allocated for the same.
- Install Red Hat Enterprise Linux 6.4
- Provide the kernel command line parameter
default_affinity=0x1
and check out the affinities.
Reproducers are as follows:
- With
default_affinity=0x1
kernel command line parameter.
# rpm -q initscripts
initscripts-9.03.38-1.el6_4.1.x86_64
# cat /proc/cmdline
ro root=/dev/mapper/myvg-rootvol rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 rd_LVM_LV=myvg/rootvol KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet default_affinity=0x1
# cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
# for pid in $(pgrep udev); do taskset -p $pid; done
pid 590's current affinity mask: 3
pid 1662's current affinity mask: 3
pid 1663's current affinity mask: 3
# for pid in $(pgrep init); do taskset -p $pid; done
pid 1's current affinity mask: 1
- Without
default_affinity=0x1
kernel command line parameter.
# rpm -q initscripts
initscripts-9.03.38-1.el6_4.1.x86_64
# cat /proc/cmdline
ro root=/dev/mapper/myvg-rootvol rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 rd_LVM_LV=myvg/rootvol KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
# cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
# for pid in $(pgrep udev); do taskset -p $pid; done
pid 506's current affinity mask: 3
pid 1516's current affinity mask: 3
pid 1517's current affinity mask: 3
# for pid in $(pgrep init); do taskset -p $pid; done
pid 1's current affinity mask: 3
- With the patch:
# cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
# cat /proc/cmdline
ro root=/dev/mapper/myvg-rootvol rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 rd_LVM_LV=myvg/rootvol KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet default_affinity=0x1
# for pid in $(pgrep udev); do taskset -p $pid; done
pid 497's current affinity mask: 1
pid 854's current affinity mask: 1
pid 1499's current affinity mask: 1
# for pid in $(pgrep init); do taskset -p $pid; done
pid 1's current affinity mask: 1
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments