lxc-execute로 메모리 및 CPU 제한


9

lxc-execute를 사용하여 프로세스를 격리하고 싶습니다. 대역폭, CPU 및 메모리 제한을 설정할 수 있습니까?

나는 lxc.conf의 사람을 보았지만 철저하지는 않았습니다.

답변:


23

우선 LXC 유틸리티의 일부인 Cgroup 을 이해하고 싶습니다 . 컨테이너가있는 경우, 실행중인 다양한 컨테이너가 다른 컨테이너 나 프로세스 내에서 굶주 리도록해야합니다. 이것을 염두에두고 LXC 프로젝트 의 좋은 사람일명 Daniel Lezcano는 cgroups와 그가 만든 컨테이너 기술, 즉 LXC를 통합했습니다. 이제 자원 사용량을 지정하려면 CGROUP 구성을 조사해야합니다. Cgroup을 사용하면 시스템에서 실행중인 사용자 정의 작업 그룹 (프로세스)간에 CPU 시간, 시스템 메모리, 네트워크 대역폭 또는 이러한 리소스 조합과 같은 리소스를 할당 할 수 있습니다. 구성한 cgroup을 모니터링하고 cgroup이 특정 리소스에 대한 액세스를 거부하고 실행중인 시스템에서 cgroup을 동적으로 재구성 할 수도 있습니다. cgconfig (control group config) 서비스는 부팅시 시작하고 미리 정의 된 cgroup을 다시 설정하여 재부팅시에도 지속적으로 유지되도록 구성 할 수 있습니다. 각 계층 구조는 하나 이상의 하위 시스템 (자원 컨트롤러 또는 컨트롤러라고도 함)에 연결되어 있으므로 Cgroup은 여러 계층을 가질 수 있습니다. 그러면 연결되지 않은 트리가 여러 개 만들어집니다. 사용 가능한 9 개의 서브 시스템이 있습니다.

  1. blkio는 블록 장치의 입력 / 출력 액세스에 대한 제한을 설정합니다
  2. CPU에 대한 cgroup 작업 액세스를위한 CPU 스케줄러
  3. cpuacct는 CPU 사용 및 cgroup에 대한 보고서를 생성합니다
  4. cpuset은 cgroup에 CPU와 메모리를 할당합니다
  5. 장치는 작업별로 장치에 대한 액세스를 관리합니다
  6. 냉동고 일시 중지 / 재개 작업
  7. 메모리 제한 메모리
  8. Linux 트래픽 컨트롤러가 작업 트래픽을 식별 할 수 있도록 net_cls 태그 네트워크 패킷
  9. NS 네임 스페이스

커널에있는 하위 시스템을 다음 명령으로 나열 할 수 있습니다.

lssubsys –am

lxc-cgroup은 컨테이너 이름과 관련된 제어 그룹에서 값을 가져 오거나 설정합니다. 컨테이너와 관련된 제어 그룹을 관리하십시오. 사용법 예 :

lxc-cgroup -n foo cpuset.cpus "0,3" 

프로세서 0과 3을 컨테이너에 할당하십시오.

자, 제 생각에는 원래 질문에 대한 답변이 있습니다. 그러나 lxc를 사용하도록 컨테이너를 구성하는 데 유용한 매개 변수를 조금 추가하겠습니다. redhat에 의한 자원 관리 문서의 요약 양식이 있습니다 .

BLKIO 수정 가능 매개 변수 :

    blkio.reset_stats : any int to reset the statistics of BLKIO
    blkio.weight : 100 - 1000 (relative proportion of block I/O access)
    blkio.weight_device : major, minor , weight 100 - 1000 
    blkio.time : major, minor and time (device type and node numbers and length of access in milli seconds)
    blkio.throttle.read_bps_device : major, minor specifies the upper limit on the number of read operations a device can perform. The rate of the read operations is specified in bytes per second.
    blkio.throttle.read_iops_device :major, minor and operations_per_second specifies the upper limit on the number of read operations a device can  perform
    blkio.throttle.write_bps_device : major, minor and bytes_per_second (bytes per second)
    blkio.throttle.write_iops_device : major, minor and operations_per_second

