0

Is it possible to prevent a CPU core from being used by the OS in Linux? The maxcpus=<n> boot parameter prevents specified number of cores from being seen in the OS. I want that all cores be visible but yet only some be used by the OS for scheduling processes.

EDIT: This is required to ensure that critical processes can be scheduled on a core and remaining not absolutely important but highly CPU intensive processes can compete amongst themselves for the other cores. This is on CentOS 6.

5
  • So that processes using this particular core can be deterministically assigned.
    – tejus
    May 27, 2016 at 10:27
  • 3
    This is possible. Please describe what you're trying to do, the OS distribution and version and just more detail about your situation.
    – ewwhite
    May 27, 2016 at 12:17
  • @ewwhite I have updated the question with further information.
    – tejus
    May 27, 2016 at 12:30
  • @pokhala Did you get an answer to your question?
    – ewwhite
    May 29, 2016 at 2:59
  • @ewwhite Yes, isolcpus boot parameter works fine.
    – tejus
    May 30, 2016 at 15:41

3 Answers 3

3

Use the isolcpus parameter on the kernel command line to isolate certain cores from user-space tasks. Quoting from kernel boot parameters documentation:

isolcpus= [KNL,SMP] Isolate CPUs from the general scheduler. Format: ,..., or - (must be a positive range in ascending order) or a mixture ,...,-

           This option can be used to specify one or more CPUs
           to isolate from the general SMP balancing and scheduling
           algorithms. You can move a process onto or off an
           "isolated" CPU via the CPU affinity syscalls or cpuset.
           <cpu number> begins at 0 and the maximum value is
           "number of CPUs in system - 1".

           This option is the preferred way to isolate CPUs. The
           alternative -- manually setting the CPU mask of all
           tasks in the system -- can cause problems and
           suboptimal load balancer performance.
2

You can disable processors for example (core0) with echo 0 > /sys/devices/system/cpu/cpu0/online and enable with echo 1 > /sys/devices/system/cpu/cpu0/online

You can verify the state with cat /proc/cpuinfo

1
  • No, I don't want to remove the core. I want it to show up in top but not be used by the OS for scheduling processes.
    – tejus
    May 27, 2016 at 12:50
2

Generic answer... until you provide more information.

You may want to use the CPU isolation tool of choice for your distribution. Also, cgroups may be relevant, depending on what you specifically trying to accomplish.

difference between taskset and cpuset


Edit:

You're looking for a CPU shield. On EL6, you may want to read up on cgroups and the cgred daemon and cgconfig package.

For instance:

/etc/cgconfig.conf:

mount {
        cpuset  = /cgroup/cpuset;
        cpu     = /cgroup/cpu;
        cpuacct = /cgroup/cpuacct;
        memory  = /cgroup/memory;
        devices = /cgroup/devices;
        freezer = /cgroup/freezer;
        net_cls = /cgroup/net_cls;
        blkio   = /cgroup/blkio;
}

group ppro-users {
        cpuset {
                cpuset.mems="0-1";
                cpuset.cpus="2-7,14-19";
        }
        cpu {
                cpu.shares = 1000;
        }
        memory {
                memory.limit_in_bytes = 40960m;
        }
}

The snippet above limits processes in the "ppro-users" cgroup to certain CPUs. I augment that by using the cgred package to identify and manage processes that should belong to that cgroup.

/etc/cgrules.conf

# Example:
#<user>         <controllers>   <destination>
#@student       cpu,memory      usergroup/student/
#peter          cpu             test1/
#%              memory          test2/
admin           cpu,cpuset,memory       ppro-users/
@ppro:dbc       cpu,cpuset,memory       ppro-users/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.