-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Linux Control Group version 2 API support cgroup v2 (#1262)
- Loading branch information
1 parent
3981030
commit 1da81db
Showing
5 changed files
with
501 additions
and
1 deletion.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/main/java/com/aws/greengrass/util/platforms/unix/linux/CgroupV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.aws.greengrass.util.platforms.unix.linux; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Represents Linux cgroup v2. | ||
*/ | ||
@SuppressFBWarnings(value = "DMI_HARDCODED_ABSOLUTE_FILENAME", justification = "Cgroup virtual filesystem path " | ||
+ "cannot be relative") | ||
public final class CgroupV2 { | ||
|
||
private static final String CGROUP_ROOT = "/sys/fs/cgroup"; | ||
private static final String GG_NAMESPACE = "greengrass"; | ||
private static final String CPU_MAX = "cpu.max"; | ||
private static final String MEMORY_MAX = "memory.max"; | ||
private static final String CGROUP_PROCS = "cgroup.procs"; | ||
private static final String CGROUP_SUBTREE_CONTROL = "cgroup.subtree_control"; | ||
private static final String CGROUP_FREEZE = "cgroup.freeze"; | ||
|
||
private CgroupV2() { | ||
} | ||
|
||
public static Path getRootPath() { | ||
return Paths.get(CGROUP_ROOT); | ||
} | ||
|
||
public static String rootMountCmd() { | ||
return String.format("mount -t cgroup2 none %s", CGROUP_ROOT); | ||
} | ||
|
||
public static Path getSubsystemRootPath() { | ||
return Paths.get(CGROUP_ROOT); | ||
} | ||
|
||
public static Path getRootSubTreeControlPath() { | ||
return getSubsystemRootPath().resolve(CGROUP_SUBTREE_CONTROL); | ||
} | ||
|
||
public static Path getSubsystemGGPath() { | ||
return getSubsystemRootPath().resolve(GG_NAMESPACE); | ||
} | ||
|
||
public static Path getGGSubTreeControlPath() { | ||
return getSubsystemGGPath().resolve(CGROUP_SUBTREE_CONTROL); | ||
} | ||
|
||
public static Path getSubsystemComponentPath(String componentName) { | ||
return getSubsystemGGPath().resolve(componentName); | ||
} | ||
|
||
public static Path getComponentCpuMaxPath(String componentName) { | ||
return getSubsystemComponentPath(componentName).resolve(CPU_MAX); | ||
} | ||
|
||
public static Path getComponentMemoryMaxPath(String componentName) { | ||
return getSubsystemComponentPath(componentName).resolve(MEMORY_MAX); | ||
} | ||
|
||
public static Path getCgroupProcsPath(String componentName) { | ||
return getSubsystemComponentPath(componentName).resolve(CGROUP_PROCS); | ||
} | ||
|
||
public static Path getCgroupFreezePath(String componentName) { | ||
return getSubsystemComponentPath(componentName).resolve(CGROUP_FREEZE); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/aws/greengrass/util/platforms/unix/linux/CgroupV2FreezerState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.aws.greengrass.util.platforms.unix.linux; | ||
|
||
public enum CgroupV2FreezerState { | ||
THAWED(0), | ||
FROZEN(1); | ||
|
||
private int index; | ||
|
||
CgroupV2FreezerState(int index) { | ||
this.index = index; | ||
} | ||
|
||
/** | ||
* Get the index value associated with this CgroupV2FreezerState. | ||
* | ||
* @return the integer index value associated with this CgroupV2FreezerState. | ||
*/ | ||
public int getIndex() { | ||
return index; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.