diff --git a/src/sysboostd/aot.rs b/src/sysboostd/aot.rs index 712f3a71454e3eddba3dd81e218f9821b3abc2f1..b31b7453fd9e2a8859904635f1879442c4d0c6f4 100644 --- a/src/sysboostd/aot.rs +++ b/src/sysboostd/aot.rs @@ -111,6 +111,28 @@ pub fn set_app_link_flag(path: &String, is_set: bool) -> i32 { return ret; } +pub fn set_rto_link_flag(path: &String, is_set: bool) -> i32 { + let mut args: Vec = Vec::new(); + if is_set { + args.push("--set-rto".to_string()); + } else { + args.push("--unset-rto".to_string()); + } + + // 回滚场景, 路径是软链接要转换为真实路径 + let real_path = match fs::canonicalize(path) { + Ok(p) => p, + Err(e) => { + log::error!("get realpath failed: {}", e); + return -1; + } + }; + + args.push(format!("{}", real_path.to_string_lossy())); + let ret = run_child(SYSBOOST_PATH, &args); + return ret; +} + // 生成rto文件 // rto文件先生成到临时文件, 然后mv到最终路径, 避免并发操作文件问题 // sysboost --output=/usr/bin/bash.tmp.rto -static /usr/bin/bash lib1 lib2 diff --git a/src/sysboostd/bolt.rs b/src/sysboostd/bolt.rs index 0fd86f90f20fabff51309f058c739e10826710bf..784a695bc989ace0038b0d5688b0a7021315a935 100644 --- a/src/sysboostd/bolt.rs +++ b/src/sysboostd/bolt.rs @@ -9,11 +9,11 @@ // See the Mulan PSL v2 for more details. // Create: 2023-8-28 -use crate::common::set_thp; use crate::common::is_arch_x86_64; use crate::config::RtoConfig; use crate::lib::process_ext::run_child; use crate::config::get_config; +use crate::aot::set_rto_link_flag; use std::fs; use std::path::Path; @@ -59,25 +59,20 @@ fn bolt_optimize_bin(conf: &RtoConfig) -> i32 { return -1; } }; - let elf_bak_path = elf_path.with_extension("bak"); - match fs::copy(&elf_path, &elf_bak_path) { - Ok(_) => {} - Err(e) => { - log::error!("Copy failed: {}", e); - return -1; - } - } - args.push(elf_bak_path.to_str().unwrap().to_string()); - args.push("-o".to_string()); + let rto_path = elf_path.with_extension("rto"); args.push(elf.split_whitespace().collect()); - + args.push("-o".to_string()); + args.push(rto_path.to_str().unwrap().to_string()); + let real_profile_path = get_profile_path(conf); if real_profile_path != "" { args.push(format!("-data={}", real_profile_path)); } - - let ret = run_child("/usr/bin/llvm-bolt", &args); - + let mut ret = run_child("/usr/bin/llvm-bolt", &args); + if ret != 0 { + return ret; + } + ret = set_rto_link_flag(&rto_path.to_str().unwrap().to_string(), true); return ret; } @@ -140,10 +135,10 @@ pub fn bolt_optimize(conf: &RtoConfig) -> i32 { return ret; } else { let ret = bolt_optimize_bin(&conf); - // 如果优化程序是mysqld, 则开启透明大页 - if is_mysqld(conf) { - set_thp(); - } + // rto加载流程会使用大页功能,不需要开启系统透明大页 + // if is_mysqld(conf) { + // //set_thp(); + // } return ret; } }