From 0ae816c7fc69ac01a7760fb4b21e1b73d4f4a1f0 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Sat, 26 Aug 2023 16:58:38 -0500 Subject: [PATCH] untangle fds_limit global --- include/tscore/ink_sys_control.h | 2 ++ iocore/net/P_UnixNet.h | 4 ++-- iocore/net/UnixNet.cc | 1 - proxy/logging/LogStandalone.cc | 5 +---- src/records/CMakeLists.txt | 2 ++ src/traffic_server/traffic_server.cc | 24 ++++++++++++------------ src/tscore/ink_sys_control.cc | 17 +++++++++++++++++ 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/tscore/ink_sys_control.h b/include/tscore/ink_sys_control.h index e38871ddc1f..5cb35136aa8 100644 --- a/include/tscore/ink_sys_control.h +++ b/include/tscore/ink_sys_control.h @@ -25,5 +25,7 @@ #include +rlim_t ink_get_fds_limit(); +void ink_set_fds_limit(rlim_t); rlim_t ink_max_out_rlimit(int which); rlim_t ink_get_max_files(); diff --git a/iocore/net/P_UnixNet.h b/iocore/net/P_UnixNet.h index 99f236440d7..36e8b78623f 100644 --- a/iocore/net/P_UnixNet.h +++ b/iocore/net/P_UnixNet.h @@ -43,6 +43,7 @@ #include "P_UnixNetVConnection.h" #include "P_UnixPollDescriptor.h" #include +#include "tscore/ink_sys_control.h" NetHandler *get_NetHandler(EThread *t); PollCont *get_PollCont(EThread *t); @@ -57,7 +58,6 @@ extern ink_hrtime emergency_throttle_time; extern int net_connections_throttle; extern bool net_memory_throttle; extern int fds_throttle; -extern int fds_limit; extern ink_hrtime last_transient_accept_error; // @@ -145,7 +145,7 @@ change_net_connections_throttle(const char *token, RecDataT data_type, RecData v (void)data_type; (void)value; (void)data; - int throttle = fds_limit - THROTTLE_FD_HEADROOM; + int throttle = ink_get_fds_limit() - THROTTLE_FD_HEADROOM; if (fds_throttle == 0) { net_connections_throttle = fds_throttle; } else if (fds_throttle < 0) { diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc index 548396f9825..31bab7e230e 100644 --- a/iocore/net/UnixNet.cc +++ b/iocore/net/UnixNet.cc @@ -35,7 +35,6 @@ ink_hrtime last_shedding_warning; int net_connections_throttle; bool net_memory_throttle = false; int fds_throttle; -int fds_limit = 8000; ink_hrtime last_transient_accept_error; NetHandler::Config NetHandler::global_config; diff --git a/proxy/logging/LogStandalone.cc b/proxy/logging/LogStandalone.cc index 1cec2379a17..5c42abdd851 100644 --- a/proxy/logging/LogStandalone.cc +++ b/proxy/logging/LogStandalone.cc @@ -43,9 +43,6 @@ #define LOG_FILENAME_SIZE 255 -// Globals the rest of the system depends on. -int fds_limit; - static char error_tags[1024] = ""; static char action_tags[1024] = ""; @@ -67,7 +64,7 @@ logging_crash_handler(int signo, siginfo_t *info, void *ptr) static void init_system(bool notify_syslog) { - fds_limit = ink_max_out_rlimit(RLIMIT_NOFILE); + ink_set_fds_limit(ink_max_out_rlimit(RLIMIT_NOFILE)); signal_register_crash_handler(logging_crash_handler); if (notify_syslog) { diff --git a/src/records/CMakeLists.txt b/src/records/CMakeLists.txt index a36731b0c4d..f60c611243b 100644 --- a/src/records/CMakeLists.txt +++ b/src/records/CMakeLists.txt @@ -45,4 +45,6 @@ target_link_libraries(records ts::inkevent ts::tscore yaml-cpp::yaml-cpp + PRIVATE + ts::tsapi ) diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc index 069d2125389..8776801df3f 100644 --- a/src/traffic_server/traffic_server.cc +++ b/src/traffic_server/traffic_server.cc @@ -159,7 +159,6 @@ static int regression_list = 0; static int regression_level = REGRESSION_TEST_NONE; #endif static int auto_clear_hostdb_flag = 0; -extern int fds_limit; static char command_string[512] = ""; static char conf_dir[512] = ""; @@ -607,7 +606,7 @@ init_system() // // Delimit file Descriptors // - fds_limit = ink_max_out_rlimit(RLIMIT_NOFILE); + ink_set_fds_limit(ink_max_out_rlimit(RLIMIT_NOFILE)); } static void @@ -1221,9 +1220,10 @@ cmd_help(char *cmd) static void check_fd_limit() { - int fds_throttle = -1; - REC_ReadConfigInteger(fds_throttle, "proxy.config.net.connections_throttle"); - if (fds_throttle > fds_limit - THROTTLE_FD_HEADROOM) { + int check_throttle = -1; + int fds_limit = static_cast(ink_get_fds_limit()); + REC_ReadConfigInteger(check_throttle, "proxy.config.net.connections_throttle"); + if (check_throttle > fds_limit - THROTTLE_FD_HEADROOM) { int new_fds_throttle = fds_limit - THROTTLE_FD_HEADROOM; if (new_fds_throttle < 1) { ink_abort("too few file descriptors (%d) available", fds_limit); @@ -1233,7 +1233,7 @@ check_fd_limit() "connection throttle too high, " "%d (throttle) + %d (internal use) > %d (file descriptor limit), " "using throttle of %d", - fds_throttle, THROTTLE_FD_HEADROOM, fds_limit, new_fds_throttle); + check_throttle, THROTTLE_FD_HEADROOM, fds_limit, new_fds_throttle); Warning("%s", msg); } } @@ -1326,7 +1326,7 @@ static void adjust_sys_settings() { struct rlimit lim; - int fds_throttle = -1; + int cfg_fds_throttle = -1; rlim_t maxfiles; maxfiles = ink_get_max_files(); @@ -1340,19 +1340,19 @@ adjust_sys_settings() lim.rlim_cur = lim.rlim_max = static_cast(maxfiles * file_max_pct); if (setrlimit(RLIMIT_NOFILE, &lim) == 0 && getrlimit(RLIMIT_NOFILE, &lim) == 0) { - fds_limit = static_cast(lim.rlim_cur); + ink_set_fds_limit(lim.rlim_cur); syslog(LOG_NOTICE, "NOTE: RLIMIT_NOFILE(%d):cur(%d),max(%d)", RLIMIT_NOFILE, static_cast(lim.rlim_cur), static_cast(lim.rlim_max)); } } - REC_ReadConfigInteger(fds_throttle, "proxy.config.net.connections_throttle"); + REC_ReadConfigInteger(cfg_fds_throttle, "proxy.config.net.connections_throttle"); if (getrlimit(RLIMIT_NOFILE, &lim) == 0) { - if (fds_throttle > (int)(lim.rlim_cur - THROTTLE_FD_HEADROOM)) { - lim.rlim_cur = (lim.rlim_max = (rlim_t)(fds_throttle + THROTTLE_FD_HEADROOM)); + if (cfg_fds_throttle > static_cast(lim.rlim_cur - THROTTLE_FD_HEADROOM)) { + lim.rlim_cur = (lim.rlim_max = static_cast(cfg_fds_throttle + THROTTLE_FD_HEADROOM)); if (setrlimit(RLIMIT_NOFILE, &lim) == 0 && getrlimit(RLIMIT_NOFILE, &lim) == 0) { - fds_limit = static_cast(lim.rlim_cur); + ink_set_fds_limit(lim.rlim_cur); syslog(LOG_NOTICE, "NOTE: RLIMIT_NOFILE(%d):cur(%d),max(%d)", RLIMIT_NOFILE, static_cast(lim.rlim_cur), static_cast(lim.rlim_max)); } diff --git a/src/tscore/ink_sys_control.cc b/src/tscore/ink_sys_control.cc index 2601d6d4f09..2baa66b18c9 100644 --- a/src/tscore/ink_sys_control.cc +++ b/src/tscore/ink_sys_control.cc @@ -28,6 +28,23 @@ #include "tscore/ink_sys_control.h" #include "tscore/Diags.h" +namespace +{ +rlim_t global_fds_limit = 8000; +} + +rlim_t +ink_get_fds_limit() +{ + return global_fds_limit; +} + +void +ink_set_fds_limit(rlim_t limit) +{ + global_fds_limit = limit; +} + rlim_t ink_max_out_rlimit(int which) {