Q: How do you tune InnoDB buffer pool dirty page flushing under write-heavy burst workloads in MariaDB?
MariaDB interview questions on InnoDB flushing: tune io_capacity, dirty page limits and redo log size, and read checkpoint age in SHOW ENGINE INNODB STATUS.
Want to master this scenario in a live sandbox? KodeKloud's PostgreSQL Database Administration & High Availability Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: Among mariadb interview questions on performance, dirty page flushing separates people who tune by copying settings from people who understand the write path. Writes land in the buffer pool and the redo log first. Background threads flush dirty pages to the data files later, and the redo log can only wrap around once its oldest changes are checkpointed. If a burst fills the redo log faster than pages get flushed, InnoDB stalls foreground queries to force a flush, and latency spikes. I diagnose which limit I am hitting before changing anything.
Measure dirty pages and buffer pool pressure
I start with the share of dirty pages in the pool and whether free pages are running out. The Innodb_buffer_pool_pages_dirty and Innodb_buffer_pool_pages_total counters give the ratio. A pool that sits close to innodb_max_dirty_pages_pct during a burst means the flusher is the bottleneck. I also check innodb_buffer_pool_size against available RAM, because a pool that is too small adds eviction flushing on top of normal flushing.
mariadb -e "SHOW GLOBAL STATUS WHERE Variable_name IN ('Innodb_buffer_pool_pages_dirty','Innodb_buffer_pool_pages_total','Innodb_buffer_pool_pages_free','Innodb_buffer_pool_wait_free');"
# Innodb_buffer_pool_pages_dirty 412880
# Innodb_buffer_pool_pages_total 786432
# Innodb_buffer_pool_wait_free 0
mariadb -e "SHOW GLOBAL VARIABLES WHERE Variable_name IN ('innodb_buffer_pool_size','innodb_io_capacity','innodb_io_capacity_max','innodb_max_dirty_pages_pct','innodb_max_dirty_pages_pct_lwm','innodb_log_file_size');"
Calculate checkpoint age from SHOW ENGINE INNODB STATUS
The LOG section lists the log sequence number and the last checkpoint. Their difference is the checkpoint age, the amount of redo that has not been flushed to data files yet. When that number approaches the usable redo log capacity, InnoDB starts aggressive flushing and can stall writes. This single number tells me whether the redo log is too small for the burst or the flusher is too slow.
mariadb -e "SHOW ENGINE INNODB STATUS\G" | sed -n '/^LOG/,/^BUFFER POOL/p'
# Log sequence number 91827364501
# Last checkpoint at 91612345678
# Checkpoint age = 91827364501 - 91612345678 = 215018823 bytes
mariadb -e "SELECT @@innodb_log_file_size/1024/1024 AS redo_mb;"
Read per-pool flushing behaviour from INNODB_BUFFER_POOL_STATS
The information_schema table shows modified pages, pages written and the write rate per buffer pool instance. If MODIFIED_DATABASE_PAGES stays high and PAGES_WRITTEN_RATE is flat, the flusher is capped, usually by innodb_io_capacity being set far below what the storage can do. If written rate is high but dirty pages still climb, the disk itself is the limit.
SELECT POOL_ID, POOL_SIZE, FREE_BUFFERS, DATABASE_PAGES, MODIFIED_DATABASE_PAGES,
PAGES_WRITTEN_RATE, PENDING_FLUSH_LRU, PENDING_FLUSH_LIST
FROM information_schema.INNODB_BUFFER_POOL_STATS;
-- shape of output (illustrative):
-- POOL_ID POOL_SIZE FREE_BUFFERS DATABASE_PAGES MODIFIED_DATABASE_PAGES PAGES_WRITTEN_RATE
-- 0 786432 1024 780000 412880 180
Raise flushing capacity to match the storage
I set innodb_io_capacity to the sustained IOPS the volume can give InnoDB background work without hurting foreground reads, and innodb_io_capacity_max to the burst ceiling used when the flusher is falling behind. I verify the numbers with an fio run on the data volume rather than guessing. Both variables are dynamic, so I can test during a quiet window and watch the dirty page count respond.
fio --name=randwrite --filename=/var/lib/mysql/fio.test --size=4G --bs=16k --rw=randwrite --ioengine=libaio --iodepth=32 --direct=1 --runtime=60 --time_based
rm /var/lib/mysql/fio.test
SET GLOBAL innodb_io_capacity = 4000;
SET GLOBAL innodb_io_capacity_max = 8000;
SET GLOBAL innodb_adaptive_flushing = ON;
Start earlier with the low-water mark and size the redo log for the burst
Setting innodb_max_dirty_pages_pct_lwm above 0 makes InnoDB start flushing before the dirty ratio reaches innodb_max_dirty_pages_pct, which smooths bursts instead of hitting a wall. If checkpoint age still nears the redo capacity, I increase innodb_log_file_size. From MariaDB 10.9 it can be changed with SET GLOBAL; on older versions it needs a config change and restart.
SET GLOBAL innodb_max_dirty_pages_pct_lwm = 30;
SET GLOBAL innodb_max_dirty_pages_pct = 75;
-- MariaDB 10.9 and later, online resize
SET GLOBAL innodb_log_file_size = 4294967296;
-- Older versions: edit my.cnf and restart
-- [mysqld]
-- innodb_log_file_size = 4G
- Writes dirty buffer pool pages and fill the redo log, and only flushing and checkpointing frees redo space.
- Stalls appear when checkpoint age nears redo log capacity or dirty pages hit innodb_max_dirty_pages_pct.
- I read the log sequence number and last checkpoint in SHOW ENGINE INNODB STATUS and watch INNODB_BUFFER_POOL_STATS for modified pages and write rate.
- I raise innodb_io_capacity to what the disk can sustain, use the low-water mark to flush earlier, and enlarge the redo log for the burst.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Setting innodb_io_capacity to a huge number on slow storage InnoDB then issues more writes than the disk can absorb, which starves foreground reads and increases latency.
- Lowering innodb_max_dirty_pages_pct to force less dirty data It raises flushing pressure permanently and increases write IO without fixing a redo log that is too small.
- Increasing innodb_buffer_pool_size beyond available RAM The host starts swapping, which is far slower than flushing and can trigger the OOM killer.
- Changing several flushing variables at once You cannot tell which change helped, and a wrong value can hide the real checkpoint age problem.