We need for the JVM to reserve a set number of CPUs. Following my research we can use taskset along with the kernel parameter isolcpus=<CPU_ID> so that no other process uses this CPU.

A few questions arise:

  • does the process need to be started with taskset?
  • does the reservation means that the process can only run on that CPU and if there are resources problems it can expand to the other CPUs?

1 Answer 1


You typically use taskset to restrict a process after it's been started. You could make use of the pidof java to determine what the PID is for your Java application and then pass that to taskset:

$ taskset -p $(pidof java) --cpu-list 0-2,5

NOTE: If you had 6 CPUs, 0,1,2,5 would assign an affinity to these CPUs for your JVM's PID.

Keep in mind that affinity does not restrict other processes from using these CPUs, taskset if more a tool of restricting a specific process or processes to a specific set of CPUs, not in restricting exclusivity.

excerpt taskset man page

taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on the system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU affinity: the scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications.


This self answered U&L Q&A titled: How to use cgroups to limit all processes except whitelist to a single CPU? covers the topic of how to accomplish this using cgroups.


  • Is it therefore not possible to reserve cpu exclusivly to some applications and nothing else uses these cpu?
    – danidar
    Jul 27, 2018 at 8:49
  • It's possible using cgroups - unix.stackexchange.com/questions/247209/…. But not in the way you imagine.
    – slm
    Jul 27, 2018 at 8:54
  • I read on xmodulo that the kernel parameter "isolcpus=<CPU_ID>" to the boot loader during boot or GRUB configuration file. Then the Linux scheduler will not schedule any regular process on the reserved CPU core(s), unless specifically requested with taskset. For example, to reserve CPU cores 0 and 1, add "isolcpus=0,1" kernel parameter. Upon boot, then use taskset to safely assign the reserved CPU cores to your program.
    – danidar
    Jul 27, 2018 at 9:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .