最佳缓冲器大小为写(2) [英] Optimal buffer size for write(2)

查看:116
本文介绍了最佳缓冲器大小为写(2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说我要一个1 GB的数据写入时,说用 EXT3 Linux文件系统写(2)系统调用,这发生在一个非常繁忙的环境(许多类似的I / O concurently)。什么是在区间的最佳缓冲区大小,比方说, [4 KB,4 MB] 这样做,当

Let's say I want to write a 1 GB of data to the file on, say ext3 Linux filesystem using write(2) syscall and this happens in a very busy environment (many similar I/Os concurently). What is the optimal buffer size in the interval, say, [4 kB, 4 MB] to do that when


  1. 不使用 O_DIRECT 开旗,或

  2. 使用 O_DIRECT

  1. not using O_DIRECT open flag, or
  2. using O_DIRECT?

请,没有检查你自己的答案 - 我想摆脱文件系统的家伙的一些答案

Please, no "check it yourself" answers -- I'd like to get some answer from "filesystems" guys.

推荐答案

作为评论的讨论,我相信确切大小不管那么多了,假设它是:

As discussed in comments, I believe the exact size don't matter that much, assuming it is :


  • 文件系统的大小小多(见注释由约阿希姆Pileborg暗示 STAT(。)等)

  • 二的幂(因为电脑和内核像他们一样)

  • 不要太大(例如在处理器内部的一些缓存,例如L2高速缓存配件)

  • 在内存中排列(例如,使用 posix_memalign A页面大小)。

  • a small multiple of the file system size (see comment by Joachim Pileborg suggesting stat(".") etc.)
  • a power of two (because computers and kernels like them)
  • not too big (e.g. fitting in some cache inside your processor, e.g. L2 cache)
  • aligned in memory (e.g. to a page size using posix_memalign).

因此​​,一个16K字节和几兆字节或许应该契合之间的两个电源。大部分时间花费在阅读上。文件系统和磁盘基准测试都相当平在这个范围内。

So a power of two between 16kbytes and a few megabytes should probably fit. Most of the time is spent on reading the disk. Filesystem and disk benchmarks are quite flat in that range.

4K字节似乎经常是页大小和磁盘块大小

4Kbytes seems to often be the page size and the disk chunk size.

当然,你可以调整的东西,甚至调,使得文件系统时使用的mke2fs ,文件系统的块大小。

Of course, you can tune things, even tune, when making the file system with mke2fs, the file system block size.

和我敢打赌,最优真的取决于你的硬件(SSD,硬盘?)和系统(和负载)。

And I'll bet that the optimal is really dependent upon your hardware (SSD, hard disks?) and your system (and its load).

这篇关于最佳缓冲器大小为写(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