日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

mysql innodb flush method_对innodb_flush_method的一点解释

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

官方文檔描述如下:

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個(gè)值

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ù)但是實(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)).

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

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

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

struct task_struct { }

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

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

2、O_DSYNC

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

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

我們知道對(duì)一個(gè)文件進(jìn)行讀,打開是使用LINUX的

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

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.

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

最大的安全性

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.

使用這個(gè)選項(xiàng)MYSQL使用O_DIRECT方式打開數(shù)據(jù)文件,而fsync()會(huì)最終同步所有的數(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.

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

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

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

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

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

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

水平有限,如有錯(cuò)誤請(qǐng)指出

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

總結(jié)

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

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