directio,dsync & sync , async IO

本文探讨了Sybase数据库中的不同I/O模型,包括同步I/O与异步I/O的区别,dsync标志如何确保数据同步写入磁盘,以及直接I/O(Direct I/O)如何绕过文件系统缓存实现高效数据写入。文章还讨论了dsync与直接I/O之间的互斥关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://sybaseblog.com/2010/04/20/directiodsync-sync-async-io/

I came across very conceptual article about the sybase device io.

If you have any questions and suggestions please let me know. Thanks.

Source: Sybase Blogs, www, sybooks, sybase white paper for direct io.

ASYNCHRONOUS I/O:

  • Asynchronous I/O allows the process issuing the I/O to continue executing while OS completes the request.
  • Dataserver process does not block on this request till its completion.

SYNCHRONOUS I/O:

  • Synchronous I/O blocks the I/O issuing process from continuing executing while OS completes the request.
  • The process is blocked till the request is completed. This generally results in poor throughput.

DSYNC :

  • In 12.0 sybase introduced the dsync flag – shorthand for “Data Synchronous.”
  • When the dsync setting is on, Adaptive Server opens a database device file using the UNIX dsync flag.
  • The dsync flag in ASE directly translates to the O_DSYNC open(2) flag. That is to say, when ASE opens a device that has the dsync flag set, ASE will pass O_DSYNC to open(2).
  • This flag tells the file system that a write to that file must pass though the cache and be written to disk before the write is considered complete.
  • In other words, for writes we throw away the cache efficiency and make sure the data goes to disk.
  • This way if the system crashes, everything that we thought had been written to disk has in fact been written to disk.

Is DSYNC “synchronous”??

  • This is not true.
  • This synchronous / asynchronous conflict is at a different level. With async i/o we are talking about the context in which the i/o is executed, i.e. whether the i/o blocks the caller or if it is done in a different context.
  • With dsync we are talking about when the write() is considered complete.
  • These are not mutually exclusive, and you can asynchronously do a data synchronous i/o.
  • The async portion is as always: the application issues an i/o and later polls (or is notified) for completion. The dsync portion means that the application won’t be told that the I/O has completed until the data has made it to disk.

DIRECT IO

  • Direct I/O is another kind of file system i/o, introduced in ASE15.
  • In the direct i/o model the file system cache is completely bypassed.
  • Using direct i/o, writes are naturally safe because they bypass the cache and go straight to disk.
  • Direct i/o is very, very similar to raw i/o.
  • The main difference is that in direct i/o the structure of a file system still exists, easing manageability.
  • With raw i/o, no file system exists. The performance of raw and direct i/o should be very similar.

Also like to add :

  • The dsync and directio are mutually exclusive. Both cannt be turn on same time on the device. Both dsync and directio provide the full recoveribility.
  • If you gone through the full article, the next question is, which would be best in raw device and filesystem device with direct io, both are bypassing the file system cache.
### 使用 `dd` 命令测试磁盘 IO 性能 可以通过执行特定配置的 `dd` 命令来评估 Linux 系统中的磁盘 IO 性能。以下是几种常见的方法及其解释: #### 方法一:使用 DirectIO 测试顺序写入性能 此方法通过指定 `oflag=direct` 参数绕过操作系统的缓存机制,从而更真实地反映底层存储设备的实际性能。 ```bash sudo dd if=/dev/zero of=testfile bs=1M count=1024 oflag=direct ``` 上述命令会创建一个大小为 1GB 的文件 (`bs=1M count=1024`) 并记录其写入速度[^1]。 --- #### 方法二:使用 Dsync 进一步同步数据到磁盘 为了更加严格地测试磁盘性能并减少缓冲区的影响,可以采用 `oflag=dsync` 参数强制每次写入都立即刷新到物理介质上。 ```bash dd if=/dev/zero of=/root/testfile bs=512 count=100000 oflag=dsync ``` 这种方法通常用于模拟数据库或其他需要频繁刷盘的工作负载场景[^3]。 --- #### 方法三:综合分析读取与写入能力 除了单独关注写入之外,也可以利用类似的参数组合来进行完整的读写对比实验。例如先生成目标文件再尝试从中快速复制回零设备作为输入源之一。 写入过程: ```bash sudo dd if=/dev/urandom of=output.dat bs=8k conv=fdatasync status=progress ``` 随后验证随机访问模式下可能存在的差异效果如何体现出来呢? 接着进行读取测试: ```bash dd if=output.dat of=/dev/null bs=8k ``` 这里需要注意的是,在某些特殊情况下比如 SSD 或者 RAID 阵列环境中得到的结果可能会因为硬件特性而有所不同因此最好结合实际情况调整具体数值设置以便获得最贴近需求的数据表现形式[^2]. --- #### 结果解读 当完成以上任意一种类型的试验之后都会返回一些统计信息其中包括传输速率单位通常是MB/s或者KB/s等形式表示;另外还有总共处理了多少字节以及耗时多久等细节内容可供进一步计算得出平均吞吐量指标供参考判断当前环境下的I/O效率水平是否满足预期要求[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值