CFS 수정 가능 매개 변수 :

    cpu.cfs_period_us : specifies a period of time in microseconds for how regularly a cgroup's access to CPU resources should be reallocated. If tasks in a cgroup should be able to access a single CPU for 0.2 seconds out of every 1 second, set cpu.cfs_quota_us to 200000 and cpu.cfs_period_us to 1000000.
    cpu.cfs_quota_us : total amount of time in microseconds that all tasks in a cgroup can run during one period. Once limit has reached, they are not allowed to run beyond that. 
    cpu.shares : contains an integer value that specifies the relative share of CPU time available to tasks in a cgroup.


    Note: For example, tasks in two cgroups that have cpu.shares set to 1 will receive equal CPU time, but tasks in a cgroup that has cpu.shares set to 2 receive twice the CPU time of tasks in a cgroup where cpu.shares is set to 1. Note that shares of CPU time are distributed per CPU. If one cgroup is limited to 25% of CPU and another cgroup is limited to 75% of CPU, on a multi-core system, both cgroups will use 100% of two different CPUs. 

RT 수정 가능 매개 변수 :

cpu.rt_period_us : time in microseconds for how regularly a cgroups access to CPU resources should be reallocated. 
cpu.rt_runtime_us : same as above.

CPU 세트 :

cpuset subsystem assigns individual CPUs and memory nodes to cgroups.
Note: here some parameters are mandatory
Mandatory: 


cpuset.cpus : specifies the CPUs that tasks in this cgroup are permitted to access. This is a comma-separated list in ASCII format, with dashes (" -")                 to represent ranges. For example 0-2,16 represents CPUs 0, 1, 2, and 16. 
        cpuset.mems : specifies the memory nodes that tasks in this cgroup are permitted to access. same as above format


Optional: 
        cpuset.cpu_exclusive : contains a flag ( 0 or 1) that specifies whether cpusets other than this one and its parents and children can share the CPUs specified for this cpuset. By default ( 0), CPUs are not allocated exclusively to one cpuset. 
        cpuset.mem_exclusive : contains a flag ( 0 or 1) that specifies whether other cpusets can share the memory nodes specified for this cpuset. By default ( 0), memory nodes are not allocated exclusively to one cpuset. Reserving memory nodes for the exclusive use of a cpuset ( 1) is functionally the same as enabling a memory hardwall with the cpuset.mem_hardwall parameter.
        cpuset.mem_hardwall : contains a flag ( 0 or 1) that specifies whether kernel allocations of memory page and buffer data should be restricted to the memory nodes specified for this cpuset. By default ( 0), page and buffer data is shared across processes belonging to multiple users. With a hardwall enabled ( 1), each tasks' user allocation can be kept separate.
        cpuset.memory_pressure_enabled : contains a flag ( 0 or 1) that specifies whether the system should compute the memory pressure created by the processes in this cgroup
        cpuset.memory_spread_page : contains a flag ( 0 or 1) that specifies whether file system buffers should be spread evenly across the memory nodes allocated to this cpuset. By default ( 0), no attempt is made to spread memory pages for these buffers evenly, and buffers are placed on the same node on which the process that created them is running. 
        cpuset.memory_spread_slab : contains a flag ( 0 or 1) that specifies whether kernel slab caches for file input/output operations should be spread evenly across the cpuset. By default ( 0), no attempt is made to spread kernel slab caches evenly, and slab caches are placed on the same node on which the process that created them is running.
        cpuset.sched_load_balance : contains a flag ( 0 or 1) that specifies whether the kernel will balance loads across the CPUs in this cpuset. By default ( 1), the kernel balances loads by moving processes from overloaded CPUs to less heavily used CPUs.

기기 :

