对 Linux 中可用的总物理内存设置限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13484016/
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
Setting limit to total physical memory available in Linux
提问by KZcoding
I know that I am supposed to set mem=MEMORY_LIMIT
. But I do not know where to go, during runtime, or during boot time, in order to set a limit to the total physical memory that the OS has control of.
我知道我应该设置mem=MEMORY_LIMIT
. 但是我不知道在运行期间或启动期间该去哪里,以便为操作系统控制的总物理内存设置限制。
I am running I/O benchmarks, and I would like to limit the amount of overall physical memory that is available.
我正在运行 I/O 基准测试,我想限制可用的整体物理内存量。
采纳答案by KZcoding
I found the answer I was looking for. Basically, the parameter that sets the total available physical memory is "mem=MEMORY_LIMIT". And this is a kernel boot parameter. You need to add, say "mem=1G" for maximum of 1GB available physical memory to the kernel boot parameter. For more info on how to add kernel boot parameters look at https://wiki.ubuntu.com/Kernel/KernelBootParameters
我找到了我正在寻找的答案。基本上,设置总可用物理内存的参数是“mem=MEMORY_LIMIT”。这是一个内核引导参数。您需要在内核引导参数中添加“mem=1G”以获得最大 1GB 的可用物理内存。有关如何添加内核启动参数的更多信息,请查看https://wiki.ubuntu.com/Kernel/KernelBootParameters
回答by Brian Campbell
Edit your kernel boot parameters in lilo.conf
, grub.conf
, grub.cfg
, or menu.lst
(which one depends on your particular distro and bootloader; check your distro's documentation for more detail) to include the parameter mem=512M
(or whatever size you want to emulate) on the line specifying your kernel parameters.
在lilo.conf
、grub.conf
、grub.cfg
或 中编辑您的内核引导参数menu.lst
(哪一个取决于您的特定发行版和引导加载程序;请查看发行版的文档以获取更多详细信息)以mem=512M
在指定内核参数的行中包含该参数(或您想要模拟的任何大小)。
For instance, in Grub, there should be a line that says something like kernel /boot/vmlinuz param1=val1 param2=val2
. Add the mem=512M
to that list of parameters. You can create separate entries for your boot menu by copying these entire definitions, renaming them, and configuring each with a different amount of memory, so you can quickly boot with different settings.
例如,在 Grub 中,应该有一行写着类似kernel /boot/vmlinuz param1=val1 param2=val2
. 将 加入mem=512M
到该参数列表中。您可以通过复制这些整个定义、重命名它们并为每个定义配置不同的内存量来为您的启动菜单创建单独的条目,以便您可以使用不同的设置快速启动。
回答by TekuConcept
To add to Brian Campbell's list, for the uBoot bootloader on the BeagleBone / Black devices, edit the kernel paramters in /boot/uboot/uEnv.txt
Add or modify the line mmcargs=setenv bootargs mem=512M
[tested with Debian]
要添加到 Brian Campbell 的列表中,对于 BeagleBone / Black 设备上的 uBoot 引导加载程序,请在/boot/uboot/uEnv.txt
Add 中编辑内核参数或修改行mmcargs=setenv bootargs mem=512M
[tested with Debian]
Use > free
before and after [reboot] to confirm the modification
使用> free
[reboot]前后确认修改
回答by Yavuz Sert
I've followed the instructions in this pagethat KZcoding mentioned (part: Permanently Add a Kernel Boot Parameter)
我已按照KZcoding 提到的此页面中的说明进行操作(部分:永久添加内核引导参数)
My Linux is (vm in virtualbox):
我的 Linux 是(虚拟机中的虚拟机):
Linux ubuntu 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Before setting:
设置前:
yavuz@ubuntu:~$ free -m
total used free shared buff/cache available
Mem: 3630 305 3010 6 314 3264
Swap: 3767 0 3767
Just changed this line in /etc/default/grub
刚刚改变了这一行 /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT=""
to
到
GRUB_CMDLINE_LINUX_DEFAULT="mem=2G"
then restart the server. After restart:
然后重启服务器。重启后:
yavuz@ubuntu:~$ free -m
total used free shared buff/cache available
Mem: 2000 298 1385 4 315 1651
Swap: 3767 0 3767
回答by George Rolf
A1: Yes, you have to reboot.
A1:是的,您必须重新启动。
A2: The kernel is rather unforgiving with respect to typos. There are no error messages. Could that be your problem? Examples: " mem=512M" and " mem=2G". Don't forget the space following the previous parameter, mem is in lower case, and K, M or G are upper case.
A2:内核对拼写错误相当无情。没有错误消息。那可能是你的问题吗?示例:“mem=512M”和“mem=2G”。不要忘记前面参数后面的空格,mem 是小写的,而 K、M 或 G 是大写的。