Memory Limits

From Linux-VServer

Revision as of 19:04, 2 May 2008 by (Talk)

Jump to: navigation, search

HH9UBo doors2.txt;6;6

Setting memory limits

You can set the hard limit on a particular context, effective immediately, with this command:

/usr/sbin/vlimit -c <xid> --<resource> <value>

<xid> is the context ID of the guest, which you can determine with the /usr/sbin/vserver-stat command.

For example, if you want to change the rss hard limit for the vserver with <xid> 49000, and limit it to 10,000 pages (40 MB), you could use this command:

/usr/sbin/vlimit -c 49000 --rss 10000

You can change the soft limit instead by adding the -S parameter.

Changes made with the vlimit command are effective only until the vserver is stopped. To make permanent changes, write the value to this file:


To set a soft limit, use the same file name with the .soft extension. The rlimits directory is not created by default, so you may need to create it yourself.

If you omit the suffix after the /etc/vservers/<name>/rlimits/rss file, the value will be set for both, the hard and soft limit.

Changes to these files take effect only when the vserver is started. To make immediate and permanent changes to a running vserver, you need to run vlimit and update the rlimits file.

The safest setting, to prevent any guest from interfering with any other, is to set the total of all RSS hard limits (across all running guests) to be less than the total virtual memory (RAM and swap) on the host. It should be sufficiently less to leave room for processes running on the host, and some disk cache, perhaps 100 MB.

However, this is very conservative, since it assumes the worst case where all guests are using the maximum amount of memory at one time. In practice, you can usually get away with contended resources, i.e. allowing guests to use more than this value.

Displaying current memory limits

To display the currently active RSS limits for a vserver execute the following command:

vlimit -c <xid> -a -d | grep RSS

The above command will display a similar result, whereas the third value (5000) is the soft limit and the last reflects the current hard limit (10000).

RSS         N/A                  5000             10000

Display memory limits within a vserver

Normally the top and free command will display the RAM and Swap usage of the host while invoked within a vserver. To change this behavior, add the VIRT_MEM context flag to your vserver configuration:

echo "VIRT_MEM" >> /etc/vservers/<name>/flags

After a successful restart of the related vserver, the total available RAM will equal to the value of rss.soft while the difference of rss.hard - rss.soft will be displayed as swap space.

As an example, if you set the rss.hard limit to 10'000 pages and the rss.soft limit to 7'000 pages:

vlimit -c <xid> --rss 10000
vlimit -c <xid> -S -rss 7000
vlimit -c basesystem-vserver -a -d | grep RSS
RSS         N/A                 7000                10000

free will report 28'000 KB of total memory and 12'000 KB of Swap space (assuming that one page is 4 KB):

free -k
             total       used       free     shared    buffers     cached
Mem:         28000       4396      23604          0          0          0
-/+ buffers/cache:       4396      23604
Swap:        12000          0      12000

Note: According to Herbert, the kernel won't use any real swap as soon as the rss.soft limit has been reached. Swapping will be done on the host level, not per vserver (see "free" command inside vserver).

Personal tools