8.9.2 Controlling CPU and Memory Usage

Define two cgroups with different allocations of available CPU time and memory resources.

mount {
    cpu = /cgroup/cpumem;
    cpuset = /cgroup/cpumem;
    memory = /cgroup/cpumem;
}

# High priority group
group hipri { 
    cpu {
#       Set the relative share of CPU resources equal to 75%
        cpu.shares="750"; 
    }
    cpuset {
#       No alternate memory nodes if the system is not NUMA
        cpuset.mems="0"; 
#       Make all CPU cores available to tasks
        cpuset.cpus="0-7"; 
    }
    memory {
#       Allocate at most 2 GB of memory to tasks
        memory.limit_in_bytes="2G"; 
#       Allocate at most 4 GB of memory+swap to tasks
        memory.memsw.limit_in_bytes="4G"; 
#       Apply a soft limit of 1 GB to tasks
        memory.soft_limit_in_bytes="1G"; 
    }
}

# Low priority group
group lopri { 
    cpu {
#       Set the relative share of CPU resources equal to 25%
        cpu.shares="250"; 
    }
    cpuset {
#       No alternate memory nodes if the system is not NUMA
        cpuset.mems="0"; 
#       Make only cores 0 and 1 available to tasks
        cpuset.cpus="0,1"; 
    }
    memory {
#       Allocate at most 1 GB of memory to tasks
        memory.limit_in_bytes="1G"; 
#       Allocate at most 2 GB of memory+swap to tasks
        memory.memsw.limit_in_bytes="2G"; 
#       Apply a soft limit of 512 MB to tasks
        memory.soft_limit_in_bytes="512M"; 
    }
}