Rechercher dans le manuel MySQL
15.8.3.1 Configuring InnoDB Buffer Pool Size
You can configure InnoDB
buffer pool size
offline (at startup) or online, while the server is running.
Behavior described in this section applies to both methods. For
additional information about configuring buffer pool size
online, see Configuring InnoDB Buffer Pool Size Online.
When increasing or decreasing
innodb_buffer_pool_size
, the
operation is performed in chunks. Chunk size is defined by the
innodb_buffer_pool_chunk_size
configuration option, which has a default of
128M
. For more information, see
Configuring InnoDB Buffer Pool Chunk Size.
Buffer pool size must always be equal to or a multiple of
innodb_buffer_pool_chunk_size
*
innodb_buffer_pool_instances
.
If you configure
innodb_buffer_pool_size
to a
value that is not equal to or a multiple of
innodb_buffer_pool_chunk_size
*
innodb_buffer_pool_instances
,
buffer pool size is automatically adjusted to a value that is
equal to or a multiple of
innodb_buffer_pool_chunk_size
*
innodb_buffer_pool_instances
.
In the following example,
innodb_buffer_pool_size
is set
to 8G
, and
innodb_buffer_pool_instances
is
set to 16
.
innodb_buffer_pool_chunk_size
is 128M
, which is the default value.
8G
is a valid
innodb_buffer_pool_size
value
because 8G
is a multiple of
innodb_buffer_pool_instances=16
*
innodb_buffer_pool_chunk_size=128M
,
which is 2G
.
shell> mysqld --innodb-buffer-pool-size=8G --innodb-buffer-pool-instances=16
- +------------------------------------------+
- | @@innodb_buffer_pool_size/1024/1024/1024 |
- +------------------------------------------+
- | 8.000000000000 |
- +------------------------------------------+
In this example,
innodb_buffer_pool_size
is set
to 9G
, and
innodb_buffer_pool_instances
is
set to 16
.
innodb_buffer_pool_chunk_size
is 128M
, which is the default value. In this
case, 9G
is not a multiple of
innodb_buffer_pool_instances=16
*
innodb_buffer_pool_chunk_size=128M
,
so innodb_buffer_pool_size
is
adjusted to 10G
, which is a multiple of
innodb_buffer_pool_chunk_size
*
innodb_buffer_pool_instances
.
shell> mysqld --innodb-buffer-pool-size=9G --innodb-buffer-pool-instances=16
- +------------------------------------------+
- | @@innodb_buffer_pool_size/1024/1024/1024 |
- +------------------------------------------+
- | 10.000000000000 |
- +------------------------------------------+
Configuring InnoDB Buffer Pool Chunk Size
innodb_buffer_pool_chunk_size
can be increased or decreased in 1MB (1048576 byte) units but
can only be modified at startup, in a command line string or
in a MySQL configuration file.
Command line:
shell> mysqld --innodb-buffer-pool-chunk-size=134217728
Configuration file:
[mysqld]
innodb_buffer_pool_chunk_size=134217728
The following conditions apply when altering
innodb_buffer_pool_chunk_size
:
If the new
innodb_buffer_pool_chunk_size
value *innodb_buffer_pool_instances
is larger than the current buffer pool size when the buffer pool is initialized,innodb_buffer_pool_chunk_size
is truncated toinnodb_buffer_pool_size
/innodb_buffer_pool_instances
.For example, if the buffer pool is initialized with a size of
2GB
(2147483648 bytes),4
buffer pool instances, and a chunk size of1GB
(1073741824 bytes), chunk size is truncated to a value equal toinnodb_buffer_pool_size
/innodb_buffer_pool_instances
, as shown below:shell> mysqld --innodb-buffer-pool-size=2147483648 --innodb-buffer-pool-instances=4 --innodb-buffer-pool-chunk-size=1073741824;
- +---------------------------+
- | @@innodb_buffer_pool_size |
- +---------------------------+
- | 2147483648 |
- +---------------------------+
- +--------------------------------+
- | @@innodb_buffer_pool_instances |
- +--------------------------------+
- | 4 |
- +--------------------------------+
- # Chunk size was set to 1GB (1073741824 bytes) on startup but was
- # truncated to innodb_buffer_pool_size / innodb_buffer_pool_instances
- +---------------------------------+
- | @@innodb_buffer_pool_chunk_size |
- +---------------------------------+
- | 536870912 |
- +---------------------------------+
Buffer pool size must always be equal to or a multiple of
innodb_buffer_pool_chunk_size
*innodb_buffer_pool_instances
. If you alterinnodb_buffer_pool_chunk_size
,innodb_buffer_pool_size
is automatically adjusted to a value that is equal to or a multiple ofinnodb_buffer_pool_chunk_size
*innodb_buffer_pool_instances
. The adjustment occurs when the buffer pool is initialized. This behavior is demonstrated in the following example:- # The buffer pool has a default size of 128MB (134217728 bytes)
- +---------------------------+
- | @@innodb_buffer_pool_size |
- +---------------------------+
- | 134217728 |
- +---------------------------+
- # The chunk size is also 128MB (134217728 bytes)
- +---------------------------------+
- | @@innodb_buffer_pool_chunk_size |
- +---------------------------------+
- | 134217728 |
- +---------------------------------+
- # There is a single buffer pool instance
- +--------------------------------+
- | @@innodb_buffer_pool_instances |
- +--------------------------------+
- | 1 |
- +--------------------------------+
- # Chunk size is decreased by 1MB (1048576 bytes) at startup
- # (134217728 - 1048576 = 133169152):
- shell> mysqld --innodb-buffer-pool-chunk-size=133169152
- +---------------------------------+
- | @@innodb_buffer_pool_chunk_size |
- +---------------------------------+
- | 133169152 |
- +---------------------------------+
- # Buffer pool size increases from 134217728 to 266338304
- # Buffer pool size is automatically adjusted to a value that is equal to
- # or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
- +---------------------------+
- | @@innodb_buffer_pool_size |
- +---------------------------+
- | 266338304 |
- +---------------------------+
This example demonstrates the same behavior but with multiple buffer pool instances:
- # The buffer pool has a default size of 2GB (2147483648 bytes)
- +---------------------------+
- | @@innodb_buffer_pool_size |
- +---------------------------+
- | 2147483648 |
- +---------------------------+
- # The chunk size is .5 GB (536870912 bytes)
- +---------------------------------+
- | @@innodb_buffer_pool_chunk_size |
- +---------------------------------+
- | 536870912 |
- +---------------------------------+
- # There are 4 buffer pool instances
- +--------------------------------+
- | @@innodb_buffer_pool_instances |
- +--------------------------------+
- | 4 |
- +--------------------------------+
- # Chunk size is decreased by 1MB (1048576 bytes) at startup
- # (536870912 - 1048576 = 535822336):
- shell> mysqld --innodb-buffer-pool-chunk-size=535822336
- +---------------------------------+
- | @@innodb_buffer_pool_chunk_size |
- +---------------------------------+
- | 535822336 |
- +---------------------------------+
- # Buffer pool size increases from 2147483648 to 4286578688
- # Buffer pool size is automatically adjusted to a value that is equal to
- # or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances
- +---------------------------+
- | @@innodb_buffer_pool_size |
- +---------------------------+
- | 4286578688 |
- +---------------------------+
Care should be taken when changing
innodb_buffer_pool_chunk_size
, as changing this value can increase the size of the buffer pool, as shown in the examples above. Before you changeinnodb_buffer_pool_chunk_size
, calculate the effect oninnodb_buffer_pool_size
to ensure that the resulting buffer pool size is acceptable.
To avoid potential performance issues, the number of chunks
(innodb_buffer_pool_size
/
innodb_buffer_pool_chunk_size
)
should not exceed 1000.
The innodb_buffer_pool_size
configuration option can be set dynamically using a
SET
statement, allowing you to
resize the buffer pool without restarting the server. For
example:
Active transactions and operations performed through
InnoDB
APIs should be completed before
resizing the buffer pool. When initiating a resizing
operation, the operation does not start until all active
transactions are completed. Once the resizing operation is in
progress, new transactions and operations that require access
to the buffer pool must wait until the resizing operation
finishes. The exception to the rule is that concurrent access
to the buffer pool is permitted while the buffer pool is
defragmented and pages are withdrawn when buffer pool size is
decreased. A drawback of allowing concurrent access is that it
could result in a temporary shortage of available pages while
pages are being withdrawn.
Nested transactions could fail if initiated after the buffer pool resizing operation begins.
The
Innodb_buffer_pool_resize_status
reports buffer pool resizing progress. For example:
- +----------------------------------+----------------------------------+
- +----------------------------------+----------------------------------+
- +----------------------------------+----------------------------------+
Buffer pool resizing progress is also logged in the server error log. This example shows notes that are logged when increasing the size of the buffer pool:
[Note] InnoDB: Resizing buffer pool from 134217728 to 4294967296. (unit=134217728)
[Note] InnoDB: disabled adaptive hash index.
[Note] InnoDB: buffer pool 0 : 31 chunks (253952 blocks) was added.
[Note] InnoDB: buffer pool 0 : hash tables were resized.
[Note] InnoDB: Resized hash tables at lock_sys, adaptive hash index, dictionary.
[Note] InnoDB: completed to resize buffer pool from 134217728 to 4294967296.
[Note] InnoDB: re-enabled adaptive hash index.
This example shows notes that are logged when decreasing the size of the buffer pool:
[Note] InnoDB: Resizing buffer pool from 4294967296 to 134217728. (unit=134217728)
[Note] InnoDB: disabled adaptive hash index.
[Note] InnoDB: buffer pool 0 : start to withdraw the last 253952 blocks.
[Note] InnoDB: buffer pool 0 : withdrew 253952 blocks from free list. tried to relocate 0 pages.
(253952/253952)
[Note] InnoDB: buffer pool 0 : withdrawn target 253952 blocks.
[Note] InnoDB: buffer pool 0 : 31 chunks (253952 blocks) was freed.
[Note] InnoDB: buffer pool 0 : hash tables were resized.
[Note] InnoDB: Resized hash tables at lock_sys, adaptive hash index, dictionary.
[Note] InnoDB: completed to resize buffer pool from 4294967296 to 134217728.
[Note] InnoDB: re-enabled adaptive hash index.
The resizing operation is performed by a background thread. When increasing the size of the buffer pool, the resizing operation:
Adds pages in
chunks
(chunk size is defined byinnodb_buffer_pool_chunk_size
)Coverts hash tables, lists, and pointers to use new addresses in memory
Adds new pages to the free list
While these operations are in progress, other threads are blocked from accessing the buffer pool.
When decreasing the size of the buffer pool, the resizing operation:
Defragments the buffer pool and withdraws (frees) pages
Removes pages in
chunks
(chunk size is defined byinnodb_buffer_pool_chunk_size
)Converts hash tables, lists, and pointers to use new addresses in memory
Of these operations, only defragmenting the buffer pool and withdrawing pages allow other threads to access to the buffer pool concurrently.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-innodb-buffer-pool-resize.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.