What are mysql dirty pages?

What are mysql dirty pages?

Dirty pages (memory pages)

Clean page: the data in memory and on disk are consistent Dirty page: the data in memory and on disk are inconsistent

Why do dirty pages appear?

Normally, fast update operations are all writing to memory and logs.
It will not be synchronized to the disk data page immediately. At this time, the contents of the memory data page are inconsistent with the disk data page, which we call a dirty page.
This involves the memory management mechanism of MySQL

Brief description of memory management mechanism

The buffer contains lists of these three categories. They are: LRUList, FreeList, and FlushList.
When the database is just started, there are no data pages in the LRUlist. FreeList stores free pages.

  • When a page needs to be read, a free page is obtained from the FreeList, and after reading the data, it is placed in the LRUlist.
  • If there are no free pages in the FreeList, the last page in the LRU list is eliminated according to the LRU algorithm.
  • When a page in the LRUlist is modified, the page becomes a dirty page and is added to the FlushList.

Note: At this time, this page is in both the LRUlist and the FlushList.

Summary: LRUList (manages pages that have been read) and FreeList (manages free pages) are used to manage page availability; FlushList (manages dirty pages) is used to manage the refresh of dirty pages

During the process of synchronizing dirty page data to disk, if an SQL statement is executed on the disk data page. The execution speed will be slower

Is it possible to modify and read data only by relying on the buffer?

If data modification and reading rely only on the memory buffer, once the database crashes, all data in the memory will be lost. Therefore, MySQL uses the redo log mentioned earlier to implement data recovery after abnormal restart. For an introduction to redo log, see this article: MySQL-redo log and binlog

In simple terms, redo log is written before updating the buffer to ensure that the data in the buffer can be restored normally after an abnormal restart.

Why dirty pages must be refreshed

  • As mentioned above, if the data is only stored in the buffer, the database will crash and the memory data will be lost. So it needs to be flushed to disk.
  • If the redo log is infinitely large or has many files, there are a large number of modification operations in the system. Once a crash occurs, the recovery time will be very long.

So naturally, we must refresh the dirty pages in the memory to the disk according to some rules. With the refresh operation, the buffer size problem and the redo log size problem can be solved.

  • The buffer does not need to be infinite because it can be persisted to disk.
  • The redo log does not need to be infinite, because once it is persisted to disk, the corresponding part of the data in the redo log can be released.

There are four scenarios for flushing dirty pages:

  • When the redo log is full, MySQL will suspend all update operations and synchronize the dirty pages corresponding to this part of the log to the disk.
  • When the system memory is insufficient, some data pages need to be eliminated. If dirty pages are eliminated, they must be synchronized to the disk first.
  • When MySQL thinks the system is idle, it will synchronize memory data to disk when it has the opportunity, which does not cause performance problems.
  • When MySQL is shut down normally, MySQL will synchronize all dirty pages in memory to disk, so that the next time MySQL is started, it can read data directly from disk, and the startup speed will be very fast. This has no performance issues.

The impact

1 If the redo log is full, try to avoid it. Otherwise the update of the entire system will stop. At this time, the write performance becomes 0, and the update can only be done after the synchronization of the corresponding dirty page of the log is completed. This will cause the SQL statement to execute very slowly.

This is the end of this article about what MySQL dirty pages are. For more relevant MySQL dirty pages, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL Flush-List and dirty page flushing mechanism
  • Analysis of the principles of Mysql dirty page flush and shrinking table space

<<:  onfocus="this.blur()" is hated by blind webmasters

>>:  How to install jupyter in docker on centos and open ports

Recommend

How to Delete Junk Files in Linux Elegantly

I wonder if you are like me, a programmer who arr...

An example of vertical centering of sub-elements in div using Flex layout

1. Flex is the abbreviation of Flexible Box, whic...

Ten useful and simple MySQL functions

function 0. Display current time Command: select ...

Method of building docker private warehouse based on Harbor

Table of contents 1. Introduction to Harbor 1. Ha...

How to build YUM in Centos7 environment

1. Enter the configuration file of the yum source...

How to start and restart nginx in Linux

Nginx (engine x) is a high-performance HTTP and r...

Implementation of proxy_pass in nginx reverse proxy

The format is simple: proxy_pass URL; The URL inc...

How to update v-for in Vue

Tips: Array change method will cause v-for to upd...

Cause Analysis and Solution of I/O Error When Deleting MySQL Table

Problem phenomenon I recently used sysbench to te...

Several ways to implement CSS height changing with width ratio

[Solution 1: padding implementation] principle: I...

How to add double quotes in HTML title

<a href="https://www.jb51.net/" titl...

Setting the engine MyISAM/InnoDB when creating a data table in MySQL

When I configured mysql, I set the default storag...

How to create a responsive column chart using CSS Grid layout

I have been playing around with charts for a whil...

A complete guide to clearing floats in CSS (summary)

1. Parent div defines pseudo-classes: after and z...

Getting Started Tutorial on Using TS (TypeScript) in Vue Project

Table of contents 1. Introducing Typescript 2. Co...