Skip to content

Commit

Permalink
YARN-11672. Create a CgroupHandler implementation for cgroup v2 (apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
brumi1024 authored Apr 24, 2024
1 parent 23286b0 commit 5d0a40c
Show file tree
Hide file tree
Showing 9 changed files with 1,364 additions and 646 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,76 @@
public interface CGroupsHandler {

/**
* List of supported cgroup subsystem types.
* List of supported cgroup controller types. The two boolean variables denote whether
* the controller is valid in v1, v2 or both.
*/
enum CGroupController {
CPU("cpu"),
NET_CLS("net_cls"),
BLKIO("blkio"),
MEMORY("memory"),
CPUACCT("cpuacct"),
CPUSET("cpuset"),
FREEZER("freezer"),
DEVICES("devices");
NET_CLS("net_cls", true, false),
BLKIO("blkio", true, false),
CPUACCT("cpuacct", true, false),
FREEZER("freezer", true, false),
DEVICES("devices", true, false),

// v2 specific
IO("io", false, true),

// present in v1 and v2
CPU("cpu", true, true),
CPUSET("cpuset", true, true),
MEMORY("memory", true, true);

private final String name;
private final boolean inV1;
private final boolean inV2;

CGroupController(String name) {
CGroupController(String name, boolean inV1, boolean inV2) {
this.name = name;
this.inV1 = inV1;
this.inV2 = inV2;
}

public String getName() {
return name;
}

public boolean isInV1() {
return inV1;
}

public boolean isInV2() {
return inV2;
}

/**
* Get the list of valid cgroup names.
* @return The set of cgroup name strings
* Returns a set of valid cgroup controller names for v1.
* @return a set of valid cgroup controller names for v1.
*/
public static Set<String> getValidCGroups() {
public static Set<String> getValidV1CGroups() {
HashSet<String> validCgroups = new HashSet<>();
for (CGroupController controller : CGroupController.values()) {
validCgroups.add(controller.getName());
if (controller.isInV1()) {
validCgroups.add(controller.getName());
}
}
return validCgroups;
}
}

String CGROUP_PROCS_FILE = "cgroup.procs";
String CGROUP_PARAM_CLASSID = "classid";
String CGROUP_PARAM_BLKIO_WEIGHT = "weight";
/**
* Returns a set of valid cgroup controller names for v2.
* @return a set of valid cgroup controller names for v2.
*/
public static Set<String> getValidV2CGroups() {
HashSet<String> validCgroups = new HashSet<>();
for (CGroupController controller : CGroupController.values()) {
if (controller.isInV2()) {
validCgroups.add(controller.getName());
}
}
return validCgroups;
}
}

// v1 specific params
String CGROUP_PARAM_MEMORY_HARD_LIMIT_BYTES = "limit_in_bytes";
String CGROUP_PARAM_MEMORY_SWAP_HARD_LIMIT_BYTES = "memsw.limit_in_bytes";
String CGROUP_PARAM_MEMORY_SOFT_LIMIT_BYTES = "soft_limit_in_bytes";
Expand All @@ -84,12 +115,19 @@ public static Set<String> getValidCGroups() {
String CGROUP_PARAM_MEMORY_MEMSW_USAGE_BYTES = "memsw.usage_in_bytes";
String CGROUP_NO_LIMIT = "-1";
String UNDER_OOM = "under_oom 1";


String CGROUP_CPU_PERIOD_US = "cfs_period_us";
String CGROUP_CPU_QUOTA_US = "cfs_quota_us";
String CGROUP_CPU_SHARES = "shares";

// v2 specific params
String CGROUP_CONTROLLERS_FILE = "cgroup.controllers";
String CGROUP_SUBTREE_CONTROL_FILE = "cgroup.subtree_control";

// present in v1 and v2
String CGROUP_PROCS_FILE = "cgroup.procs";
String CGROUP_PARAM_CLASSID = "classid";
String CGROUP_PARAM_BLKIO_WEIGHT = "weight";

/**
* Mounts or initializes a cgroup controller.
* @param controller - the controller being initialized
Expand Down Expand Up @@ -125,6 +163,12 @@ void deleteCGroup(CGroupController controller, String cGroupId) throws
*/
String getControllerPath(CGroupController controller);

/**
* Gets the valid cgroup controller names based on the version used.
* @return a set containing the valid controller names for the used cgroup version.
*/
Set<String> getValidCGroups();

/**
* Gets the relative path for the cgroup, independent of a controller, for a
* given cgroup id.
Expand Down
Loading

0 comments on commit 5d0a40c

Please sign in to comment.