1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include "my_static.h"
21
set how many open files we want to be able to handle
24
set_maximum_open_files()
25
max_file_limit Files to open
28
The request may not fulfilled becasue of system limitations
31
Files available to open.
32
May be more or less than max_file_limit!
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); /* purecov: inspected */
58
rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
59
if (setrlimit(RLIMIT_NOFILE, &rlimit))
60
max_file_limit= old_cur; /* Use original value */
63
rlimit.rlim_cur= 0; /* Safety if next call fails */
64
(void) getrlimit(RLIMIT_NOFILE,&rlimit);
65
DBUG_PRINT("info", ("rlim_cur: %u", (uint) rlimit.rlim_cur));
66
if (rlimit.rlim_cur) /* If call didn't fail */
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 int set_max_open_files(uint max_file_limit)
77
/* We don't know the limit. Return best guess */
78
return min(max_file_limit, OS_FILE_LIMIT);
84
Change number of open files
87
my_set_max_open_files()
88
files Number of requested files
91
number of files available for open
94
uint my_set_max_open_files(uint files)
96
struct st_my_file_info *tmp;
97
DBUG_ENTER("my_set_max_open_files");
98
DBUG_PRINT("enter",("files: %u my_file_limit: %u", files, my_file_limit));
100
files= set_max_open_files(min(files, OS_FILE_LIMIT));
101
if (files <= MY_NFILE)
104
if (!(tmp= (struct st_my_file_info*) my_malloc(sizeof(*tmp) * files,
106
DBUG_RETURN(MY_NFILE);
108
/* Copy any initialized files */
109
memcpy((char*) tmp, (char*) my_file_info,
110
sizeof(*tmp) * min(my_file_limit, files));
111
bzero((char*) (tmp + my_file_limit),
112
max((int) (files- my_file_limit), 0)*sizeof(*tmp));
113
my_free_open_file_info(); /* Free if already allocated */
115
my_file_limit= files;
116
DBUG_PRINT("exit",("files: %u", files));
121
void my_free_open_file_info()
123
DBUG_ENTER("my_free_file_info");
124
if (my_file_info != my_file_info_default)
126
/* Copy data back for my_print_open_files */
127
memcpy((char*) my_file_info_default, my_file_info,
128
sizeof(*my_file_info_default)* MY_NFILE);
129
my_free((char*) my_file_info, MYF(0));
130
my_file_info= my_file_info_default;
131
my_file_limit= MY_NFILE;