Linux 如何更改内核 I/O 缓冲区大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7044863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:41:32  来源:igfitidea点击:

How to change kernel i/o buffer size

clinuxiolinux-kernel

提问by jitihsk

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 密集型应用程序的实验,并试图了解改变内核 I/O 缓冲区大小、不同电梯算法等的影响。

How can I know the current size of the i/o buffer in the kernel? Does the kernel use more than one buffer as need arises? How can I change the size of this buffer? Is there a config file somewhere that stores this info?

如何知道内核中 i/o 缓冲区的当前大小?内核是否根据需要使用多个缓冲区?如何更改此缓冲区的大小?是否有存储此信息的配置文件?

(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).

(明确地说,我不是在谈论处理器或磁盘缓存,我在谈论内核内部使用的缓冲区,它在不时将读/写刷新到磁盘之前缓冲它们)。

Thanks in advance.

提前致谢。

采纳答案by Nemo

The kernel does not buffer reads and writes the way you think... It maintains a "page cache" that holds pages from the disk. You do not get to manipulate its size (well, not directly, anyway); the kernel will always use allavailable free memory for the page cache.

内核不会像您想象的那样缓冲读取和写入...它维护一个“页面缓存”,用于保存磁盘中的页面。你不能操纵它的大小(好吧,无论如何不能直接操纵);内核将始终将所有可用的空闲内存用于页面缓存。

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". (Hint: blockdev --setra XXX)

你需要解释你真正想要做什么。如果您想控制内核从磁盘预取的数据量,请尝试搜索“linux readahead”。(提示: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".

如果您想在将脏页刷新到磁盘之前控制内核将保留脏页的时间,请尝试搜索“linuxdirty_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_DIRECTand sync_file_rangeare Linux-specific; the rest are POSIX.)

特定的应用程序还可以绕过页面缓存完全使用O_DIRECT,并且它可以使用实行某种控制权fsyncsync_file_rangeposix_fadvise,和posix_madvise。(O_DIRECT并且sync_file_range是特定于 Linux 的;其余的是 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 子系统,尤其是页面缓存,您将能够提出更好的问题。

回答by Zan Lynx

I think you mean the disk IO queues. For example:

我想你的意思是磁盘 IO 队列。例如:

$ 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]

cfqis the most common choice, although on systems with advanced disk controllers and in virtual guest systems noopis 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 中,以便向许多系统大规模分发。