diff options
author | unknown <kaa@polly.local> | 2004-12-14 22:26:31 +0300 |
---|---|---|
committer | unknown <kaa@polly.local> | 2004-12-14 22:26:31 +0300 |
commit | 526fbcbbc551495d1fed482fbfa9b4f7496a935c (patch) | |
tree | 039af5ac48ea9b322014c4c858874b5452e38d9d /mysys | |
parent | 8d45c5f9d0ed290bb0bb880488b5ff1d5c2c7619 (diff) | |
download | mariadb-git-526fbcbbc551495d1fed482fbfa9b4f7496a935c.tar.gz |
Forward port of HugeTLB, InnoDB doublewrite and checksums patches to 5.0
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/Makefile.am | 2 | ||||
-rw-r--r-- | mysys/mf_keycache.c | 10 | ||||
-rw-r--r-- | mysys/my_largepage.c | 167 | ||||
-rw-r--r-- | mysys/my_static.c | 6 |
4 files changed, 179 insertions, 6 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 6a118df03cc..b0ca1b402ee 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -53,7 +53,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ my_net.c my_semaphore.c my_port.c my_sleep.c \ charset.c charset-def.c my_bitmap.c my_bit.c md5.c \ my_gethostbyname.c rijndael.c my_aes.c sha1.c \ - my_handler.c my_netware.c + my_handler.c my_netware.c my_largepage.c EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \ thr_mutex.c thr_rwlock.c libmysys_a_LIBADD = @THREAD_LOBJECTS@ diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 052d6c79ab9..bf7ed7ab6b6 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -341,8 +341,8 @@ int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, blocks--; /* Allocate memory for cache page buffers */ if ((keycache->block_mem= - my_malloc_lock((ulong) blocks * keycache->key_cache_block_size, - MYF(0)))) + my_large_malloc((ulong) blocks * keycache->key_cache_block_size, + MYF(MY_WME)))) { /* Allocate memory for blocks, hash_links and hash entries; @@ -351,7 +351,7 @@ int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, if ((keycache->block_root= (BLOCK_LINK*) my_malloc((uint) length, MYF(0)))) break; - my_free_lock(keycache->block_mem, MYF(0)); + my_large_free(keycache->block_mem, MYF(0)); } if (blocks < 8) { @@ -421,7 +421,7 @@ err: keycache->blocks= 0; if (keycache->block_mem) { - my_free_lock((gptr) keycache->block_mem, MYF(0)); + my_large_free((gptr) keycache->block_mem, MYF(0)); keycache->block_mem= NULL; } if (keycache->block_root) @@ -605,7 +605,7 @@ void end_key_cache(KEY_CACHE *keycache, my_bool cleanup) { if (keycache->block_mem) { - my_free_lock((gptr) keycache->block_mem, MYF(0)); + my_large_free((gptr) keycache->block_mem, MYF(0)); keycache->block_mem= NULL; my_free((gptr) keycache->block_root, MYF(0)); keycache->block_root= NULL; diff --git a/mysys/my_largepage.c b/mysys/my_largepage.c new file mode 100644 index 00000000000..0639c360b46 --- /dev/null +++ b/mysys/my_largepage.c @@ -0,0 +1,167 @@ +/* Copyright (C) 2004 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" + +#ifdef HAVE_LARGE_PAGES + +#ifdef HAVE_SYS_IPC_H +#include <sys/ipc.h> +#endif + +#ifdef HAVE_SYS_SHM_H +#include <sys/shm.h> +#endif + +static uint my_get_large_page_size_int(void); +static gptr my_large_malloc_int(uint size, myf my_flags); +static my_bool my_large_free_int(gptr ptr, myf my_flags); + +/* Gets the size of large pages from the OS */ + +uint my_get_large_page_size(void) +{ + uint size; + DBUG_ENTER("my_get_large_page_size"); + + if (!(size = my_get_large_page_size_int())) + fprintf(stderr, "Warning: Failed to determine large page size\n"); + + DBUG_RETURN(size); +} + +/* + General large pages allocator. + Tries to allocate memory from large pages pool and falls back to + my_malloc_lock() in case of failure +*/ + +gptr my_large_malloc(uint size, myf my_flags) +{ + gptr ptr; + DBUG_ENTER("my_large_malloc"); + + if (my_use_large_pages && my_large_page_size) + { + if ((ptr = my_large_malloc_int(size, my_flags)) != NULL) + DBUG_RETURN(ptr); + if (my_flags & MY_WME) + fprintf(stderr, "Warning: Using conventional memory pool\n"); + } + + DBUG_RETURN(my_malloc_lock(size, my_flags)); +} + +/* + General large pages deallocator. + Tries to deallocate memory as if it was from large pages pool and falls back + to my_free_lock() in case of failure + */ + +void my_large_free(gptr ptr, myf my_flags __attribute__((unused))) +{ + DBUG_ENTER("my_large_free"); + + /* + my_large_free_int() can only fail if ptr was not allocated with + my_large_malloc_int(), i.e. my_malloc_lock() was used so we should free it + with my_free_lock() + */ + if (!my_use_large_pages || !my_large_page_size || + !my_large_free_int(ptr, my_flags)) + my_free_lock(ptr, my_flags); + + DBUG_VOID_RETURN; +} + +#ifdef HUGETLB_USE_PROC_MEMINFO +/* Linux-specific function to determine the size of large pages */ + +uint my_get_large_page_size_int(void) +{ + FILE *f; + uint size = 0; + char buf[256]; + DBUG_ENTER("my_get_large_page_size_int"); + + if (!(f = my_fopen("/proc/meminfo", O_RDONLY, MYF(MY_WME)))) + goto finish; + + while (fgets(buf, sizeof(buf), f)) + if (sscanf(buf, "Hugepagesize: %u kB", &size)) + break; + + my_fclose(f, MYF(MY_WME)); + +finish: + DBUG_RETURN(size * 1024); +} +#endif /* HUGETLB_USE_PROC_MEMINFO */ + +#if HAVE_DECL_SHM_HUGETLB +/* Linux-specific large pages allocator */ + +gptr my_large_malloc_int(uint size, myf my_flags) +{ + int shmid; + gptr ptr; + struct shmid_ds buf; + DBUG_ENTER("my_large_malloc_int"); + + /* Align block size to my_large_page_size */ + size = ((size - 1) & ~(my_large_page_size - 1)) + my_large_page_size; + + shmid = shmget(IPC_PRIVATE, (size_t)size, SHM_HUGETLB | SHM_R | SHM_W); + if (shmid < 0) + { + if (my_flags & MY_WME) + fprintf(stderr, + "Warning: Failed to allocate %d bytes from HugeTLB memory." + " errno %d\n", size, errno); + + DBUG_RETURN(NULL); + } + + ptr = shmat(shmid, NULL, 0); + if (ptr == (void *)-1) + { + if (my_flags& MY_WME) + fprintf(stderr, "Warning: Failed to attach shared memory segment," + " errno %d\n", errno); + shmctl(shmid, IPC_RMID, &buf); + + DBUG_RETURN(NULL); + } + + /* + Remove the shared memory segment so that it will be automatically freed + after memory is detached or process exits + */ + shmctl(shmid, IPC_RMID, &buf); + + DBUG_RETURN(ptr); +} + +/* Linux-specific large pages deallocator */ + +my_bool my_large_free_int(byte *ptr, myf my_flags __attribute__((unused))) +{ + DBUG_ENTER("my_large_free_int"); + DBUG_RETURN(shmdt(ptr) == 0); +} +#endif /* HAVE_DECL_SHM_HUGETLB */ + +#endif /* HAVE_LARGE_PAGES */ diff --git a/mysys/my_static.c b/mysys/my_static.c index 5f034555156..57d41676390 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -61,6 +61,12 @@ const char *soundex_map= "01230120022455012623010202"; USED_MEM* my_once_root_block=0; /* pointer to first block */ uint my_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */ + /* from my_largepage.c */ +#ifdef HAVE_LARGE_PAGES +my_bool my_use_large_pages= 0; +uint my_large_page_size= 0; +#endif + /* from my_tempnam */ #if !defined(HAVE_TEMPNAM) || defined(HPUX11) int _my_tempnam_used=0; |