Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set niceness and process affinity at the same time?

Is there a way to set the nice value of process and its affinity at the same time? For example:

 taskset -c 0,1 nice -20 proc

Update: It works like this. I thought it must me something more complex.

like image 754
barp Avatar asked Jul 23 '12 14:07

barp


People also ask

How do I check my CPU affinity?

CPU affinity enables binding a process or multiple processes to a specific CPU core in a way that the process(es) will run from that specific core only. When trying to perform performance testing on a host with many cores, it is wise to run multiple instances of a process, each one on different core.

How do I change the niceness in Linux?

You can change the scheduling priority of a running process to a value lower or higher than the base scheduling priority by using the renice command from the command line. This command changes the nice value of a process.

Why pin a process to CPU core?

You can bind/pin a process to one or more CPUs. This increases the chances of more cache warmth/cache hits thus resulting in a much better performance.


1 Answers

Using PID-Based Scheduling Tools

Many CPU scheduling tools want a PID rather than a command. The following seems to work on my system:

# Using shell expansion to reliably use correct PID.
sudo nice -n18 schedtool -a 0,1 $(sleep 30 & echo $!) &

by using a shell expansion to get the PID of the last backgrounded process, but it seems hackish. The following seems cleaner, IMHO, but your mileage (and obviously the specifics of the scheduling tool you're using) may vary.

# Cleaner example with less hacking around.
nice -n18 sleep 30 &
sudo schedtool -a 0,1 $!

Flags That Take Commands

If supported, the -e flag seems to do what's needed by allowing a command instead of a PID. For example:

sudo schedtool -a 0,1 -e nice -n18 sleep 30 &
like image 97
Todd A. Jacobs Avatar answered Nov 03 '22 23:11

Todd A. Jacobs