Setting limit to total physical memory available in Linux

情到浓时终转凉″ 提交于 2019-12-20 18:06:50

问题


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.

I am running I/O benchmarks, and I would like to limit the amount of overall physical memory that is available.


回答1:


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




回答2:


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.

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.




回答3:


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]

Use > free before and after [reboot] to confirm the modification




回答4:


A1: Yes, you have to reboot.

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.




回答5:


I've followed the instructions in this page that KZcoding mentioned (part: Permanently Add a Kernel Boot Parameter)

My Linux is (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

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


来源:https://stackoverflow.com/questions/13484016/setting-limit-to-total-physical-memory-available-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!