The devices subsystem allows or denies access to devices by tasks in a cgroup. 
    devices.allow : specifies devices to which tasks in a cgroup have access. Each entry has four fields: type, major, minor, and access.
    type can be of following three values: 
        a - applies to all devices
        b - block devices
        c - character devices
    access is a sequence of one or more letters: 
        r read from device
        w write to device
        m create device files that do not yet exist

    devices.deny : similar syntax as above
    devices.list : reports devices for which access control has been set for tasks in this cgroup

기억:

메모리 하위 시스템은 cgroup의 작업에서 사용하는 메모리 리소스에 대한 자동 보고서를 생성하고 해당 작업에서 메모리 사용에 대한 제한을 설정합니다. Memory 수정 가능한 매개 변수 : memory.limit_in_bytes : 최대 사용자 메모리 양을 설정합니다. 킬로그램에는 K, 메가 등에는 M과 같은 접미사를 사용할 수 있습니다. 이렇게하면 계층의 하위 그룹 만 제한됩니다. 즉, 루트 cgroup은 제한 될 수 없습니다. memory.memsw.limit_in_bytes : 메모리와 스왑 사용량의 최대량을 설정합니다. 다시 이것은 루트 cgroup을 제한 할 수 없습니다.

    Note: memory.limit_in_bytes should always be set before memory.memsw.limit_in_bytes because only after limit, can swp limit be set
    memory.force_empty : when set to 0, empties memory of all pages used by tasks in this cgroup
    memory.swappiness : sets the tendency of the kernel to swap out process memory used by tasks in this cgroup instead of reclaiming pages from the page cache. he default value is 60. Values lower than 60 decrease the kernel's tendency to swap out process memory, values greater than 60 increase the kernel's tendency to swap out process memory, and values greater than 100 permit the kernel to swap out pages that are part of the address space of the processes in this cgroup. 


    Note: Swappiness can only be asssigned to leaf groups in the cgroups architecture. i.e if any cgroup has a child cgroup, we cannot set the swappiness for that
    memory.oom_control : contains a flag ( 0 or 1) that enables or disables the Out of Memory killer for a cgroup. If enabled ( 0), tasks that attempt to consume more memory than they are allowed are immediately killed by the OOM killer. 

net_cls :

net_cls 하위 시스템은 Linux 트래픽 컨트롤러 (tc)가 특정 cgroup에서 시작된 패킷을 식별 할 수 있도록하는 클래스 식별자 (classid)로 네트워크 패킷에 태그를 지정합니다. 트래픽 컨트롤러는 다른 cgroup의 패킷에 다른 우선 순위를 할당하도록 구성 할 수 있습니다.

net_cls.classid : 0XAAAABBBB AAAA = major number (hex)
                         BBBB = minor number (hex)
        net_cls.classid contains a single value that indicates a traffic control handle. The value of classid read from the net_cls.classid file is presented in the decimal format while the value to be written to the file is expected in the hexadecimal format. e.g. 0X100001 = 10:1

net_prio :

네트워크 우선 순위 (net_prio) 서브 시스템은 다양한 cgroup 내의 애플리케이션에 대해 각 네트워크 인터페이스 당 네트워크 트래픽의 우선 순위를 동적으로 설정하는 방법을 제공합니다. 네트워크 우선 순위는 네트워크 트래픽에 할당되고 시스템 및 네트워크 장치에서 내부적으로 사용되는 번호입니다. 네트워크 우선 순위는 전송, 대기 또는 삭제 된 패킷을 구별하는 데 사용됩니다. 트래픽 컨트롤러 (tc)는 네트워크 우선 순위를 설정합니다.

net_prio.ifpriomap : networkinterface , priority (/cgroup/net_prio/iscsi/net_prio.ifpriomap)
        Contents of the net_prio.ifpriomap file can be modified by echoing a string into the file using the above format, for example:

            ~]# echo "eth0 5" > /cgroup/net_prio/iscsi/net_prio.ifpriomap

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.