Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/tscore/ink_sys_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@

#include <sys/resource.h>

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();
4 changes: 2 additions & 2 deletions iocore/net/P_UnixNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "P_UnixNetVConnection.h"
#include "P_UnixPollDescriptor.h"
#include <limits>
#include "tscore/ink_sys_control.h"

NetHandler *get_NetHandler(EThread *t);
PollCont *get_PollCont(EThread *t);
Expand All @@ -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;

//
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion iocore/net/UnixNet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions proxy/logging/LogStandalone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "";

Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/records/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ target_link_libraries(records
ts::inkevent
ts::tscore
yaml-cpp::yaml-cpp
PRIVATE
ts::tsapi
)
24 changes: 12 additions & 12 deletions src/traffic_server/traffic_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<int>(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);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -1340,19 +1340,19 @@ adjust_sys_settings()

lim.rlim_cur = lim.rlim_max = static_cast<rlim_t>(maxfiles * file_max_pct);
if (setrlimit(RLIMIT_NOFILE, &lim) == 0 && getrlimit(RLIMIT_NOFILE, &lim) == 0) {
fds_limit = static_cast<int>(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<int>(lim.rlim_cur),
static_cast<int>(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<int>(lim.rlim_cur - THROTTLE_FD_HEADROOM)) {
lim.rlim_cur = (lim.rlim_max = static_cast<rlim_t>(cfg_fds_throttle + THROTTLE_FD_HEADROOM));
if (setrlimit(RLIMIT_NOFILE, &lim) == 0 && getrlimit(RLIMIT_NOFILE, &lim) == 0) {
fds_limit = static_cast<int>(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<int>(lim.rlim_cur),
static_cast<int>(lim.rlim_max));
}
Expand Down
17 changes: 17 additions & 0 deletions src/tscore/ink_sys_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down