Skip to content
/ server Public
Open
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
5 changes: 4 additions & 1 deletion extra/mariabackup/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4796,11 +4796,14 @@ static ulong xb_set_max_open_files(rlim_t max_file_limit)
goto end;
}

rlimit.rlim_cur = rlimit.rlim_max = max_file_limit;
rlimit.rlim_cur = max_file_limit;

if (setrlimit(RLIMIT_NOFILE, &rlimit)) {
/* Use original value */
max_file_limit = static_cast<ulong>(old_cur);

msg( "setrlimit failed %d %s limit S: %lu H: %lu",
errno, strerror(errno), rlimit.rlim_cur, rlimit.rlim_max);
} else {

rlimit.rlim_cur = 0; /* Safety if next call fails */
Expand Down
24 changes: 19 additions & 5 deletions mysys/my_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,37 @@ static uint set_max_open_files(uint max_file_limit)
{
old_cur= (uint) rlimit.rlim_cur;
DBUG_PRINT("info", ("rlim_cur: %u rlim_max: %u",
(uint) rlimit.rlim_cur,
(uint) rlimit.rlim_max));
(uint) rlimit.rlim_cur,
(uint) rlimit.rlim_max));
if ((ulonglong) rlimit.rlim_cur == (ulonglong) RLIM_INFINITY ||
rlimit.rlim_cur >= max_file_limit)
DBUG_RETURN(max_file_limit);
rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
if (setrlimit(RLIMIT_NOFILE, &rlimit))

/* Never lower the hard limit (rlim_max): lowering is irreversible for
non-privileged users and can prevent later increases. */
if ((ulonglong) rlimit.rlim_max != (ulonglong) RLIM_INFINITY &&
max_file_limit > rlimit.rlim_max)
{
/* Best effort: try raising hard limit only when needed. */
rlimit.rlim_max= max_file_limit;
}

/* Soft limit cannot exceed hard limit. */
rlimit.rlim_cur= max_file_limit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If setting new limit fails, does it also mean that soft limit remains bigger than hard limit ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hard limit is the ceiling, soft limit can never been higher


if (setrlimit(RLIMIT_NOFILE, &rlimit)) {
max_file_limit= old_cur; /* Use original value */
}
else
{
rlimit.rlim_cur= 0; /* Safety if next call fails */
(void) getrlimit(RLIMIT_NOFILE,&rlimit);
DBUG_PRINT("info", ("rlim_cur: %u", (uint) rlimit.rlim_cur));
if (rlimit.rlim_cur) /* If call didn't fail */
max_file_limit= (uint) rlimit.rlim_cur;
max_file_limit= (uint) rlimit.rlim_cur;
}
}

DBUG_PRINT("exit",("max_file_limit: %u", max_file_limit));
DBUG_RETURN(max_file_limit);
}
Expand Down