To improve the speed of reading and writing files, the Linux system uses a page caching mechanism. When an application calls a function such as read,write to read and write files, the system does not immediately
, instead, to see if the data that needs to be read is already in the page cache, if not, read from the hard disk. When writing, just write the data to the page cache, and then
Using the system process Pdflush write to the hard disk based on an algorithm, the details of the algorithm in the following section will be a brief introduction.
System current page cache size and other data can view the/proc/meminfo file, here is a simple example
[Email protected]_ses]# Cat/proc/meminfo
cached:1094972 KB
dirty:20484 KB
writeback:0 KB
For easy reading, a lot of irrelevant information about this article has been removed.
Cached: Current page Cache size
Dirty: The size of the page cache waiting to be written to hard disk data
Writeback: Writing hard disk data size, this value is generally 0, no way, hard disk write speed is too fast ....
The page cache is simply introduced, and the pdflush process of refreshing the page cache is described below. System can only have 2~8 Pdflush process, the current number of Pdflush process can be viewed through/proc/sys/vm/nr_pdflush_threads. A new Pdflush process is initiated when all pdflush processes within the system are busy for more than 1 seconds. After more than one second, the system will kill a pdflush process when all the current Pdflush processes are idle.
The system has some controllable parameters that affect the Pdflush process behavior:
/proc/sys/vm/dirty_writeback_centisecs: The default is 500 (in units of 1% seconds), and how long the interval wakes up the Pdflush process to work.
However, modifying this configuration file generally does not affect the specific wake-up time, the kernel algorithm itself in accordance with the actual system control.
/proc/sys/vm/dirty_expire_centiseconds: The default is 3000 (in 1% seconds), the maximum length of time that the data is cached in the page cache before it is brushed into the hard disk. It is worth noting that the default time is 30 seconds, which means that the data will not actually be written to the hard disk until 30 seconds after the page is cached.
/proc/sys/vm/dirty_background_ratio: The default is 10 or 5 (per cent), and how much of the dirty data is in the system's free memory before it is brushed into the hard disk. System Idle Memory calculation method =cached+memfree-mapped. (These three data are in/proc/meminfo).
Summary: The system refreshes the page cache normally there are only 2 cases, 1: The data into the page cache exceeds the time limit. 2: The size of the data to be written in the page cache has arrived online.
There is also an extreme case where the write operation is blocked until all dirt are written to the file when the system dirty data size is greater than or equal to/proc/sys/vm/dirty_ratio (default is 40%). This can be simulated with DD If=/dev/zero Of=hog.
Linux page Cache