为什么linux 当系统内存大于8GB 时禁用磁盘写入缓冲区?
Why linux disables disk write buffer when system ram is greater than 8GB?
背景:
我试图在我的台式电脑上安装一台 ubuntu
机器。整个过程花了一整天,包括安装 OS 和软件。不过我也没多想。
然后我尝试用新机器做我的工作,它比我的笔记本电脑慢得多,这很奇怪。
我做了iotop
,发现解压包时磁盘流量在1-2MB/s左右,肯定不正常。
然后,经过几个小时的研究,我发现 this article 描述了完全相同的问题,并提供了一个丑陋的解决方案:
We recently had a major performance issue on some systems, where disk write speed is extremely slow (~1 MB/s — where normal performance
is 150+MB/s).
...
EDIT: to solve this, either remove enough RAM, or add “mem=8G” as kernel boot parameter (e.g. in /etc/default/grub on Ubuntu — don’t
forget to run update-grub !)
这个我也看了post
https://lonesysadmin.net/2013/12/22/better-linux-disk-caching-performance-vm-dirty_ratio/
并做了
cat /proc/vmstat | egrep "dirty|writeback"
输出为:
nr_dirty 10
nr_writeback 0
nr_writeback_temp 0
nr_dirty_threshold 0 // and here
nr_dirty_background_threshold 0 // here
当设置 mem=8g
时,这些值为 8223
和 4111
。
所以,它基本上表明 当系统内存大于 8GB(我的情况是 32GB),无论 vm.dirty_background_ratio
和 vm.dirty_ratio
设置如何, (在我的例子中是 5% 和 10%),实际脏阈值变为 0 并且写缓冲区被禁用?
为什么会这样?
这是内核或其他地方的错误吗?
除了拔出 RAM 或使用 "mem=8g" 之外,还有其他解决方案吗?
更新: 我是 运行 3.13.0-53 通用内核 ubuntu 12.04 32 位,所以这可能只是发生在 32 位系统上。
如果您使用 32 位内核和超过 2G 的 RAM,则您 运行 处于次优配置,必须做出重大权衡。这是因为在这些配置中,内核无法再一次映射所有物理内存。
随着物理内存量的增加超过这一点,权衡变得越来越糟糕,因为用于管理所有物理内存的 struct page
数组必须始终保持映射,并且该数组随物理内存增长。
不被内核直接映射的物理内存称为"highmem",默认情况下回写代码将highmem 视为不可修改的。这就是脏阈值的零值的原因。
您可以通过将 /proc/sys/vm/highmem_is_dirtyable
设置为 1 来更改此设置,但是如果您安装 64 位内核,那么使用这么多内存会更好。
Is this a bug in the kernel
根据您引用的文章,这是一个错误,在较早的内核中不存在,在较新的内核中已修复。
Note that this issue seems to be fixed in later releases (3.5.0+) and is a regression (doesn’t happen on e.g. 2.6.32)
背景:
我试图在我的台式电脑上安装一台 ubuntu
机器。整个过程花了一整天,包括安装 OS 和软件。不过我也没多想。
然后我尝试用新机器做我的工作,它比我的笔记本电脑慢得多,这很奇怪。
我做了iotop
,发现解压包时磁盘流量在1-2MB/s左右,肯定不正常。
然后,经过几个小时的研究,我发现 this article 描述了完全相同的问题,并提供了一个丑陋的解决方案:
We recently had a major performance issue on some systems, where disk write speed is extremely slow (~1 MB/s — where normal performance is 150+MB/s).
...
EDIT: to solve this, either remove enough RAM, or add “mem=8G” as kernel boot parameter (e.g. in /etc/default/grub on Ubuntu — don’t forget to run update-grub !)
这个我也看了post
https://lonesysadmin.net/2013/12/22/better-linux-disk-caching-performance-vm-dirty_ratio/
并做了
cat /proc/vmstat | egrep "dirty|writeback"
输出为:
nr_dirty 10
nr_writeback 0
nr_writeback_temp 0
nr_dirty_threshold 0 // and here
nr_dirty_background_threshold 0 // here
当设置 mem=8g
时,这些值为 8223
和 4111
。
所以,它基本上表明 当系统内存大于 8GB(我的情况是 32GB),无论 vm.dirty_background_ratio
和 vm.dirty_ratio
设置如何, (在我的例子中是 5% 和 10%),实际脏阈值变为 0 并且写缓冲区被禁用?
为什么会这样?
这是内核或其他地方的错误吗?
除了拔出 RAM 或使用 "mem=8g" 之外,还有其他解决方案吗?
更新: 我是 运行 3.13.0-53 通用内核 ubuntu 12.04 32 位,所以这可能只是发生在 32 位系统上。
如果您使用 32 位内核和超过 2G 的 RAM,则您 运行 处于次优配置,必须做出重大权衡。这是因为在这些配置中,内核无法再一次映射所有物理内存。
随着物理内存量的增加超过这一点,权衡变得越来越糟糕,因为用于管理所有物理内存的 struct page
数组必须始终保持映射,并且该数组随物理内存增长。
不被内核直接映射的物理内存称为"highmem",默认情况下回写代码将highmem 视为不可修改的。这就是脏阈值的零值的原因。
您可以通过将 /proc/sys/vm/highmem_is_dirtyable
设置为 1 来更改此设置,但是如果您安装 64 位内核,那么使用这么多内存会更好。
Is this a bug in the kernel
根据您引用的文章,这是一个错误,在较早的内核中不存在,在较新的内核中已修复。
Note that this issue seems to be fixed in later releases (3.5.0+) and is a regression (doesn’t happen on e.g. 2.6.32)