Memory and user_beancounters

OpenVZ uses a memory management model based on the idea of Beancounters, which represent your VPS's allocation of various system resources. (i.e. Memory)


Viewing your memory utilization

You may see these allocations when you login by typing the following: (as root)

[root@vps proc]# more /proc/user_beancounters
Version: 2.5
       uid  resource           held    maxheld    barrier      limit    failcnt
     nnnn:  kmemsize        1828843    5145361   22028640   22809600          0
            lockedpages           0          0        819        819          0
            privvmpages        6559      98268      98304      98304          0
            shmpages             36       1972      75676      75676          0
            dummy                 0          0          0          0          0
            numproc              14         84        495        495          0
            physpages          3187      76599          0 2147483647          0
            vmguarpages           0          0      98304 2147483647          0
            oomguarpages       3187      76599      98304 2147483647          0
            numtcpsock            3         18        768        768          0
            numflock              2         16        768        768          0
            numpty                0          2         75         75          0
            numsiginfo            0         11       1536       1536          0
            tcpsndbuf         26832     543348    2746800    4026180          0
            tcprcvbuf         49152    1551332    2746800    4026180          0
            othersockbuf     147576     221544    2746800    4026180          0
            dgramrcvbuf           0       8380    2013090    2013090          0
            numothersock         94        120        768        768          0
            dcachesize       223551     476937    6000000    6000000          0
            numfile             551       1972      12288      12288          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            numiptent            14         14        768        768          0



What counts as my VPS's "RAM"

Your VPS's memory allotment is the sum of several of these values:
kmemsize+tcpsndbuf+tcprcvbuf+dgramrcvbuf+othersockbuf+vmguarpages+privvmpages.

Some VPS providers count all of the above towards your plans resources. When they say you get 256MB of memory, you get less than a full 256MB of memory that is addressable, since kmemsize+tcpsndbuf+tcprcvbuf+dgramrcvbuf+othersockbuf take up some of that memory.

At Quantact, our VS series of servers (VS1,VS2,VSn) only count your privvmpages towards that memory limit, so in effect you are getting a bit of extra memory for free from the other beancounters.

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 fair share or plan limit)


Is there a script to show me my current RAM usage?

A perl script that a customer contributed that helps sum up your memory usage:

#!/usr/bin/perl
use strict;
use warnings;

# Author: David J. Weller-Fahy
# Inspired by 
# 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);
 
About Us   Contact Us    Terms of Service     Privacy Policy  
 © Quantact Hosting Solutions, Inc. 2010