จำกัด หน่วยความจำและ cpu ด้วย lxc-execute


9

ฉันต้องการแยกกระบวนการโดยใช้ lxc-execute เป็นไปได้ไหมที่จะตั้งค่าแบนด์วิดท์, cpu และหน่วยความจำ

ฉันได้ดูผู้ชาย lxc.conf แต่ไม่พบว่าหมดแรง

คำตอบ:


23

ก่อนอื่นฉันอยากให้คุณเข้าใจกลุ่มที่เป็นส่วนหนึ่งของยูทิลิตี้ LXC เมื่อคุณมีภาชนะบรรจุคุณจะต้องแน่ใจว่าภาชนะต่าง ๆ ที่คุณใช้ทำภาชนะบรรจุหรือกระบวนการอื่น ๆ หมดภายใน ด้วยสิ่งนี้ในใจคนดีของโครงการ LXCaka Daniel Lezcano รวมกลุ่ม cg เข้ากับเทคโนโลยี container ที่เขาสร้างเช่น LXC ตอนนี้ถ้าคุณต้องการกำหนดการใช้งานทรัพยากรคุณจะต้องพิจารณาการกำหนดค่า CGROUP ของคุณ Cgroups ช่วยให้คุณสามารถจัดสรรทรัพยากรเช่นเวลา CPU, หน่วยความจำระบบ, แบนด์วิดท์เครือข่ายหรือการรวมกันของทรัพยากรเหล่านี้ - ระหว่างกลุ่มงาน (กระบวนการ) ที่ผู้ใช้กำหนดเองซึ่งทำงานอยู่บนระบบ คุณสามารถตรวจสอบ cgroups ที่คุณกำหนดค่า, ปฏิเสธการเข้าถึง cgroups ของทรัพยากรบางอย่างและแม้แต่กำหนดค่า cgroups ของคุณแบบไดนามิกบนระบบที่กำลังทำงานอยู่ บริการ cgconfig (กลุ่มควบคุมการกำหนดค่า) สามารถกำหนดค่าให้เริ่มต้นในเวลาบูตและสร้างกลุ่ม cg ที่กำหนดไว้ล่วงหน้าของคุณอีกครั้งจึงทำให้พวกเขาคงอยู่ตลอดการบูทใหม่ กลุ่ม Cg สามารถมีหลายลำดับชั้นเพราะแต่ละลำดับชั้นจะแนบกับระบบย่อยอย่างน้อยหนึ่งระบบ (หรือที่เรียกว่าตัวควบคุมทรัพยากรหรือตัวควบคุม) สิ่งนี้จะสร้างต้นไม้หลายต้นที่ไม่ได้เชื่อมต่อ มีเก้าระบบย่อยที่พร้อมใช้งาน

  1. blkio กำหนดขีด จำกัด ในการเข้าถึงอินพุต / เอาต์พุตบนอุปกรณ์บล็อก
  2. cpu scheduler สำหรับ cgroup task เข้าถึง CPU
  3. cpuacct สร้างรายงานสำหรับการใช้งาน CPU และ cgroup
  4. cpuset กำหนด CPU และหน่วยความจำให้กับ cgroup
  5. อุปกรณ์จัดการการเข้าถึงอุปกรณ์ตามงาน
  6. ตู้แช่แข็งระงับ / กลับมาทำงาน
  7. หน่วยความจำ จำกัด หน่วยความจำ
  8. แท็กเก็ตเครือข่าย 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.

CPUset:

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.limit_in_bytes: กำหนดจำนวนหน่วยความจำสูงสุดของผู้ใช้ สามารถใช้คำต่อท้ายเช่น K สำหรับกิโลและ M สำหรับ mega เป็นต้นซึ่ง จำกัด เฉพาะกลุ่มที่ต่ำกว่าในการสืบทอด เช่น root cgroup ไม่สามารถ จำกัด memory.memsw.limit_in_bytes: ตั้งค่าจำนวนสูงสุดสำหรับผลรวมของหน่วยความจำและการใช้งาน swap อีกครั้งสิ่งนี้ไม่สามารถ จำกัด กลุ่ม 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 พร้อมตัวระบุคลาส (classid) ที่อนุญาตให้ตัวควบคุมปริมาณการใช้งาน Linux (tc) ระบุแพ็คเก็ตที่มาจาก cgroup ที่เฉพาะเจาะจง Traffic Controller สามารถกำหนดค่าเพื่อกำหนดลำดับความสำคัญที่แตกต่างให้กับแพ็คเก็ตจาก cgroups ที่แตกต่างกัน

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:

ระบบย่อย Network Priority (net_prio) จัดเตรียมวิธีการกำหนดลำดับความสำคัญของทราฟฟิกเครือข่ายตามแต่ละเน็ตเวิร์กอินเตอร์เฟสสำหรับแอ็พพลิเคชันภายใน cgroups ต่างๆ ลำดับความสำคัญของเครือข่ายคือหมายเลขที่กำหนดให้กับทราฟฟิกเครือข่ายและใช้ภายในโดยระบบและอุปกรณ์เครือข่าย ลำดับความสำคัญของเครือข่ายใช้เพื่อแยกความแตกต่างของแพ็กเก็ตที่ถูกส่งเข้าคิวหรือทำตก traffic controller (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

0

เอกสารนี้มีประโยชน์มาก: http://doc.opensuse.org/documentation/html/openSUSE/opensuse-tuning/cha.tuning.cgroups.html

ข้อมูลอยู่ในเอกสารคู่มือเคอร์เนล Linux ที่นี่: / usr / src / linux / Documentation / cgroups


ในขณะที่สิ่งนี้อาจตอบคำถามในทางทฤษฎีมันก็ควรที่จะรวมส่วนสำคัญของคำตอบที่นี่และให้ลิงค์สำหรับการอ้างอิง
Léo Lam
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.