From 6c8c8fc8712e6dfcd5d73bb73b1ce40be2f8e93f Mon Sep 17 00:00:00 2001 From: ClawSeven Date: Thu, 21 Dec 2023 11:38:37 +0800 Subject: [PATCH] Reduce error log by downgrading unnecessary `error!` to `warn!` --- src/libos/src/entry.rs | 12 ++++++------ src/libos/src/syscall/mod.rs | 24 ++++++++++++++++++------ src/libos/src/vm/process_vm.rs | 8 +++++--- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/libos/src/entry.rs b/src/libos/src/entry.rs index 1f0668e7..778670b5 100644 --- a/src/libos/src/entry.rs +++ b/src/libos/src/entry.rs @@ -437,12 +437,12 @@ fn parse_host_files(file_buffer: *const host_file_buffer) -> Result { let resolv_conf_ptr = unsafe { (*file_buffer).resolv_conf_buf }; match parse_host_file(HostFile::ResolvConf, resolv_conf_ptr) { Err(e) => { - error!("failed to parse /etc/resolv.conf: {}", e.backtrace()); + warn!("failed to parse /etc/resolv.conf: {}", e.backtrace()); } Ok(resolv_conf_str) => { *RESOLV_CONF_STR.write().unwrap() = Some(resolv_conf_str); if let Err(e) = write_host_file(HostFile::ResolvConf) { - error!("failed to write /etc/resolv.conf: {}", e.backtrace()); + warn!("failed to write /etc/resolv.conf: {}", e.backtrace()); } } } @@ -450,13 +450,13 @@ fn parse_host_files(file_buffer: *const host_file_buffer) -> Result { let hostname_ptr = unsafe { (*file_buffer).hostname_buf }; match parse_host_file(HostFile::HostName, hostname_ptr) { Err(e) => { - error!("failed to parse /etc/hostname: {}", e.backtrace()); + warn!("failed to parse /etc/hostname: {}", e.backtrace()); } Ok(hostname_str) => { misc::init_nodename(&hostname_str); *HOSTNAME_STR.write().unwrap() = Some(hostname_str); if let Err(e) = write_host_file(HostFile::HostName) { - error!("failed to write /etc/hostname: {}", e.backtrace()); + warn!("failed to write /etc/hostname: {}", e.backtrace()); } } } @@ -464,12 +464,12 @@ fn parse_host_files(file_buffer: *const host_file_buffer) -> Result { let hosts_ptr = unsafe { (*file_buffer).hosts_buf }; match parse_host_file(HostFile::Hosts, hosts_ptr) { Err(e) => { - error!("failed to parse /etc/hosts: {}", e.backtrace()); + warn!("failed to parse /etc/hosts: {}", e.backtrace()); } Ok(hosts_str) => { *HOSTS_STR.write().unwrap() = Some(hosts_str); if let Err(e) = write_host_file(HostFile::Hosts) { - error!("failed to write /etc/hosts: {}", e.backtrace()); + warn!("failed to write /etc/hosts: {}", e.backtrace()); } } } diff --git a/src/libos/src/syscall/mod.rs b/src/libos/src/syscall/mod.rs index a7024982..cce00e42 100644 --- a/src/libos/src/syscall/mod.rs +++ b/src/libos/src/syscall/mod.rs @@ -689,26 +689,38 @@ fn do_syscall(user_context: &mut CpuContext) { let retval = match ret { Ok(retval) => retval as isize, Err(e) => { - let should_log_err = |errno| { + // let syscall_num = SyscallNum::try_from(num).unwrap(); + let should_log_err = |num, errno| { + let syscall_num = match SyscallNum::try_from(num) { + Ok(num) => num, + Err(e) => return true, + }; // If the log level requires every detail, don't ignore any error if log::max_level() == LevelFilter::Trace { return true; } - // All other log levels require errors to be outputed. But // some errnos are usually benign and may occur in a very high - // frequency. So we want to ignore them to keep noises at a - // minimum level in the log. + // frequency. So we want to lower them to warn level to keep noises + // at a minimum level in the error log. // // TODO: use a smarter, frequency-based strategy to decide whether // to suppress error messages. match errno { - EAGAIN | ETIMEDOUT => false, + EAGAIN | ETIMEDOUT | ENOENT | ENOTTY => false, + ENOSYS => match syscall_num { + SyscallNum::Getrusage => false, + SyscallNum::Madvise => false, + _ => true, + }, _ => true, } }; - if should_log_err(e.errno()) { + + if should_log_err(num, e.errno()) { error!("Error = {}", e.backtrace()); + } else { + warn!("Error = {}", e.backtrace()); } let retval = -(e.errno() as isize); diff --git a/src/libos/src/vm/process_vm.rs b/src/libos/src/vm/process_vm.rs index e637e42a..32acec6e 100644 --- a/src/libos/src/vm/process_vm.rs +++ b/src/libos/src/vm/process_vm.rs @@ -485,10 +485,12 @@ impl ProcessVM { *brk_guard = brk; Ok(brk) } else { - if brk < heap_start { - error!("New brk address is too low"); + if brk == 0 { + debug!("Try get current program break address") + } else if brk < heap_start { + warn!("New brk address is too low"); } else if brk > heap_end { - error!("New brk address is too high"); + warn!("New brk address is too high"); } Ok(*brk_guard)