sysmaster/backport-fix-enable-subtree_control-for-sub-cgroup-on-hongmen.patch

53 lines
2.0 KiB
Diff

From b95071b3d24ef2211b3fed059d31497cd62ccbb6 Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Thu, 24 Aug 2023 16:01:24 +0800
Subject: [PATCH] fix: enable subtree_control for sub cgroup on hongmeng
---
core/sysmaster/src/main.rs | 5 +++++
core/sysmaster/src/mount/setup.rs | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/core/sysmaster/src/main.rs b/core/sysmaster/src/main.rs
index 95aea65b..7d30fb64 100755
--- a/core/sysmaster/src/main.rs
+++ b/core/sysmaster/src/main.rs
@@ -146,6 +146,11 @@ fn initialize_runtime(self_recovery_enable: bool) -> Result<()> {
msg: format!("mount cgroup controllers failed: {}", e),
})?;
+ #[cfg(feature = "hongmeng")]
+ setup::enable_subtree_control(cgroup::CG_BASE_DIR).map_err(|e| Error::Other {
+ msg: format!("enable hongmeng resmgr subtree_control failed: {}", e),
+ })?;
+
set_child_reaper();
Ok(())
diff --git a/core/sysmaster/src/mount/setup.rs b/core/sysmaster/src/mount/setup.rs
index 953ff4d9..56efdac4 100755
--- a/core/sysmaster/src/mount/setup.rs
+++ b/core/sysmaster/src/mount/setup.rs
@@ -460,6 +460,18 @@ pub fn mount_cgroup_controllers() -> Result<()> {
Ok(())
}
+#[cfg(feature = "hongmeng")]
+/// enable memory controller for sub cgroup
+pub fn enable_subtree_control(cg_base_dir: &str) -> Result<()> {
+ /* hongmeng doesn't enable cgroup controller for sub cgroup. So when we create a directory under
+ * /run/sysmaster/cgroup, i.e. foo.service, the file /run/sysmaster/cgroup/foo.service/controllers
+ * is empty. If controllers file is empty, we can't migrate our process to this cgroup. To avoid
+ * this problem, we forcely enable memory controller for sub cgroup. */
+ let sub_tree_control = Path::new(cg_base_dir).join("subtree_control");
+ fs::write(sub_tree_control, "+memory").context(IoSnafu)?;
+ Ok(())
+}
+
// return the pair controller which will join with the original controller
fn pair_controller(controller: &str) -> Option<String> {
let mut pairs = HashMap::new();
--
2.30.2