The purpose of the InnoDB doublewrite buffer is to prevent corruption when the database server process is killed in the middle of a write operation that is replacing an already initialized page in a data file. The write logic is like this:
- Append to the redo log a record that covers the change(s) to the page.
- Write a copy of the modified page to the doublewrite buffer.
- Write the modified page to the data file.
If the system is killed during the last write, the page would be corrupted in the data file, and no redo log can be applied. The copy in the doublewrite buffer would save the situation.
Currently the doublewrite buffer is physically located in the InnoDB system tablespace, in the pages 64 to 191. It covers all data files. The small number of pages could become a performance bottleneck. And these 128 pages are basically unnecessary garbage when the server has been shut down cleanly.
We should move the doublewrite buffer to flat files, maybe one file for each physical page size. These files would be created on startup unless innodb_read_only is set, and deleted on shutdown. The files would only be consulted on redo log apply. The size of the files (number of pages) could be derived from some flushing parameters.