简体   繁体   English

如何更改 kernel i/o 缓冲区大小

[英]How to change kernel i/o buffer size

I am running some experiments with I/O intensive applications and am trying to understand the effects of varying the kernel i/o buffer size, different elevator algorithms, and so on.我正在对 I/O 密集型应用程序进行一些实验,并试图了解改变 kernel i/o 缓冲区大小、不同电梯算法等的影响。

How can I know the current size of the i/o buffer in the kernel?我如何知道 kernel 中 i/o 缓冲区的当前大小? Does the kernel use more than one buffer as need arises? kernel 是否在需要时使用多个缓冲区? How can I change the size of this buffer?如何更改此缓冲区的大小? Is there a config file somewhere that stores this info?是否有存储此信息的配置文件?

(To be clear, I am not talking about processor or disk caches, I am talking about the buffer used by the kernel internally that buffers reads/writes before flushing them out to disk from time to time). (需要明确的是,我不是在谈论处理器或磁盘缓存,我是在谈论 kernel 内部使用的缓冲区,该缓冲区在不时将读取/写入刷新到磁盘之前缓冲读取/写入)。

Thanks in advance.提前致谢。

The kernel does not buffer reads and writes the way you think... It maintains a "page cache" that holds pages from the disk. kernel 不会像您想象的那样缓冲读取和写入...它维护一个“页面缓存”来保存磁盘中的页面。 You do not get to manipulate its size (well, not directly, anyway);你不能操纵它的大小(好吧,不是直接的,反正); the kernel will always use all available free memory for the page cache. kernel 将始终使用所有可用的免费 memory 作为页面缓存。

You need to explain what you are really trying to do.你需要解释你真正想要做什么。 If you want some control over how much data the kernel pre-fetches from disk, try a search for "linux readahead".如果您想控制 kernel 从磁盘预取多少数据,请尝试搜索“linux readahead”。 (Hint: blockdev --setra XXX ) (提示: blockdev --setra XXX

If you want some control over how long the kernel will hold dirty pages before flushing them to disk, try a search for "linux dirty_ratio".如果您想控制 kernel 在将脏页刷新到磁盘之前将其保留多长时间,请尝试搜索“linux dirty_ratio”。

A specific application can also bypass the page cache completely by using O_DIRECT , and it can exercise some control over it using fsync , sync_file_range , posix_fadvise , and posix_madvise .特定应用程序还可以使用O_DIRECT完全绕过页面缓存,并且可以使用fsyncsync_file_rangeposix_fadviseposix_madvise对其进行一些控制。 ( O_DIRECT and sync_file_range are Linux-specific; the rest are POSIX.) O_DIRECTsync_file_range是特定于 Linux 的;rest 是 POSIX。)

You will be able to ask a better question if you first educate yourself about the Linux VM subsystem, especially the page cache.如果您首先了解 Linux VM 子系统,尤其是页面缓存,您将能够提出更好的问题。

I think you mean the disk IO queues.我认为您的意思是磁盘 IO 队列。 For example:例如:

$ cat /sys/block/sda/queue/nr_requests
128

How this queue is used depends on the IO scheduler that is in use.如何使用此队列取决于正在使用的 IO 调度程序。

$ cat /sys/block/sda/queue/scheduler
noop anticipatory deadline [cfq]

cfq is the most common choice, although on systems with advanced disk controllers and in virtual guest systems noop is also a very good choice. cfq是最常见的选择,尽管在具有高级磁盘控制器的系统和虚拟客户系统中noop也是一个非常好的选择。

There is no config file for this information that I am aware of.我知道没有此信息的配置文件。 On systems that I need to change the queue settings on I put the changes into /etc/rc.local although you could use a full-up init script instead and place it into an RPM or DEB for mass distribution to a lot of systems.在需要更改队列设置的系统上,我将更改放入 /etc/rc.local,尽管您可以使用完整的 init 脚本并将其放入 RPM 或 DEB 中,以便大规模分发到许多系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM