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.

tejus
  • 164
  • 1
  • 1
  • 10

3 Answers3

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.
pdp
  • 778
  • 1
  • 6
  • 16
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

deagh
  • 1,969
  • 5
  • 18
  • 16
  • 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 '16 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/
ewwhite
  • 194,921
  • 91
  • 434
  • 799