diff --git a/bin/bolt.rs b/bin/bolt.rs index b40dfe7df75c1c52f5ef23622a6d08443fd83944..3c4db86c58dac0ac3ddec9e7613e65bd5c9de1fd 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 65ebc38e5e53c86ba91694ee41d246f3c3248b75..b0aeab56f6dadc97b4ca0e8a0c40dc22b8783123 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; +}