简体   繁体   English

设置Linux中可用的总物理内存限制

[英]Setting limit to total physical memory available in Linux

I know that I am supposed to set mem=MEMORY_LIMIT . 我知道我应该设置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. 但我不知道去哪里,在运行时或在启动时,为了设置操作系统控制的总物理内存的限制。

I am running I/O benchmarks, and I would like to limit the amount of overall physical memory that is available. 我正在运行I / O基准测试,我想限制可用的整体物理内存量。

I found the answer I was looking for. 我找到了我正在寻找的答案。 Basically, the parameter that sets the total available physical memory is "mem=MEMORY_LIMIT". 基本上,设置总可用物理内存的参数是“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. 您需要为内核引导参数添加最多1GB可用物理内存的“mem = 1G”。 For more info on how to add kernel boot parameters look at https://wiki.ubuntu.com/Kernel/KernelBootParameters 有关如何添加内核引导参数的更多信息,请访问https://wiki.ubuntu.com/Kernel/KernelBootParameters

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.confgrub.confgrub.cfgmenu.lst编辑内核引导参数(哪一个取决于您的特定发行版和引导程序;请查看发行版的文档以获取更多详细信息)以包含参数mem=512M (或在指定内核参数的行上,您想要模拟的任何大小。

For instance, in Grub, there should be a line that says something like kernel /boot/vmlinuz param1=val1 param2=val2 . 例如,在Grub中,应该有一行代表kernel /boot/vmlinuz param1=val1 param2=val2 Add the mem=512M to that list of parameters. mem=512M添加到该参数列表中。 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. 您可以通过复制这些完整定义,重命名它们以及使用不同的内存量配置每个定义来为引导菜单创建单独的条目,以便您可以使用不同的设置快速启动。

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 要添加到Brian Campbell的列表,对于BeagleBone / Black设备上的uBoot引导加载程序,请编辑/boot/uboot/uEnv.txt的内核参数
Add or modify the line mmcargs=setenv bootargs mem=512M [tested with Debian] 添加或修改行mmcargs=setenv bootargs mem=512M [用Debian测试]

Use > free before and after [reboot] to confirm the modification 在[reboot]之前和之后使用> free确认修改

I've followed the instructions in this page that KZcoding mentioned (part: Permanently Add a Kernel Boot Parameter) 我按照本页中KZcoding提到的说明(部分:永久添加内核引导参数)

My Linux is (vm in virtualbox): 我的Linux是(vm in virtualbox):

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

A1: Yes, you have to reboot. A1:是的,你必须重启。

A2: The kernel is rather unforgiving with respect to typos. A2:关于打字错误的内核是相当无情的。 There are no error messages. 没有错误消息。 Could that be your problem? 这可能是你的问题吗? Examples: " mem=512M" and " mem=2G". 示例:“mem = 512M”和“mem = 2G”。 Don't forget the space following the previous parameter, mem is in lower case, and K, M or G are upper case. 不要忘记前一个参数后面的空格,mem是小写,K,M或G是大写。

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

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