OpenVZ Intro
From Quantact
OpenVZ is the Open Source version of the popular Virtuozzo VPS system.
OpenVZ is a shared kernel approach, in which all VM's on the server share the hosts Linux kernel.
The result is a low overhead system, which gives great performance.
OpenVZ is a fully functional VPS system, offering full root access on your own VM.
OpenVZ achieves its virtualization by controlling several key resource counters
in the kernel.
Here is a link to the resource configuration for our VZ vm's.
Your VM is given X amount of Ram, Y amount of disk, etc.
You may see these settings when you login by typing the following:
[root@vps proc]# more /proc/user_beancounters
Version: 2.5
uid resource held maxheld barrier limit failcnt
574: kmemsize 924808 1724891 5767168 5767168 0
lockedpages 0 0 128 128 0
privvmpages 8042 27953 32768 32768 0
shmpages 640 1328 8192 8192 0
dummy 0 0 0 0 0
numproc 14 26 250 250 0
physpages 2259 21025 0 2147483647 0
vmguarpages 0 0 30636 30636 0
oomguarpages 2259 21025 32768 32768 0
numtcpsock 3 7 250 250 0
numflock 4 11 100 110 0
numpty 1 2 16 16 0
numsiginfo 0 2 256 256 0
tcpsndbuf 8944 109564 741867 741867 0
tcprcvbuf 0 194532 741867 741867 0
othersockbuf 6708 15552 741867 741867 0
dgramrcvbuf 0 8380 741867 741867 0
numothersock 9 20 250 250 0
dcachesize 0 0 1048576 1097728 0
numfile 367 607 2178 2178 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
numiptent 10 10 128 128 0
Your vm's memory allotment is the sum of several of these values:
kmemsize+tcpsndbuf+tcprcvbuf+dgramrcvbuf+othersockbuf+vmguarpages+privvmpages.
All values ending in 'pages', such as vmguarpages and privvmpages, are multiplied by 4096.
All other values are in bytes.
The limit barrier and limit fields are your maximum amount that your vm can utilize. (its share)
A perl script that a customer contributed:
#!/usr/bin/perl
use strict;
use warnings;
# Author: David J. Weller-Fahy
# Inspired by <http://www.quantact.com/dl/openvzmemory.sh.gz>
# Placed in the public domain
my($field, $res_bytes, $res_pages, $value, $total);
print("$0 must be run by a SuperUser!\n") and exit(1) if ($< != 0);
# If no command-line parameters are used, stick with the default.
@ARGV = ('/proc/user_beancounters') unless @ARGV;
# These are the resources we care about.
$res_bytes = "dgramrcvbuf|kmemsize|othersockbuf|tcprcvbuf|tcpsndbuf|";
$res_pages .= "privvmpages|vmguarpages";
$total = 0;
# Iterate over the files specified in @ARGV.
while (<>) {
# Get rid of the UID and trailing colon.
s![[:digit:]]+:!! if m!kmemsize!;
# Strip leading/trailing whitespace.
s!^[[:space:]]+!!;
s![[:space:]]+$!!;
# We only care about the lines containing the resources in
# $res_(bytes|pages), so skip all other lines.
next unless m!^(?:$res_bytes$res_pages)!;
# Set the field to extract.
$field = (m!^kmemsize! ? 2 : 1);
# Grab the resource and value.
$value = (split)[$field];
# If this is a 'page' resource, multiply by the number of bytes in a page.
$value *= 4096 if m!^(?:$res_pages)!;
# Add this value to the total.
$total += $value;
}
# Original used 1024000 (??). Not sure why, the value below is 1024*1024.
$total /= 1048576;
# Print the number of MB used, rounded to 2 decimal places.
printf("Total MiB used: %.2f\n", $total);
A php script that will summarize your vm memory usage is:
http://www.labradordata.ca/home/13
A customer contributed script that will sum up your current ram usage:
http://www.quantact.com/dl/openvzmemory.sh.gz
