Commit f120a15b authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-19212 4GB Limit on large_pages - integer overflow

os_mem_alloc_large(): Invoke the macro ut_2pow_round() with the
correct argument type.

innobase_large_page_size, innobase_use_large_pages,
os_use_large_pages, os_large_page_size: Remove.
Simply refer to opt_large_page_size, my_use_large_pages.
parent caa8c20a
......@@ -221,8 +221,6 @@ const char *defaults_group = "mysqld";
#define HA_INNOBASE_ROWS_IN_TABLE 10000 /* to get optimization right */
#define HA_INNOBASE_RANGE_COUNT 100
ulong innobase_large_page_size = 0;
/* The default values for the following, type long or longlong, start-up
parameters are declared in mysqld.cc: */
......@@ -247,7 +245,6 @@ affects Windows: */
char* innobase_unix_file_flush_method;
my_bool innobase_use_doublewrite;
my_bool innobase_use_large_pages;
my_bool innobase_file_per_table;
my_bool innobase_locks_unsafe_for_binlog;
my_bool innobase_rollback_on_timeout;
......@@ -1919,8 +1916,6 @@ innodb_init_param(void)
srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite;
os_use_large_pages = (ibool) innobase_use_large_pages;
os_large_page_size = (ulint) innobase_large_page_size;
row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
srv_file_per_table = (my_bool) innobase_file_per_table;
......
......@@ -1566,7 +1566,7 @@ buf_chunk_init(
chunk->blocks = (buf_block_t*) chunk->mem;
/* Align a pointer to the first frame. Note that when
os_large_page_size is smaller than UNIV_PAGE_SIZE,
opt_large_page_size is smaller than UNIV_PAGE_SIZE,
we may allocate one fewer block than requested. When
it is bigger, we may allocate more blocks than requested. */
......
......@@ -4265,12 +4265,6 @@ innobase_init(
innodb_log_checksums = innodb_log_checksums_func_update(
NULL, innodb_log_checksums);
#ifdef HAVE_LINUX_LARGE_PAGES
if ((os_use_large_pages = my_use_large_pages)) {
os_large_page_size = opt_large_page_size;
}
#endif
row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog;
......
/*****************************************************************************
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2019, MariaDB Corporation.
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
......@@ -42,12 +42,6 @@ typedef unsigned long int os_process_id_t;
system with os_mem_alloc_large(). */
extern ulint os_total_large_mem_allocated;
/** Whether to use large pages in the buffer pool */
extern my_bool os_use_large_pages;
/** Large page size. This may be a boot-time option on some platforms */
extern uint os_large_page_size;
/** Converts the current process id to a number.
@return process id as a number */
ulint
......
/*****************************************************************************
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2019, MariaDB Corporation.
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
......@@ -25,6 +26,9 @@ Created 9/30/1995 Heikki Tuuri
*******************************************************/
#include "univ.i"
#ifdef HAVE_LINUX_LARGE_PAGES
# include "mysqld.h"
#endif
/* FreeBSD for example has only MAP_ANON, Linux has MAP_ANONYMOUS and
MAP_ANON but MAP_ANON is marked as deprecated */
......@@ -38,12 +42,6 @@ MAP_ANON but MAP_ANON is marked as deprecated */
system with os_mem_alloc_large(). */
ulint os_total_large_mem_allocated = 0;
/** Whether to use large pages in the buffer pool */
my_bool os_use_large_pages;
/** Large page size. This may be a boot-time option on some platforms */
uint os_large_page_size;
/** Converts the current process id to a number.
@return process id as a number */
ulint
......@@ -66,18 +64,18 @@ os_mem_alloc_large(
{
void* ptr;
ulint size;
#if defined HAVE_LINUX_LARGE_PAGES && defined UNIV_LINUX
#ifdef HAVE_LINUX_LARGE_PAGES
int shmid;
struct shmid_ds buf;
if (!os_use_large_pages || !os_large_page_size) {
if (!my_use_large_pages || !opt_large_page_size) {
goto skip;
}
/* Align block size to os_large_page_size */
ut_ad(ut_is_2pow(os_large_page_size));
size = ut_2pow_round(*n + (os_large_page_size - 1),
os_large_page_size);
/* Align block size to opt_large_page_size */
ut_ad(ut_is_2pow(opt_large_page_size));
size = ut_2pow_round(*n + opt_large_page_size - 1,
ulint(opt_large_page_size));
shmid = shmget(IPC_PRIVATE, (size_t) size, SHM_HUGETLB | SHM_R | SHM_W);
if (shmid < 0) {
......@@ -109,7 +107,7 @@ os_mem_alloc_large(
ib::warn() << "Using conventional memory pool";
skip:
#endif /* HAVE_LINUX_LARGE_PAGES && UNIV_LINUX */
#endif /* HAVE_LINUX_LARGE_PAGES */
#ifdef _WIN32
SYSTEM_INFO system_info;
......@@ -161,13 +159,13 @@ os_mem_free_large(
{
ut_a(os_total_large_mem_allocated >= size);
#if defined HAVE_LINUX_LARGE_PAGES && defined UNIV_LINUX
if (os_use_large_pages && os_large_page_size && !shmdt(ptr)) {
#ifdef HAVE_LINUX_LARGE_PAGES
if (my_use_large_pages && opt_large_page_size && !shmdt(ptr)) {
my_atomic_addlint(
&os_total_large_mem_allocated, -size);
return;
}
#endif /* HAVE_LINUX_LARGE_PAGES && UNIV_LINUX */
#endif /* HAVE_LINUX_LARGE_PAGES */
#ifdef _WIN32
/* When RELEASE memory, the size parameter must be 0.
Do not use MEM_RELEASE with MEM_DECOMMIT. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment