From bbd9d0f98735f5bce9570899e0bef291f2ea36f3 Mon Sep 17 00:00:00 2001 From: Zhou Kang Date: Mon, 28 Aug 2023 08:18:17 +0000 Subject: [PATCH] open THP when app is mysqld --- bin/bolt.rs | 17 +++++++++++++++++ bin/common.rs | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/bin/bolt.rs b/bin/bolt.rs index b40dfe7..3c4db86 100644 --- a/bin/bolt.rs +++ b/bin/bolt.rs @@ -11,6 +11,7 @@ use crate::lib::process_ext::run_child; use crate::common::ARCH; +use crate::common::set_thp; use crate::config::RtoConfig; use std::fs; @@ -116,6 +117,18 @@ fn bolt_optimize_so(conf: &RtoConfig) -> i32 { return ret; } +fn is_mysqld(conf: &RtoConfig) -> bool { + match Path::new(&conf.elf_path).file_name() { + Some(app_file_name) => { + if app_file_name == "mysqld" { + return true; + } + }, + None => {}, + } + return false; +} + pub fn bolt_optimize(conf: &RtoConfig) -> i32 { if let Some(_p) = &conf.path.clone() { log::error!("Configuration file fail"); @@ -126,6 +139,10 @@ pub fn bolt_optimize(conf: &RtoConfig) -> i32 { return ret; } else { let ret = bolt_optimize_bin(&conf); + // 如果优化程序是mysqld, 则开启透明大页 + if is_mysqld(conf) { + set_thp(); + } return ret; } } diff --git a/bin/common.rs b/bin/common.rs index 65ebc38..b0aeab5 100644 --- a/bin/common.rs +++ b/bin/common.rs @@ -9,6 +9,8 @@ // See the Mulan PSL v2 for more details. // Create: 2023-8-26 +use crate::lib::process_ext::run_child; + pub const SYSBOOST_PATH: &str = "/usr/bin/sysboost"; #[cfg(target_arch = "x86_64")] @@ -16,3 +18,10 @@ pub const ARCH: &str = "x86_64"; #[cfg(target_arch = "aarch64")] pub const ARCH: &str = "aarch64"; + +// echo always > /sys/kernel/mm/transparent_hugepage/enabled +pub fn set_thp() -> i32 { + let args: Vec = Vec::new(); + let ret = run_child("echo always > /sys/kernel/mm/transparent_hugepage/enabled", &args); + return ret; +} -- Gitee