diff options
author | unknown <monty@mashka.mysql.fi> | 2004-02-19 19:33:09 +0200 |
---|---|---|
committer | unknown <monty@mashka.mysql.fi> | 2004-02-19 19:33:09 +0200 |
commit | ddbb78809dcce02d649eae436c77799d7a76983e (patch) | |
tree | 86d1d367349c537e9cbd45f6bf0ba3c2315f1a59 /mysys | |
parent | 62cc89aad50b00c0ab1ef3e94c5a3467eb78eb70 (diff) | |
download | mariadb-git-ddbb78809dcce02d649eae436c77799d7a76983e.tar.gz |
Max open files handling moved to my_set_max_open_files()
This ensures that my_file_info takes this the max number of files into account and one can now use --open-files-limit on windows to increase number of used files up to 2048
client/client_priv.h:
Added --open-files-limit to mysqlbinlog
client/mysqlbinlog.cc:
Added --open-files-limit to mysqlbinlog
include/config-win.h:
Define that you can have up to 2048 files open on windows
include/my_global.h:
Allow override of OS_FILE_LIMIT
include/my_sys.h:
Cleanup
Added prototypes for my_set_max_open_files() and my_free_open_files()
libmysql/Makefile.shared:
Added my_file.c
myisam/myisamlog.c:
Use my_set_max_open_files()
mysys/Makefile.am:
Use my_file.c (for mysqlbinlog)
mysys/my_alloc.c:
Remove compiler warning
mysys/my_div.c:
MY_NFILE -> my_file_limit
mysys/my_dup.c:
MY_NFILE -> my_file_limit
mysys/my_fopen.c:
MY_NFILE -> my_file_limit
mysys/my_open.c:
MY_NFILE -> my_file_limit
mysys/my_static.c:
Allow changing of open files limit
mysys/my_static.h:
Allow changing of open files limit
sql/mysqld.cc:
Max open files handling moved to my_set_max_open_files()
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/Makefile.am | 4 | ||||
-rw-r--r-- | mysys/my_alloc.c | 2 | ||||
-rw-r--r-- | mysys/my_div.c | 2 | ||||
-rw-r--r-- | mysys/my_dup.c | 2 | ||||
-rw-r--r-- | mysys/my_file.c | 147 | ||||
-rw-r--r-- | mysys/my_fopen.c | 8 | ||||
-rw-r--r-- | mysys/my_open.c | 4 | ||||
-rw-r--r-- | mysys/my_static.c | 4 | ||||
-rw-r--r-- | mysys/my_static.h | 2 |
9 files changed, 163 insertions, 12 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am index bd508b8de12..eb6d21c360a 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -25,8 +25,8 @@ noinst_HEADERS = mysys_priv.h my_static.h \ my_os2cond.c my_os2dirsrch.c my_os2dirsrch.h \ my_os2dlfcn.c my_os2file64.c my_os2mutex.c \ my_os2thread.c my_os2tls.c -libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\ - mf_path.c mf_loadpath.c\ +libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c \ + mf_path.c mf_loadpath.c my_file.c \ my_open.c my_create.c my_dup.c my_seek.c my_read.c \ my_pread.c my_write.c \ mf_keycache.c mf_keycaches.c my_crc32.c \ diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 2961e57d28f..34a03391bc4 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -68,7 +68,7 @@ void init_alloc_root(MEM_ROOT *mem_root, uint block_size, */ void reset_root_defaults(MEM_ROOT *mem_root, uint block_size, - uint pre_alloc_size) + uint pre_alloc_size __attribute__((unused))) { mem_root->block_size= block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8; #if !(defined(HAVE_purify) && defined(EXTRA_DEBUG)) diff --git a/mysys/my_div.c b/mysys/my_div.c index 777ffe403d7..9141ff4fcc5 100644 --- a/mysys/my_div.c +++ b/mysys/my_div.c @@ -27,7 +27,7 @@ my_string my_filename(File fd) { DBUG_ENTER("my_filename"); - if (fd >= MY_NFILE) + if ((uint) fd >= (uint) my_file_limit) DBUG_RETURN((char*) "UNKNOWN"); if (fd >= 0 && my_file_info[fd].type != UNOPEN) { diff --git a/mysys/my_dup.c b/mysys/my_dup.c index df298780e3e..4b7434e29ea 100644 --- a/mysys/my_dup.c +++ b/mysys/my_dup.c @@ -32,7 +32,7 @@ File my_dup(File file, myf MyFlags) DBUG_ENTER("my_dup"); DBUG_PRINT("my",("file: %d MyFlags: %d", MyFlags)); fd = dup(file); - filename= (((int) file < MY_NFILE) ? + filename= (((uint) file < my_file_limit) ? my_file_info[(int) file].name : "Unknown"); DBUG_RETURN(my_register_filename(fd, filename, FILE_BY_DUP, EE_FILENOTFOUND, MyFlags)); diff --git a/mysys/my_file.c b/mysys/my_file.c new file mode 100644 index 00000000000..6a9d39cf944 --- /dev/null +++ b/mysys/my_file.c @@ -0,0 +1,147 @@ +/* Copyright (C) 2000 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include "mysys_priv.h" +#include "my_static.h" +#include <m_string.h> + +/* + set how many open files we want to be able to handle + + SYNOPSIS + set_maximum_open_files() + max_file_limit Files to open + + NOTES + The request may not fulfilled becasue of system limitations + + RETURN + Files available to open. + May be more or less than max_file_limit! +*/ + +#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE) && !defined(HAVE_mit_thread) + +#ifndef RLIM_INFINITY +#define RLIM_INFINITY ((uint) 0xffffffff) +#endif + +static uint set_max_open_files(uint max_file_limit) +{ + struct rlimit rlimit; + uint old_cur; + DBUG_ENTER("set_max_open_files"); + DBUG_PRINT("enter",("files: %u", max_file_limit)); + + if (!getrlimit(RLIMIT_NOFILE,&rlimit)) + { + old_cur= (uint) rlimit.rlim_cur; + DBUG_PRINT("info", ("rlim_cur: %u rlim_max: %u", + (uint) rlimit.rlim_cur, + (uint) rlimit.rlim_max)); + if (rlimit.rlim_cur == RLIM_INFINITY) + rlimit.rlim_cur = max_file_limit; + if (rlimit.rlim_cur >= max_file_limit) + DBUG_RETURN(rlimit.rlim_cur); /* purecov: inspected */ + rlimit.rlim_cur= rlimit.rlim_max= max_file_limit; + 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; + } + } + DBUG_PRINT("exit",("max_file_limit: %u", max_file_limit)); + DBUG_RETURN(max_file_limit); +} + +#elif defined (OS2) + +static uint set_max_open_files(uint max_file_limit) +{ + LONG cbReqCount; + ULONG cbCurMaxFH0; + APIRET ulrc; + DBUG_ENTER("set_max_open_files"); + + /* get current limit */ + cbReqCount = 0; + DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH0); + + /* set new limit */ + if ((cbReqCount = max_file_limit - cbCurMaxFH0) > 0) + ulrc = DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH); + DBUG_RETURN(cbCurMaxFH0); +} + +#else +static int set_max_open_files(uint max_file_limit) +{ + /* We don't know the limit. Return best guess */ + return min(max_file_limit, OS_FILE_LIMIT); +} +#endif + + +/* + Change number of open files + + SYNOPSIS: + my_set_max_open_files() + files Number of requested files + + RETURN + number of files available for open +*/ + +uint my_set_max_open_files(uint files) +{ + struct st_my_file_info *tmp; + DBUG_ENTER("my_set_max_open_files"); + DBUG_PRINT("enter",("files: %u my_file_limit: %u", files, my_file_limit)); + + files= set_max_open_files(min(files, OS_FILE_LIMIT)); + if (files <= MY_NFILE) + DBUG_RETURN(files); + + if (!(tmp= (struct st_my_file_info*) my_malloc(sizeof(*tmp) * files, + MYF(MY_WME)))) + DBUG_RETURN(MY_NFILE); + + /* Copy any initialized files */ + memcpy((char*) tmp, (char*) my_file_info, sizeof(*tmp) * my_file_limit); + my_free_open_file_info(); /* Free if already allocated */ + my_file_info= tmp; + my_file_limit= files; + DBUG_PRINT("exit",("files: %u", files)); + DBUG_RETURN(files); +} + + +void my_free_open_file_info() +{ + DBUG_ENTER("my_free_file_info"); + if (my_file_info != my_file_info_default) + { + my_free((char*) my_file_info, MYF(0)); + my_file_info= my_file_info_default; + } + DBUG_VOID_RETURN; +} diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c index d3b0b90f9c5..8906a288b11 100644 --- a/mysys/my_fopen.c +++ b/mysys/my_fopen.c @@ -42,7 +42,7 @@ FILE *my_fopen(const char *FileName, int Flags, myf MyFlags) on some OS (SUNOS). Actually the filename save isn't that important so we can ignore if this doesn't work. */ - if ((uint) fileno(fd) >= MY_NFILE) + if ((uint) fileno(fd) >= my_file_limit) { thread_safe_increment(my_stream_opened,&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ @@ -91,7 +91,7 @@ int my_fclose(FILE *fd, myf MyFlags) } else my_stream_opened--; - if ((uint) file < MY_NFILE && my_file_info[file].type != UNOPEN) + if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN) { my_file_info[file].type = UNOPEN; my_free(my_file_info[file].name, MYF(MY_ALLOW_ZERO_PTR)); @@ -123,11 +123,11 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) { pthread_mutex_lock(&THR_LOCK_open); my_stream_opened++; - if (Filedes < MY_NFILE) + if ((uint) Filedes < (uint) my_file_limit) { if (my_file_info[Filedes].type != UNOPEN) { - my_file_opened--; /* File is opened with my_open ! */ + my_file_opened--; /* File is opened with my_open ! */ } else { diff --git a/mysys/my_open.c b/mysys/my_open.c index 97f21724e1c..ca5c0d8683f 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -86,7 +86,7 @@ int my_close(File fd, myf MyFlags) if (MyFlags & (MY_FAE | MY_WME)) my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno); } - if ((uint) fd < MY_NFILE && my_file_info[fd].type != UNOPEN) + if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN) { my_free(my_file_info[fd].name, MYF(0)); #if defined(THREAD) && !defined(HAVE_PREAD) @@ -115,7 +115,7 @@ File my_register_filename(File fd, const char *FileName, enum file_type { if ((int) fd >= 0) { - if ((int) fd >= MY_NFILE) + if ((uint) fd >= my_file_limit) { #if defined(THREAD) && !defined(HAVE_PREAD) (void) my_close(fd,MyFlags); diff --git a/mysys/my_static.c b/mysys/my_static.c index b24ef28b7b1..5f034555156 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -34,7 +34,9 @@ int NEAR my_umask=0664, NEAR my_umask_dir=0777; #ifndef THREAD int NEAR my_errno=0; #endif -struct my_file_info my_file_info[MY_NFILE]= {{0,UNOPEN}}; +struct st_my_file_info my_file_info_default[MY_NFILE]= {{0,UNOPEN}}; +uint my_file_limit= MY_NFILE; +struct st_my_file_info *my_file_info= my_file_info_default; /* From mf_brkhant */ int NEAR my_dont_interrupt=0; diff --git a/mysys/my_static.h b/mysys/my_static.h index 08d1a93692f..bb408aa808d 100644 --- a/mysys/my_static.h +++ b/mysys/my_static.h @@ -68,6 +68,8 @@ extern byte *sf_min_adress,*sf_max_adress; extern uint sf_malloc_count; extern struct st_irem *sf_malloc_root; +extern struct st_my_file_info my_file_info_default[MY_NFILE]; + #if defined(THREAD) && !defined(__WIN__) extern sigset_t my_signals; /* signals blocked by mf_brkhant */ #endif |