Module cgroups_rs::cgroup_builder
source · Expand description
This module allows the user to create a control group using the Builder pattern.
Example
The following example demonstrates how the control group builder looks like. The user
specifies the name of the control group (here: “hello”) and the hierarchy it belongs to (here:
a V1 hierarchy). Next, the user selects a subsystem by calling functions like memory(),
cpu() and devices(). The user can then add restrictions and details via subsystem-specific
calls. To finalize a subsystem, the user may call done(). Finally, if the control group build
is done and all requirements/restrictions have been specified, the control group can be created
by a call to build().
let h = cgroups_rs::hierarchies::auto();
let cgroup: Cgroup = CgroupBuilder::new("hello")
.memory()
.kernel_memory_limit(1024 * 1024)
.memory_hard_limit(1024 * 1024)
.done()
.cpu()
.shares(100)
.done()
.devices()
.device(1000, 10, DeviceType::Block, true,
vec![DevicePermissions::Read,
DevicePermissions::Write,
DevicePermissions::MkNod])
.device(6, 1, DeviceType::Char, false, vec![])
.done()
.network()
.class_id(1337)
.priority("eth0".to_string(), 100)
.priority("wl0".to_string(), 200)
.done()
.hugepages()
.limit("2M".to_string(), 0)
.limit("4M".to_string(), 4 * 1024 * 1024 * 100)
.limit("2G".to_string(), 2 * 1024 * 1024 * 1024)
.done()
.blkio()
.weight(123)
.leaf_weight(99)
.weight_device(6, 1, Some(100), Some(55))
.weight_device(6, 1, Some(100), Some(55))
.throttle_iops()
.read(6, 1, 10)
.write(11, 1, 100)
.throttle_bps()
.read(6, 1, 10)
.write(11, 1, 100)
.done()
.build(h).unwrap();Structs
- A builder that configures the blkio controller of a control group.
- A control group builder instance
- A builder that configures the cpuset & cpu controllers of a control group.
- A builder that configures the devices controller of a control group.
- A builder that configures the hugepages controller of a control group.
- A builder that configures the memory controller of a control group.
- A builder that configures the net_cls & net_prio controllers of a control group.
- A builder that configures the pid controller of a control group.