-
Notifications
You must be signed in to change notification settings - Fork 50
feat: Linux Control Group version 2 API support cgroup v2 #1329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChangxinDong
wants to merge
18
commits into
aws-greengrass:main
Choose a base branch
from
ChangxinDong:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
58f4ec1
feat: linux control group version 2 API support cgroup v2
ChangxinDong 52800bd
Merge branch 'aws-greengrass:main' into main
ChangxinDong 1abc7cc
feat: linux control group version 2 API support cgroup v2
yiwenTS 5832fb2
feat: linux control group version 2 API support cgroup v2
ChangxinDong 8132b86
Merge branch 'aws-greengrass:main' into main
ChangxinDong 1b95b7d
feat: linux control group version 2 API support cgroup v2
ChangxinDong b8cd781
feat: linux control group version 2 API support cgroup v2
ChangxinDong 901efe1
Merge branch 'aws-greengrass:main' into main
ChangxinDong 58441a7
feat: linux control group version 2 API support cgroup v2
ChangxinDong 8ef0143
feat: linux control group version 2 API support cgroup v2
ChangxinDong ec2348b
feat: linux control group version 2 API support cgroup v2
yiwenTS 3db48d7
feat: linux control group version 2 API support cgroup v2
ChangxinDong 996d87c
Merge branch 'aws-greengrass:main' into main
ChangxinDong c1626ce
feat: linux control group version 2 API support cgroup v2
ChangxinDong acfe1eb
Merge branch 'aws-greengrass:main' into main
ChangxinDong 6004a64
feat: linux control group version 2 API support cgroup v2
ChangxinDong 936e8eb
Merge branch 'main' of ssh://github.com/ChangxinDong/aws-greengrass-n…
ChangxinDong 1a35f5d
Merge branch 'main' into main
junfuchen99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
126 changes: 126 additions & 0 deletions
126
src/main/java/com/aws/greengrass/util/platforms/unix/linux/CGroupSubSystemPaths.java
This file contains hidden or 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,126 @@ | ||
/* | ||
* 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 com.aws.greengrass.lifecyclemanager.GreengrassService; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@SuppressFBWarnings(value = "DMI_HARDCODED_ABSOLUTE_FILENAME", | ||
justification = "CGroupSubSystemPath virtual filesystem path cannot be relative") | ||
public interface CGroupSubSystemPaths { | ||
Path CGROUP_ROOT = Paths.get("/sys/fs/cgroup"); | ||
String GG_NAMESPACE = "greengrass"; | ||
String CGROUP_MEMORY_LIMITS = "memory.limit_in_bytes"; | ||
String CPU_CFS_PERIOD_US = "cpu.cfs_period_us"; | ||
String CPU_CFS_QUOTA_US = "cpu.cfs_quota_us"; | ||
String CGROUP_PROCS = "cgroup.procs"; | ||
String FREEZER_STATE_FILE = "freezer.state"; | ||
String CPU_MAX = "cpu.max"; | ||
String MEMORY_MAX = "memory.max"; | ||
String CGROUP_SUBTREE_CONTROL = "cgroup.subtree_control"; | ||
String CGROUP_FREEZE = "cgroup.freeze"; | ||
String MOUNT_PATH = "/proc/self/mounts"; | ||
String UNICODE_SPACE = "\\040"; | ||
|
||
default Path getRootPath() { | ||
return CGROUP_ROOT; | ||
} | ||
|
||
String rootMountCmd(); | ||
|
||
default String subsystemMountCmd() { | ||
return null; | ||
} | ||
|
||
Path getSubsystemRootPath(); | ||
|
||
default Path getSubsystemGGPath() { | ||
return getSubsystemRootPath().resolve(GG_NAMESPACE); | ||
} | ||
|
||
default Path getSubsystemComponentPath(String componentName) { | ||
return getSubsystemGGPath().resolve(componentName); | ||
} | ||
|
||
Path getComponentMemoryLimitPath(String componentName); | ||
|
||
default Path getComponentCpuPeriodPath(String componentName) { | ||
return null; | ||
} | ||
|
||
default Path getComponentCpuQuotaPath(String componentName) { | ||
return null; | ||
} | ||
|
||
default Path getCgroupProcsPath(String componentName) { | ||
return getSubsystemComponentPath(componentName).resolve(CGROUP_PROCS); | ||
} | ||
|
||
Path getCgroupFreezerStateFilePath(String componentName); | ||
|
||
default Path getRootSubTreeControlPath() { | ||
return null; | ||
} | ||
|
||
default Path getGGSubTreeControlPath() { | ||
return null; | ||
} | ||
|
||
default Path getComponentCpuMaxPath(String componentName) { | ||
return null; | ||
} | ||
|
||
default Path getCgroupFreezePath(String componentName) { | ||
return null; | ||
} | ||
ChangxinDong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
void initializeCgroup(GreengrassService component, LinuxPlatform platform) throws IOException; | ||
|
||
void handleCpuLimits(GreengrassService component, double cpu) throws IOException; | ||
|
||
void pauseComponentProcessesCore(GreengrassService component) throws IOException; | ||
|
||
void resumeComponentProcesses(GreengrassService component) throws IOException; | ||
|
||
/** | ||
* Get mounted paths. | ||
* | ||
* @return A set of String | ||
* @throws IOException IOException | ||
*/ | ||
default Set<String> getMountedPaths() throws IOException { | ||
Set<String> mountedPaths = new HashSet<>(); | ||
|
||
Path procMountsPath = Paths.get(MOUNT_PATH); | ||
List<String> mounts = Files.readAllLines(procMountsPath); | ||
for (String mount : mounts) { | ||
String[] split = mount.split(" "); | ||
// As reported in fstab(5) manpage, struct is: | ||
// 1st field is volume name | ||
// 2nd field is path with spaces escaped as \040 | ||
// 3rd field is fs type | ||
// 4th field is mount options | ||
// 5th field is used by dump(8) (ignored) | ||
// 6th field is fsck order (ignored) | ||
if (split.length < 6) { | ||
continue; | ||
} | ||
|
||
// We only need the path of the mounts to verify whether cgroup is mounted | ||
String path = split[1].replace(UNICODE_SPACE, " "); | ||
mountedPaths.add(path); | ||
} | ||
return mountedPaths; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.