How to Restrict Oracle to Certain CPUs on a Multi-CPU Machine on Linux (文档 ID 390079.1)

本文介绍如何在Linux多CPU系统中使用schedutils或util-linux-ng包的taskset命令,来限制Oracle进程或其他进程运行在指定的CPU上,包括设置启动实例、监听器及更改现有进程的亲和性的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值