How to Restrict Oracle to Certain CPUs on a Multi-CPU Machine on Linux (文档 ID 390079.1)
APPLIES TO:
Linux OS - Version 2.6 to 2.6
Linux x86
Linux x86-64
Linux x86-64
Doc is valid for stated releases: ol5, ol6.
For ol7, a new doc is required as the required package differs
GOAL
You want to restrict the Oracle processes (or any other process) to certain CPUs of a multi-cpu system. For example, on Windows there is "ORACLE_AFFINITY" registry setting (See Note 108512.1). How to do this on Linux?
SOLUTION
The schedutils (OL5) or util-linux-ng (OL6) RPM package provides this capability. You can install the package from Oracle Linux installation media or via yum / up2date, e.g. for OL5:
# up2date -i schedutils
OL6:
# yun install -y util-linux-ng
It provides the taskset command which can be used to manipulate processes. (See "man taskset" for more information)
You can also use the taskset command to start up an Oracle instance, for example:
$ taskset -c 1,3-5 sqlplus '/ as sysdba'
SQL> startup
SQL> exit
All the background tasks will then have affinity to processors 1, 3, 4 and 5 (not 0, 2 or 6 and above).
You can verify the affinity of any particular process by first finding the process id (pid) with the ps command (e.g. "ps -ef | grep dbw" to find all the database writer processes), then using the "-p" option of taskset. In this example, process id 2675 was that of a dbw task started as a result of the "taskset -c 1,3-5 sqlplus .." command:
# taskset -p 2675
pid 2675's current affinity mask: 3a
The result is given in hexadecimal notation but it is meaningful in binary. Convert the value to binary:
# echo "obase=2;ibase=16;3A" | bc
111010
note that the hexadecimal numerals should be in capital letters and output is the least significant digits.
Here our value is 00111010. The rightmost 0 represents processor 0, thus the bitmap shows affinity to processors 5,4,3 and 1 (not 7,6,2 or 0)
You can also use the taskset command to start the TNS listener in the same way as the database - this will cause the dedicated two-task servers to inherit the same CPU affinity as the tnslsnr command.
You can also change the affinity of any particular process, e.g.
# taskset -pc 1-3 2675
pid 2675's current affinity list: 1,3-5
pid 2675's new affinity list: 1-3
In the above example, the result is more meaningful to the command issued. Querying the process again gets the hexadecimal notation:
# taskset -p 2675
pid 2675's current affinity mask: e
0x0e is binary 00001110 thus it can be seen that affinity is now set to processors 3,2 and 1 (not 0, not 4 or higher).
For multi-threaded appliccations, establish the "master" process, then assign all the slave processes. For example:
for p in `ls /proc/2675/task`; do taskset -p -c 1-3 $p; done
Note that if NUMA (Non-Uniform Memory Architecture) is implemented, then the cpu affinity for NUMA will take precedence.
REFERENCES
NOTE:108512.1 - ORACLE_AFFINITY - How to Restrict Oracle on a Multi-CPU Windows Machine