Understanding MySQL Buffer Pool: Architecture, Caching, and Performance
This article explains how MySQL's Buffer Pool caches data in memory, its default size and configuration, the internal structure of instances, chunks, control blocks and pages, and how it manages data loading, dirty pages, and flushing to disk for optimal query performance.
MySQL stores data on disk, but repeatedly reading from disk hurts performance, so it uses a Buffer Pool to cache data in memory, allowing faster subsequent reads.
1. What is the Buffer Pool?
When MySQL starts, it allocates a contiguous memory area called the Buffer Pool to cache data, reducing disk I/O and improving query speed. The default size is 128 MB (the total cache page size), while a separate 6 MB control block area is allocated. It is recommended to set the Buffer Pool to about 60 % of physical memory.
2. Buffer Pool Structure
To boost performance under high concurrency, the Buffer Pool is divided into multiple instances. The number of instances is controlled by the innodb_buffer_pool_instances parameter.
Each instance contains several chunks, and each chunk is further split into control blocks and cache pages.
Control blocks store metadata such as page numbers, tablespace IDs, memory addresses, and linked‑list information. A chunk begins with a 16 KB page that holds these control blocks. If one page cannot hold all control block information, additional pages are allocated, which may lead to internal fragmentation.
3. Buffer Pool Caching and Data Retrieval
In InnoDB, control blocks are linked in a free list when the Buffer Pool is initialized. When a page is loaded from disk (e.g., cache page 8), its control block is removed from the free list and the count is decremented.
A hash table inside the Buffer Pool maps tablespace + page number (key) to cache page address (value). MySQL first checks this hash table; if the entry exists, data is read directly from the cached page, otherwise it is fetched from disk and placed into the Buffer Pool.
4. Modifying Data in the Buffer Pool
When a cached page is modified, it becomes a dirty page. Instead of writing each dirty page immediately (which would degrade performance), MySQL uses a flush list to track pages that need to be written back to disk. The flush list also maintains a counter of pending pages.
When the number of dirty pages reaches a threshold, MySQL asynchronously flushes them to disk, ensuring data durability while maintaining high throughput.
Thus, the Buffer Pool handles loading and caching disk data, provides fast read access, and efficiently synchronizes modified data back to storage.
Lobster Programming
Sharing insights on technical analysis and exchange, making life better through technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.