16 #include "mysys_priv.h"
17 #include "my_static.h"
35 #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
38 #define RLIM_INFINITY ((uint) 0xffffffff)
41 static uint set_max_open_files(uint max_file_limit)
45 DBUG_ENTER(
"set_max_open_files");
46 DBUG_PRINT(
"enter",(
"files: %u", max_file_limit));
48 if (!getrlimit(RLIMIT_NOFILE,&rlimit))
50 old_cur= (uint) rlimit.rlim_cur;
51 DBUG_PRINT(
"info", (
"rlim_cur: %u rlim_max: %u",
52 (uint) rlimit.rlim_cur,
53 (uint) rlimit.rlim_max));
54 if (rlimit.rlim_cur == RLIM_INFINITY)
55 rlimit.rlim_cur = max_file_limit;
56 if (rlimit.rlim_cur >= max_file_limit)
57 DBUG_RETURN(rlimit.rlim_cur);
58 rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
59 if (setrlimit(RLIMIT_NOFILE, &rlimit))
60 max_file_limit= old_cur;
64 (void) getrlimit(RLIMIT_NOFILE,&rlimit);
65 DBUG_PRINT(
"info", (
"rlim_cur: %u", (uint) rlimit.rlim_cur));
67 max_file_limit= (uint) rlimit.rlim_cur;
70 DBUG_PRINT(
"exit",(
"max_file_limit: %u", max_file_limit));
71 DBUG_RETURN(max_file_limit);
75 static uint set_max_open_files(uint max_file_limit)
78 return min(max_file_limit, OS_FILE_LIMIT);
94 uint my_set_max_open_files(uint files)
97 DBUG_ENTER(
"my_set_max_open_files");
98 DBUG_PRINT(
"enter",(
"files: %u my_file_limit: %u", files, my_file_limit));
101 files= set_max_open_files(MY_MIN(files, OS_FILE_LIMIT));
102 if (files <= MY_NFILE)
107 DBUG_RETURN(MY_NFILE);
110 memcpy((
char*) tmp, (
char*) my_file_info,
111 sizeof(*tmp) * MY_MIN(my_file_limit, files));
112 memset((tmp + my_file_limit), 0,
113 MY_MAX((
int) (files - my_file_limit), 0) *
sizeof(*tmp));
114 my_free_open_file_info();
116 my_file_limit= files;
117 DBUG_PRINT(
"exit",(
"files: %u", files));
122 void my_free_open_file_info()
124 DBUG_ENTER(
"my_free_file_info");
125 if (my_file_info != my_file_info_default)
128 memcpy((
char*) my_file_info_default, my_file_info,
129 sizeof(*my_file_info_default)* MY_NFILE);
130 my_free(my_file_info);
131 my_file_info= my_file_info_default;
132 my_file_limit= MY_NFILE;