TIL: How to restrict a linux process to a specified set of cores

in #til8 years ago (edited)

Today


I learned about a feature of linux called CPU core pinning, which lets you set which cores of a multicore processor your processes are running.

I had a look at what options I had available that I could pay for with the $6 extra credit an extra core for my witness VPS server. I was in the middle of adding a full bitcoin witness node for a trustworthy bitcoin RPC endpoint for my web application.

But I don't want them stepping on each other's access to the CPU, so I started searching for info about how to set which or which number of cores you can set a process to be limited to.

So now, I have my /etc/rc.local containing the following to start up these processes limited to cores, bitcoin has core 0, and the witness 1-3:

sudo mount -o remount,size=32G /dev/shm
sudo -u loki "taskset -c 1-3 steemd -d /work/loki/witness_node_data_dir --shared-file-dir /dev/shm --replay 2>>/dev/null 2>>/home/loki/steemd.l$
sudo -u bitcoin  taskset -c 0  /usr/local/bin/bitcoind -datadir=/home/bitcoin/.bitcoin

You can also set the cores available to running processes like this:

taskset -c -p {cores} {process ID}

for example:

taskset -c -p 0-1 1337

or

taskset -c -p 1-3 80085

So since I have a huge hard drive on this VPS, it holds a full bitcoin blockchain, which runs a witness only on core 0, and the witness has core 1-3.

In the process list above you can see core zero is fully loaded, and using about 24% of total processing capacity, and the other three are running the witness. In theory, if either one locks up a core, it won't stop the other (s) from operating other processes, like ssh, to log in and restart this pesty process.

😎


We can't code here! This is Whale country!

Vote #1 l0k1

Go to steemit.com/~witnesses to cast your vote by typing l0k1 into the text entry at the bottom of the leaderboard.

Sort:  

Does taskset have state across calls? I mean, can you get it to use "all cores that haven't been assigned in a previous call"? Does each call overwrite previous assignments when there is a conflict?
I should be googling this, sorry.

I think you have to manage that manually. The notations just create a bitmask that selects the cores available. You could make a simple script that dishes them out according to whatever scheme you want to use I suppose.

Possible to know why placed here falg https://steemit.com/life/@tohamy7/today-we-ll-send-a-beautiful-flower-to-all-the-kids-in-the-world-hope-you-accept-it //// -100% l0k1 2017-02-06 20:37:36 0.000 -126,825,095,828.000

you should not use @all and @here in the chat, especially not post promotion chats. you should not post idiot promotion comments completely irrelevant to the topic, you should not try to force people to pay attention to you.

If you decide to ignore me, like you ignored some 50 other people - I have seen you pop up in 4 different places with the same nonsense, nobody is going to be sad when your posts don't even appear in anyone's feed because you kept spamming and people had to escalate to the point where they get a whale to flag your posts a few times.

And you just made my mute-list now. bye!

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.030
BTC 58020.27
ETH 2464.76
USDT 1.00
SBD 2.37