• Linux
  • FreeBSD
  • Networking
  • Python
  • AWS
  • WebDev
  • About Us
Tech Tips and Tutorials
Menu
  • Linux
  • FreeBSD
  • Networking
  • Python
  • AWS
  • WebDev
  • About Us
Home  /  FreeBSD  /  How to set CPU affinity in FreeBSD to allocate specific cores to specific processes

How to set CPU affinity in FreeBSD to allocate specific cores to specific processes

Written by
FreeBSD Leave a Comment

If your hardware has multiple CPUs, you can set CPU affinity to run certain processes on specific cores. In FreeBSD, the cpuset command is used for this purpose. I have a test server on AWS with two CPU cores. First, let’s verify the hardware by running the following command:

sysctl -a | egrep -i 'hw.machine|hw.model|hw.ncpu'

So you can see I have two cpu s on this machine , its upto 2 cores ie, 0 and 1 are the cpu’s. So from the two cpu cores, I want to run all my system default processes on first cpu and only my openvpn on second cpu .

To set all the default processes on core 0

cpuset -s1 -l 0  (the last 0 is the cpu number)

To make this change permanent even after reboot , add the below line to the /etc/rc.conf file

/usr/bin/cpuset -s1 -l 0

To set the openvpn process on CPU2 , first you need to find out the openvpn process id using the ps command .

ps ax | grep openvpn

This will show the process id of your openvpn process . Then run the below command to move the process to cpu 1

cpuset -C -c -l 1 -p openvpnpid

So to get this working even after the reboot , either you need to run some startup script to find the process id and then execute the above command or run it manually . This is because every time system reboots or the service stops the process id changes , so thats something you need to figure out .

So now if you run a top command you will be able to see all my system processes are running on CPU 0 and the openvpn process on core 1

Share On
Share on Facebook
Share on Twitter
Share on Google+
Share on Whatsapp

 Previous Article How to install Python Pip on FreeBSD 12 .1
Next Article   How to create an empty file of a specific size in Linux

Related Posts

  • How to run tcpdump as a process for pcap capture in FreeBSD

  • How to increase the disk size in FreeBSD

  • How to list and mount an external USB disk in FreeBSD

Leave a Reply

Cancel reply

  • Popular Posts
  • Recent Posts
  • Linux Shell Scripts for System Administrators
  • Cacti 1.1.38 ERROR Opening .rrd No Such file or directory
  • Apache configuration for Cacti
  • How to create RAM disk in Ubuntu 18.04
  • Linux Shell Scripts for System Administrators
  • SOCKS PROXY
  • How to install XAMPP and access phpMyAdmin in MAC OS
  • How to increase the root volume in a Linux ec2 instance

Linux

  • Linux Shell Scripts for System Administrators
  • SOCKS PROXY
  • How to grep IP addresses from log files in Linux
  • How to empty or delete a large file in Linux

Categories

  • AWS (5)
  • FreeBSD (12)
  • Linux (29)
  • Networking (3)
  • Python (5)
  • Uncategorized (4)
  • WebDev (1)
  • Connect on Facebook
  • Connect on YouTube
© Copyright 2020.TechieNix. All Rights Reserved.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Non-necessary

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.