linux虚拟内存内核参数

本文详细介绍了Linux内核中与虚拟内存管理相关的参数,包括admin_reserve_kbytes、block_dump、compact_memory等,涉及到内存预留、块I/O调试、内存压缩、脏页回写策略等内容,对理解Linux内存管理机制具有重要意义。
摘要由CSDN通过智能技术生成
参数说明
==============================================================
1.    admin_reserve_kbytes
给有cap_sys_admin权限的用户保留的内存数量,默认值是min(free pages * 3%, 8MB)。这些内存是为了给管理员登录和杀死进程恢复系统提供足够的内存.

2.     block_dump
block_dump enables block I/O debugging when set to a nonzero value. More information on block I/O debugging is in Documentation/laptops/laptop-mode.txt.
如果设置的是非零值,则会启用块I/O调试。更多的关于块I/O调试的信息可以参见Documentation/laptops/laptop-mode.txt。
3.    compact_memory
Available only when CONFIG_COMPACTION is set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible. This can be important for example in the allocation of huge pages although processes will also directly compact memory as required.
只有在启用了CONFIG_COMPACTION选项才有效。当向该文件(/proc/sys/vm/compact_memory)写入1时,所有的内存域都会被压缩,使空闲的内存尽可能形成连续的内存块。
4.    dirty_background_bytes
Contains the amount of dirty memory at which the pdflush background writeback daemon will start writeback.
Note: dirty_background_bytes is the counterpart of dirty_background_ratio. Only one of them may be specified at a time. When one sysctl is written it is immediately taken into account to evaluate the dirty memory limits and the other appears as 0 when read.
当脏页所占的内存数量超过dirty_background_bytes时,内核的flusher线程开始回写脏页。
  注意:dirty_background_bytes参数和dirty_background_ratio参数是相对的,只能指定其中一个。当其中一个参数文件被写入时,会立即开始计算脏页限制,并且会将另一个参数的值清零。
5.    dirty_background_ratio
Contains, as a percentage of total system memory, the number of pages at which the pdflush background writeback daemon will start writing out dirty data.
当脏页所占的百分比(相对于所有可用内存,即空闲内存页+可回收内存页)达到dirty_background_ratio时,内核的flusher线程开始回写脏页数据。所有可用内存不等于总的系统内存。
6.    dirty_bytes
Contains the amount of dirty memory at which a process generating disk writes will itself start writeback.
Note: dirty_bytes is the counterpart of dirty_ratio. Only one of them may be specified at a time. When one sysctl is written it is immediately taken into account to evaluate the dirty memory limits and the other appears as 0 when read.
Note: the minimum value allowed for dirty_bytes is two pages (in bytes); any value lower than this limit will be ignored and the old configuration will be retained.
当脏页所占的百分比(相对于所有可用内存,即空闲内存页+可回收内存页)达到dirty_ratio时,执行磁盘写操作的进程会自己开始回写脏数据。所有可用内存不等于总的系统内存。
7.    dirty_expire_centisecs
This tunable is used to define when dirty data is old enough to be eligible for writeout by the pdflush daemons.  It is expressed in 100'ths of a second. Data which has been dirty in-memory for longer than this interval will be written out next time a pdflush daemon wakes up.
脏数据的过期时间,超过该时间后内核的flusher线程被唤醒时会将脏数据回写到磁盘上,单位是百分之一秒。

8.    dirty_ratio
Contains, as a percentage of total system memory, the number of pages at which a process which is generating disk writes will itself start writing out dirty data.
当脏页所占的百分比(相对于所有可用内存,即空闲内存页+可回收内存页)达到dirty_ratio时,执行磁盘写操作的进程会自己开始回写脏数据。所有可用内存不等于总的系统内存。
9.    dirty_writeback_centisecs
The pdflush writeback daemons will periodically wake up and write `old' data out to disk.  This tunable expresses the interval between those wakeups, in 100'ths of a second.
Setting this to zero disables periodic writeback altogether.
内核的flusher线程会周期性地唤醒,然后将老的脏数据写到磁盘上。dirty_writeback_centisecs定义了唤醒的间隔,单位是百分之一秒。如果设置为0,则禁止周期性地唤醒回写线程。
10.    drop_caches
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation and dirty objects are not freeable, the user should run `sync' first.
向/proc/sys/vm/drop_caches文件中写入数值可以使内核释放page cache,dentries和inodes缓存所占的内存。
  只释放pagecache:
      echo 1 > /proc/sys/vm/drop_caches
  只释放dentries和inodes缓存:
      echo 2 > /proc/sys/vm/drop_caches
  释放pagecache、dentries和inodes缓存:
      echo 3 > /proc/sys/vm/drop_caches
  这个操作不是破坏性操作,脏的对象(比如脏页)不会被释放,因此要首先运行sync命令。
11.    extfrag_threshold
This parameter affects whether the kernel will compact memory or direct reclaim to satisfy a high-order allocation. /proc/extfrag_index shows what the fragmentation index for each order is in each zone in the system. Values tending towards 0 imply allocations would fail due to lack of memory, values towards 1000 imply failures are due to fragmentation and -1 implies that the allocation will succeed as long as watermarks are met.
The kernel will not compact memory in a zone if the fragmentation index is <= extfrag_threshold. The default value is 500.
12.    extra_free_kbytes
Add a userspace visible knob to tell the VM to keep an extra amount
of memory free, by increasing the gap between each zone's min and
low watermarks.
    This is useful for realtime applications that call system calls and have a bound on the number of allocations that happen in any short time period. In this application, extra_free_kbytes would be left at an amount equal to or larger than than the maximum number of allocations that happen in any burst.
