日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

mysql innodb flush method_对innodb_flush_method的一点解释

發(fā)布時間:2023/12/2 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql innodb flush method_对innodb_flush_method的一点解释 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

官方文檔描述如下:

By default, InnoDB uses the fsync()system call to flush both the data and log files. If

innodb_flush_method option is set to O_DSYNC, InnoDB uses O_SYNC to open and flush the

log files, and fsync()to flush the data files. If O_DIRECT is specified (available on some GNU/

Linux versions, FreeBSD, and Solaris), InnoDBuses O_DIRECT(or directio()on Solaris) to

open the data files, and uses fsync()to flush both the data and log files. Note that InnoDB uses

fsync() instead of fdatasync(), and it does not use O_DSYNC by default because there have

been problems with it on many varieties of Unix.

innodb_flush_method

常規(guī)3個值

1、fdatasync

2、O_DSYNC

3、O_DIRECT

正常的訪問方式

用戶態(tài)緩存---》內(nèi)核態(tài)緩存---》磁盤

按照MYSQL的描述

1、fdatasync

InnoDB uses the fsync() system call to flush both the data and log files.

Note that InnoDB uses fsync() instead of fdatasync()

雖然MYSQL可以使用fdatasync為參數(shù)但是實際上是調(diào)用的系統(tǒng)的 fsync()函數(shù),

我們可以看看LINUX下FSYNC()函數(shù)的描述

fsync() ?transfers ?("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the

file descriptor fd to the disk device (or other permanent storage device) so that all changed information can be retrieved ?even

after ?the ?system crashed or was rebooted. ?This includes writing through or flushing a disk cache if present. ?The call blocks

until the device reports that the transfer has completed. ?It also flushes metadata information associated with ?the ?file ?(see

stat(2)).

簡單的說這個參數(shù)用于同步所有線程修改過的文件,而進程中的PCB中記錄了打開文件,他是通過文件描述符進行匹配的

在LINUX內(nèi)核中/usr/src/linux-headers-3.19.0-25-generic/include/linux/sched.h

有如下的PCB結(jié)構(gòu)體

struct task_struct { }

其中有一個files_struct的結(jié)構(gòu)體,而文件描述符就是這樣一個結(jié)構(gòu)體的指針

那么只要MYSQL線程進行了刷新動作,那么他的這些文件的數(shù)據(jù)一定會同步到磁盤

2、O_DSYNC

InnoDB uses O_SYNC to open and flush the log files, and fsync()to flush the data files

當(dāng)設(shè)置為這個選項的時候,當(dāng)MYSQL線程打開LOGFILE的時候使用的O_SYNC的方式,而對數(shù)據(jù)文件還是使用的fsync()

我們知道對一個文件進行讀,打開是使用LINUX的

open()函數(shù),而其中也就有這樣一個選項

O_SYNC The ?file ?is ?opened for synchronous I/O. ?Any write(2)s on the resulting file descriptor will block the calling process

until the data has been physically written to the underlying hardware.

他描述的是如果這樣打開一個文件那么在數(shù)據(jù)從內(nèi)核態(tài)緩存寫到了物理磁盤前,任何試圖修改文件描述符的進程都會被堵塞。如此保證了日志文件

最大的安全性

3、O_DIRECT

If O_DIRECT is specified (available on some GNU/Linux versions, FreeBSD, and Solaris), InnoDB

uses O_DIRECT(or directio()on Solaris) to open the data files, and uses

fsync()to flush both the data and log files.

使用這個選項MYSQL使用O_DIRECT方式打開數(shù)據(jù)文件,而fsync()會最終同步所有的數(shù)據(jù)和日志文件。

我們同樣看看open()函數(shù)中關(guān)于O_DIRECT描述

O_DIRECT (Since Linux 2.4.10)

Try to minimize cache effects of the I/O to and from this file. ?In general this will degrade performance, but it is use‐

ful ?in special situations, such as when applications do their own caching. ?File I/O is done directly to/from user-space

buffers. ?The O_DIRECT flag on its own makes an effort to transfer data synchronously, but does not give ?the ?guarantees

of ?the ?O_SYNC flag that data and necessary metadata are transferred. ?To guarantee synchronous I/O, O_SYNC must be used

in addition to O_DIRECT.

使用這個選項一般來說會降低性能,但是在特定的情況下比如應(yīng)用程序有自己的緩存機制。I/O直接來自用戶態(tài)的緩存,O_DIRECT標(biāo)識對大量的

數(shù)據(jù)寫有利,因為他繞開了內(nèi)核態(tài)緩存,但是他并同步METADATA(這里占時理解為INODE緩存,也就是文件的基本信息比如打開時間修改時間等)

所以要完成同步必須同時調(diào)用O_SYNC。

如此我們也了解為什么為什么使用O_DIRECT還會調(diào)用FSYNC()我們知道FSYNC()是全同步的,LINUX上的傳統(tǒng)的FDATASYNC()是不同步METADATA的

如INODE緩存,進程描述緩存。但是他能夠?qū)Υ罅康臄?shù)據(jù)繞開緩存,提高性能,需要最后同步的只是DATAFILE的METADAT。

MYSQL有自己的緩沖,這種可以使用O_DIRECT比較好

水平有限,如有錯誤請指出

來自 “ ITPUB博客 ” ,鏈接:http://blog.itpub.net/7728585/viewspace-1980262/,如需轉(zhuǎn)載,請注明出處,否則將追究法律責(zé)任。

總結(jié)

以上是生活随笔為你收集整理的mysql innodb flush method_对innodb_flush_method的一点解释的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。