mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
402c7584a8
HAVE_LARGE_PAGES was always Linux but now there is HAVE_SOLARIS_LARGE_PAGES in the code base. Innodb was using HAVE_LINUX_LARGE_PAGES so keep this consistent everywhere. Test plan: $ grep Hugepagesize: /proc/meminfo Hugepagesize: 2048 kB $ sudo sysctl vm.nr_hugepages=1024 vm.nr_hugepages = 1024 $ sudo sysctl kernel.shmmax=$(( 2 * 1024 *1024 * 1024 )) kernel.shmmax = 2147483648 No errors in ouput: $ sql/mysqld --skip-networking --datadir=/tmp/datadir --log-bin=/tmp/datadir/mysqlbin --socket /tmp/s.sock --lc-messages-dir=${PWD}/sql/share --verbose --large-pages=1 2018-03-23 12:51:18 139697428129984 [Note] sql/mysqld (mysqld 10.2.14-MariaDB-log) starting as process 25406 ... 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Uses event mutexes 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Compressed tables use zlib 1.2.11 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Using Linux native AIO 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Number of pools: 1 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Using SSE2 crc32 instructions 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Completed initialization of buffer pool 2018-03-23 12:51:18 139696883590912 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Highest supported file format is Barracuda. 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: 128 out of 128 rollback segments are active. 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Creating shared tablespace for temporary tables 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2018-03-23 12:51:18 139697428129984 [Note] InnoDB: 5.7.21 started; log sequence number 1620099 2018-03-23 12:51:18 139696713733888 [Note] InnoDB: Loading buffer pool(s) from /tmp/datadir/ib_buffer_pool 2018-03-23 12:51:18 139696713733888 [Note] InnoDB: Buffer pool(s) load completed at 180323 12:51:18 2018-03-23 12:51:18 139697428129984 [Note] Plugin 'FEEDBACK' is disabled. 2018-03-23 12:51:18 139697428129984 [Note] Reading of all Master_info entries succeded 2018-03-23 12:51:18 139697428129984 [Note] Added new Master_info '' to hash table 2018-03-23 12:51:18 139697428129984 [Note] sql/mysqld: ready for connections. Version: '10.2.14-MariaDB-log' socket: '/tmp/s.sock' port: 0 Source distribution $ grep -i huge /proc/25406/smaps | grep -v ' 0 kB' Private_Hugetlb: 8192 kB Private_Hugetlb: 2048 kB $ grep huge /proc/25406/numa_maps 7f0d74400000 default file=/SYSV00000000\040(deleted) huge 7f0dbd200000 default file=/SYSV00000000\040(deleted) huge dirty=4 N0=4 kernelpagesize_kB=2048 7f0dc5600000 default file=/SYSV00000000\040(deleted) huge 7f0dd1200000 default file=/SYSV00000000\040(deleted) huge dirty=1 N0=1 kernelpagesize_kB=2048 $ grep Huge /proc/meminfo AnonHugePages: 0 kB ShmemHugePages: 0 kB HugePages_Total: 940 HugePages_Free: 935 HugePages_Rsvd: 177 HugePages_Surp: 0 Hugepagesize: 2048 kB Ran again with --memlock (note needs ulimit -l > size) $ grep Huge /proc/meminfo AnonHugePages: 0 kB ShmemHugePages: 0 kB HugePages_Total: 940 HugePages_Free: 758 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB $ grep huge /proc/26020/numa_maps 7fe870400000 default file=/SYSV00000000\040(deleted) huge dirty=62 N0=62 kernelpagesize_kB=2048 7fe8b3a00000 default file=/SYSV00000000\040(deleted) huge dirty=66 N0=66 kernelpagesize_kB=2048 7fe8bd600000 default file=/SYSV00000000\040(deleted) huge dirty=53 N0=53 kernelpagesize_kB=2048 7fe8c8400000 default file=/SYSV00000000\040(deleted) huge dirty=1 N0=1 kernelpagesize_kB=2048 $ grep -i huge /proc/26020/smaps | grep -v ' 0 kB' Private_Hugetlb: 126976 kB Private_Hugetlb: 135168 kB Private_Hugetlb: 108544 kB Private_Hugetlb: 2048 kB
166 lines
4.2 KiB
C
166 lines
4.2 KiB
C
/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
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; version 2 of the License.
|
|
|
|
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
#include "mysys_priv.h"
|
|
|
|
#ifdef HAVE_LINUX_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 uchar* my_large_malloc_int(size_t size, myf my_flags);
|
|
static my_bool my_large_free_int(uchar* ptr);
|
|
|
|
/* 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
|
|
*/
|
|
|
|
uchar* my_large_malloc(size_t size, myf my_flags)
|
|
{
|
|
uchar* 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(uchar* ptr)
|
|
{
|
|
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_free_lock(ptr);
|
|
|
|
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)
|
|
{
|
|
MYSQL_FILE *f;
|
|
uint size = 0;
|
|
char buf[256];
|
|
DBUG_ENTER("my_get_large_page_size_int");
|
|
|
|
if (!(f= mysql_file_fopen(key_file_proc_meminfo, "/proc/meminfo",
|
|
O_RDONLY, MYF(MY_WME))))
|
|
goto finish;
|
|
|
|
while (mysql_file_fgets(buf, sizeof(buf), f))
|
|
if (sscanf(buf, "Hugepagesize: %u kB", &size))
|
|
break;
|
|
|
|
mysql_file_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 */
|
|
|
|
uchar* my_large_malloc_int(size_t size, myf my_flags)
|
|
{
|
|
int shmid;
|
|
uchar* ptr;
|
|
struct shmid_ds buf;
|
|
DBUG_ENTER("my_large_malloc_int");
|
|
|
|
/* Align block size to my_large_page_size */
|
|
size= MY_ALIGN(size, (size_t) my_large_page_size);
|
|
|
|
shmid = shmget(IPC_PRIVATE, size, SHM_HUGETLB | SHM_R | SHM_W);
|
|
if (shmid < 0)
|
|
{
|
|
if (my_flags & MY_WME)
|
|
fprintf(stderr,
|
|
"Warning: Failed to allocate %lu bytes from HugeTLB memory."
|
|
" errno %d\n", (ulong) size, errno);
|
|
|
|
DBUG_RETURN(NULL);
|
|
}
|
|
|
|
ptr = (uchar*) shmat(shmid, NULL, 0);
|
|
if (ptr == (uchar *) -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(uchar *ptr)
|
|
{
|
|
DBUG_ENTER("my_large_free_int");
|
|
DBUG_RETURN(shmdt(ptr) == 0);
|
|
}
|
|
#endif /* HAVE_DECL_SHM_HUGETLB */
|
|
|
|
#endif /* HAVE_LINUX_LARGE_PAGES */
|