It may also be useful to reduce the memory use of virtual machines (temporarily?), in a way that does not cause memory fragmentation like ballooning does.

http://www.gossamer-threads.com/lists/linux/kernel/1687142
13.    hugepages_treat_as_movable
This parameter is only useful when kernelcore= is specified at boot time to create
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Linux虚拟内存是操作系统提供的一种用于扩展系统内存的机制。通过虚拟内存Linux可以将部分磁盘空间用作额外的内存来满足系统运行时的内存需求。 在Linux中,虚拟内存可以通过设置系统的交换空间(swap space)来进行配置。交换空间是硬盘上的一块用于存放被置换出来的内存页的区域。当系统内存不足时,不经常使用的内存页会被换入到交换空间,从而释放出更多的物理内存用于当前正在执行的程序。 为了设置Linux虚拟内存,需要进行以下几个步骤: 1. 创建一个交换分区(swap partition)或交换文件(swap file)。交换分区是在磁盘上划分的一个特定区域,而交换文件是一个普通的文件。可以使用Linux的磁盘工具(如fdisk)来创建交换分区,或使用命令dd来创建交换文件。 2. 格式化交换分区或交换文件。可以使用mkswap命令对交换分区或交换文件进行格式化,以便系统能够使用它作为交换空间。 3. 启用交换空间。可以使用swapon命令将交换分区或交换文件作为有效的交换空间启用。例如,可以使用swapon /dev/sdb1命令将/dev/sdb1设备上的交换分区启用。 4. 配置系统在启动时自动启用交换空间。可以将交换分区或交换文件的信息添加到/etc/fstab文件中,以便系统在每次启动时自动启用交换空间。 在设置Linux虚拟内存时,需要注意交换空间的大小。如果设置的交换空间过小,系统可能在内存不足时无法正常工作;如果设置的交换空间过大,可能会浪费磁盘空间。通常,建议将交换空间的大小设置为物理内存的1.5倍到2倍左右。 总而言之,通过设置Linux的交换空间,可以扩展系统的内存容量,提高系统的运行稳定性和性能,确保系统能够正常运行。 ### 回答2: Linux虚拟内存设置是指对Linux操作系统中的虚拟内存进行配置和管理的过程。虚拟内存是一种计算机系统的内存管理方式,它将磁盘上的一部分空间用作扩展内存,使得操作系统可以在物理内存不足时使用这部分空间来进行内存交换。 在Linux中,虚拟内存的设置主要涉及以下几个方面: 1. 交换空间设置:通过设置交换分区或者交换文件来为虚拟内存提供支持。可以使用命令swapon和swapoff来启用或禁用交换空间。 2. 虚拟内存的大小调整:可以通过调整内核参数来设置虚拟内存的大小。在Linux系统中,可以通过修改/sys/devices/system/node/nodeX/meminfo文件中的参数来调整虚拟内存的大小。 3. 调整页面大小:页面大小是虚拟内存管理的基本单位,可以通过修改内核参数vm.page_size来调整页面大小。通常情况下,页面大小为4KB,但也可以根据实际需求进行调整。 4. 管理页面置换:当物理内存不足时,Linux会根据页面置换算法将不常用的页面从物理内存中交换到交换空间或者磁盘上,以腾出物理内存空间。可以通过修改内核参数vm.swappiness来调整页面置换的策略。 5. 内存分配策略:Linux使用伙伴系统算法来管理内存分配。可以通过修改内核参数vm.min_free_kbytes来调整空闲内存的阈值,从而控制内存分配的策略。 总之,Linux虚拟内存设置是一个复杂的过程,需要根据实际需求和系统资源情况进行调整和优化。正确地配置和管理虚拟内存可以提高系统的性能和可靠性。 ### 回答3: Linux虚拟内存(Virtual Memory)设置是指操作系统用于扩展计算机内存的一种技术。在Linux系统中,虚拟内存允许将部分磁盘空间用作临时的内存存储,以使计算机能够处理更大的数据量和运行更多的程序。 Linux系统通过将内存分为多个页面(Page)来管理虚拟内存。操作系统将常用的页面保存在物理内存中,而将不常用的页面交换(swap)到硬盘上的交换空间(Swap Space)。这样一来,即使物理内存不足,操作系统仍可以继续执行程序,从而提高了系统的可用内存大小。虚拟内存的大小由内核参数vm.swappiness来控制,范围为0到100。值越高,越倾向于将页面交换到交换空间,值越低,越倾向于保留页面在物理内存中。 在Linux系统中,可以使用命令“sysctl”来查看和修改虚拟内存设置。通过修改/sys/kernel/mm/transparent_hugepage/enabled文件的值,可以启用或禁用透明大页(Transparent Huge Pages),从而提升系统性能。另外,还可以通过修改/etc/sysctl.conf文件来永久修改虚拟内存设置。 在设置虚拟内存时,需要综合考虑系统的硬件配置、应用程序的资源需求以及性能需求。过大的虚拟内存设置可能导致磁盘空间的浪费,而过小的设置可能会影响系统的性能。因此,根据具体的情况,合理地配置虚拟内存是非常重要的。 总之,虚拟内存Linux系统中重要的内存管理技术。通过适当地设置虚拟内存,可以提升系统的性能和可用内存大小,从而更好地满足计算机的资源需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值