LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to Tell Your OpenVZ VPS is Swapping

So you think your OpenVZ VPS really has “guaranteed memory”? Well. Not quite. I have got an OpenVZ VPS from one of the providers listed here — 256MB guaranteed and 512MB burstable memory. When I run free it shows

$ free -m
             total       used       free     shared    buffers     cached
Mem:           512         65        446          0          0          0
-/+ buffers/cache:         65        446
Swap:            0          0          0

So — 512MB total memory and 0 swap? After all I am only using 65MB of memory so well below my “guaranteed” amount. Zero swap because it is just how OpenVZ does its memory account. But is it really the case that all my processes reside in physical RAM?

Let’s dig out the good ol’ user_beancounters.

$ sudo cat /proc/user_beancounters | grep -E '(uid|physpages|oomguarpages)'
uid  resource              held       maxheld       barrier         limit       failcnt
     physpages             6662         11570             0    2147483647             0
     oomguarpages          8085         12750         65536    2147483647             0

I am trying to highlight the “physpages” and “oomguarpages” amount. According to OpenVZ Wiki:

physpages

Total number of RAM pages used by processes in this container.

oomguarpages

oomguarpages parameter accounts the total amount of memory and swap space used by the processes of a particular container.

Sounds like one is the total number of physical pages used by the container, and the other one is the total number of pages (physical + swap) used by the container. That means when you take oomguarpages – physpages you get — the number of swapped pages from processes in this container! Now back to my UBC readouts, I have

(8085 – 6662) * 4096 / 1024 / 1024 = 5.56MB!

out of 31.58MB (8,085 pages) that has been swapped out. And the 65MB figure returned by “free” is merely how much my processes have been allocating — so only 1/2 are actually used, and 18% of that is already swapped out.

So, has your low end provider been overselling the memory and caused your pages to swap out?

LEA
Latest posts by LEA (see all)

102 Comments

  1. Yomero:

    Wow! That is real? That can show us the real scenary of our VPS providers.

    Another reason to setup a machine with openVZ and understand better the behavior of vps’s

    Thanks!

    At this moment, none of my providers show that problem n_n

    November 10, 2010 @ 7:10 am | Reply
    • Hi, one thing to remember is that some hosts determine the saturation point, 65MB in your case. The real question is what value, (if any), the web host determines that the memory is oversold.

      Based on my experience, it is not necessary to oversell memory. The disk io bandwidth is a much more finite and valued number for real-time processing (think 60MB database->website).

      What type of disk configuration is this server running?

      November 11, 2010 @ 12:39 am | Reply
  2. On my main VPS, 4.5 of 344.6MB is swapped out.

    November 10, 2010 @ 7:26 am | Reply
  3. Snape:

    The rogue’s gallery of low-end (and not-so-low-end) OpenVZ VMs, in no particular order:

    “256MB Dedicated RAM” ‘1 Power Unit’ @ Hostrail: ( 4892 – 3074) * 4096 / 1024 / 1024 = 7.1MB out of 19.1MB used. *Ouch*

    256MB BuyVM: 0 – yes, zero – MB out of 89.1MB used.

    128MB NixCom: 0.86MB of 79.9MB used.

    256MB Spacerich: 3KB of 143.8MB used.

    256MB 123Systems: 4MB of 43.9MB used.

    128MB HostinginCanada: 0 – yes, zero – MB out of 15.6MB used.
    Second 128MB HostinginCanada: 0 – yes, zero – MB out of 18.5MB used.

    128MB VPS4LESS: 0 – yes, zero – MB out of 15MB used.

    Ancient 256MB ex-NYNOC (now Steadfast): 0 – yes, zero – MB out of 58.4MB used.

    368MB(?) ThrustVPS: 0.1MB out of 18.6MB used.

    So, overally, I’ve been somewhat lucky, I guess…

    November 10, 2010 @ 7:41 am | Reply
    • My HostRail VPS (4 power units) only swapped out 998 pages, or 3992 KiB of it’s 316 MB used.

      November 10, 2010 @ 4:17 pm | Reply
      • Snape:

        After this afternoon’s reboot of the Uranus node, the same VM above is now swapping zero of its 30.9MB used. I suspect they might have craftily adjusted a few things when they did the processor upgrade. (Or just added another couple gigs of RAM while they were at it.)

        It’s actually running at 0.00 load right now, i.e. no blocking iowait. If it stays like this for a couple days, I might even be willing to put it into production…

        November 10, 2010 @ 10:56 pm | Reply
  4. Heh heh heh…. there goes “the secret of overselling” good I/O and HDD.

    November 10, 2010 @ 7:58 am | Reply
  5. James:

    512MB – Europhase.net VPS – Zero (0.00MB) of 394MB used. *Phew*

    November 10, 2010 @ 8:38 am | Reply
  6. rm:

    Thanks for the great info!
    Here is a small script to do the calculation automatically:

    #!/bin/bash
    cat /proc/user_beancounters | grep -E '(uid|physpages|oomguarpages)'
    PHYS=`cat /proc/user_beancounters | grep " physpages " | awk '{print $2}'`
    OOMGUAR=`cat /proc/user_beancounters | grep " oomguarpages " | awk '{print $2}'`
    SWAP=$(($OOMGUAR-$PHYS))
    echo
    echo Swapped out: $SWAP pages, or $(($SWAP*4096/1024)) KiB

    November 10, 2010 @ 8:49 am | Reply
    • Yomero:

      Too useful :D

      Thanks!

      BTW, nice grep usage LEAdmin

      November 10, 2010 @ 8:51 am | Reply
      • marrco:

        Run the script on my 99 cents 64MB vpstree box:

        uid resource held maxheld barrier limit failcnt
        physpages 3554 12489 0 2147483647 0
        oomguarpages 3554 12489 16384 2147483647 0

        Swapped out: 31 pages, or 124 KiB

        November 10, 2010 @ 9:23 am | Reply
        • rm:

          Ah, 3554/3554 and still 31 pages… the script makes 3 separate accesses to that file, so it will be a bit imprecise. Still not by much and your result is nothing to worry about. Here’s a better version:
          #!/bin/bash
          cp /proc/user_beancounters /tmp/
          cat /tmp/user_beancounters | grep -E '(uid|physpages|oomguarpages)'
          PHYS=`cat /tmp/user_beancounters | grep " physpages " | awk '{print $2}'`
          OOMGUAR=`cat /tmp/user_beancounters | grep " oomguarpages " | awk '{print $2}'`
          SWAP=$(($OOMGUAR-$PHYS))
          rm /tmp/user_beancounters
          echo
          echo Swapped out: $SWAP pages, or $(($SWAP*4096/1024)) KiB

          November 10, 2010 @ 9:34 am | Reply
    • Thanks for the script.

      November 10, 2010 @ 10:31 am | Reply
      • marrco:

        thx rm, i used the new version of the script on my 99 cents 64MB vpstree box:

        uid resource held maxheld barrier limit failcnt
        physpages 3579 12489 0 2147483647 0
        oomguarpages 3579 12489 16384 2147483647 0

        Swapped out: 0 pages, or 0 KiB

        November 10, 2010 @ 1:09 pm | Reply
    • This does not seem to work on 2 out of 3 of my OpenVZ VPSs.

      November 10, 2010 @ 4:25 pm | Reply
      • Yomero:

        Lol, forgot sudo? xD

        Yes, I didn’t advised the mistake in the script, now is consistent.
        Ty, rm n_n

        My 99C vps doesn’t swap :D and is the VPS with BEST I/O I have o_O

        November 10, 2010 @ 4:53 pm | Reply
        • I was running it from root on all 3.

          uid resource held maxheld barrier limit failcnt
          physpages 26999 46999 0 2147483647 0
          oomguarpages 29897 47318 131072 2147483647 0
          Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
          Usage: awk [POSIX or GNU style options] [--] 'program' file ...
          POSIX options: GNU long options:
          -f progfile --file=progfile
          -F fs --field-separator=fs
          -v var=val --assign=var=val
          -m[fr] val
          -W compat --compat
          -W copyleft --copyleft
          -W copyright --copyright
          -W dump-variables[=file] --dump-variables[=file]
          -W exec=file --exec=file
          -W gen-po --gen-po
          -W help --help
          -W lint[=fatal] --lint[=fatal]
          -W lint-old --lint-old
          -W non-decimal-data --non-decimal-data
          -W profile[=file] --profile[=file]
          -W posix --posix
          -W re-interval --re-interval
          -W source=program-text --source=program-text
          -W traditional --traditional
          -W usage --usage
          -W version --version

          To report bugs, see node `Bugs' in `gawk.info', which is
          section `Reporting Problems and Bugs' in the printed version.

          gawk is a pattern scanning and processing language.
          By default it reads standard input and writes standard output.

          Examples:
          gawk '{ sum += $1 }; END { print sum }' file
          gawk -F: '{ print $1 }' /etc/passwd
          /bin/swapcheck: line 7: {print $2}: command not found
          /bin/swapcheck: line 7: - physpages 27065 46999 0 2147483647 0: syntax error in expression (error token is "27065 46999 0 2147483647 0")

          /bin/swapcheck: line 9: *4096/1024/1024: syntax error: operand expected (error token is "*4096/1024/1024")
          /bin/swapcheck: line 10: *4096/1024/1024: syntax error: operand expected (error token is "*4096/1024/1024")

          November 10, 2010 @ 7:18 pm | Reply
    • labrador:


      #!/bin/sh

      awk '
      $1 ~ /^physpages$/ { phys=$2 }
      $1 ~ /^oomguarpages$/ { oomguar=$2 }
      END { printf "%.1fM / %.1fM\n", (oomguar - phys) / 256, oomguar / 256 }
      ' /proc/user_beancounters

      November 10, 2010 @ 5:30 pm | Reply
    • ibk:

      Thanks!
      Nice script

      November 11, 2010 @ 5:42 am | Reply
  7. Sidahmed:

    Thanks for sharing this,

    @Everyone, Remember this is only shows how much SWAP you are using (NOW), it is not necessarily over selling, it could simply means the provider doesn’t do good monitoring and controlling over the node. And in case of over selling, it many not give you the real picture, since most of clients may not be using the ALL guaranteed RAM. You need to repeatedly get these numbers to get a clear picture.

    November 10, 2010 @ 9:29 am | Reply
  8. BuyVM Freemont 1GB ram, (2GB burstable)


    uid resource held maxheld barrier limit failcnt
    physpages 96214 119778 0 2147483647 0
    oomguarpages 121540 142563 262144 2147483647 0

    98MB out of 474MB
    Damn, I knew BUYVM sucked from the first month I got them. ah well. using for backup storage now.

    November 10, 2010 @ 9:31 am | Reply
  9. I wrote a Munin Plugin to graph this behavior on openVZ, and also have a cron bash script to check and alert by email.
    check on my blog:

    bash script: http://www.frederico-araujo.com/2010/07/09/check-guaranteed-ram-burstable-ram-o-openvz/

    Munin plugin on github: http://github.com/fred/munin_plugins

    and the code is in my github.

    contributions and improvements are welcome :)

    November 10, 2010 @ 9:32 am | Reply
  10. Jamie:

    Nothing in swap at Ramhost :)

    November 10, 2010 @ 9:43 am | Reply
  11. root@lalalalala:~# bash calc.sh
    uid resource held maxheld barrier limit failcnt
    physpages 58041 118340 0 9223372036854775807 0
    oomguarpages 58041 118340 131072 131072 0

    Swapped out: 0 pages, or 0 KiB

    this at bluemilecloud. is this swaped?

    November 10, 2010 @ 10:11 am | Reply
  12. this is from hostrail

    sh calc.sh
    uid resource held maxheld barrier limit failcnt
    physpages 2321 8219 0 2147483647 0
    oomguarpages 2321 8219 98304 2147483647 0

    Swapped out: 0 pages, or 0 KiB

    November 10, 2010 @ 10:13 am | Reply
  13. BuyVM

           uid  resource                     held              maxheld              barrier                limit              failcnt
                physpages                   86276               119778                    0           2147483647                    0
                oomguarpages               110315               142563               262144           2147483647                    0
    
    Swapped out: 24017 pages, or 96068 KiB
    

    free

    # free
                 total       used       free     shared    buffers     cached
    Mem:          2048        597       1450          0          0          0
    -/+ buffers/cache:        597       1450
    Swap:            0          0          0
    
    November 10, 2010 @ 10:28 am | Reply
  14. Alright. Here is the script I use. Coded in C so minimum memory usage.

    $ wget -O - http://www.lowendbox.com/scripts/vzfree.c 2>/dev/null | gcc -o vzfree -x c -
    $ sudo ./vzfree
                 Total     Used     Free
    Kernel:   2048.00M    2.92M 2045.08M
    Allocate:  512.00M   64.71M  447.29M (256M Guaranteed)
    Commit:    256.00M   33.57M  222.43M (47.4% of Allocated)
    Swap:                 5.50M          (17.9% of Committed)
    

    It compiles the C code into an executable, and then run the program “vzfree”. It needs root access to read /proc/user_beancounters.

    Also don’t trust me — read the code! :) Just in case you want to know what gets executed with root privilege.

    November 10, 2010 @ 10:51 am | Reply
    • sweet. that is fast.
      Good to know you do C. I love C too.

      November 10, 2010 @ 11:25 am | Reply
    • dannix:

      I didn’t look exactly at the vzfree.c code, so no warannty at all,
      but if you want use as a normal user, just do the following

      cp vzfree /usr/local/bin/vzfree
      chmod 4750 /usr/local/bin/vzfree
      # check to which group the files belongs to in this folder
      ls -la /usr/local/bin/vzfree
      # add yourself to this group

      November 10, 2010 @ 1:10 pm | Reply
    • Awesome Bro

      November 10, 2010 @ 1:55 pm | Reply

    • ksx4system@ramses:~/skrypty$ sudo ./vzfree
      Total Used Free
      Kernel: 2048.00M 1.01M 2046.99M
      Allocate: 1024.00M 5.05M 1018.95M (512M Guaranteed)
      Commit: 512.00M 4.43M 507.57M (67.6% of Allocated)
      Swap: 0.00M (0.0% of Committed)

      done using vzfree.c on CityNetHost’s $2,50/month OpenVZ VPS :-)

      November 10, 2010 @ 2:31 pm | Reply
  15. Christos:

    HostRail :


    sudo cat /proc/user_beancounters | grep -E '(uid|physpages|oomguarpages)'
    uid resource held maxheld barrier limit failcnt
    physpages 2795 20218 0 2147483647 0
    oomguarpages 2795 20218 98304 2147483647 0

    November 10, 2010 @ 11:12 am | Reply
  16. thanks LEA

    November 10, 2010 @ 11:17 am | Reply
  17. hey,lowendadmin

    By default, the page size is 4k , but you have to run

    getconf PAGE_SIZE

    to see if it is not 8k or 16k

    November 10, 2010 @ 11:25 am | Reply
    • True. Just that I haven’t seen one that is not 4k :)

      November 10, 2010 @ 11:40 am | Reply
      • i have seen a lot. Note that 4k page size can only map 4G memory directly. If you have a server with 32G memory and you want a high performance, larger page size is needed(8k or 16k).

        November 10, 2010 @ 12:25 pm | Reply
      • and in 64bit OS

        November 10, 2010 @ 12:30 pm | Reply
      • You sure? :) Variable pagesize is usually only for x86 Linux boxens. All x86_64 ones I came across with are fixed to 4kb (and have no problem accessing over 4GB of memory address either for obvious reason).

        November 10, 2010 @ 12:51 pm | Reply
  18. Matt T.:

    mine look ok;

    quickweb SupaVZ1

    Total Used Free
    Kernel: 2048.00M 4.12M 2043.88M
    Allocate: 768.00M 221.47M 546.53M (512M Guaranteed)
    Commit: 512.00M 104.13M 407.87M (45.2% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    quickweb testbox01


    Kernel: 2048.00M 2.72M 2045.28M
    Allocate: 150.00M 45.26M 104.74M (128M Guaranteed)
    Commit: 128.00M 18.82M 109.18M (35.6% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    November 10, 2010 @ 11:36 am | Reply
  19. Thanks for the script and c code:)
    ./vzfree
    Total Used Free
    Kernel: 2048.00M 3.38M 2044.62M
    Allocate: 1024.00M 28.01M 995.99M (512M Guaranteed)
    Commit: 512.00M 18.88M 493.12M (55.3% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    November 10, 2010 @ 11:47 am | Reply
  20. Tom:

    Using LEA’s vzfree.c none of the following rockmyweb, nordicvps, buyvm have any swap =]

    November 10, 2010 @ 12:10 pm | Reply
    • JockTwo:

      Give some updates on rockmyweb man… how’s it going with them. Any issues? How long have you had them? etc etc.

      I almost went with them, but then xen called.

      November 10, 2010 @ 12:57 pm | Reply
  21. BuyVM – 128mb OpenVZ

    Total Used Free
    Kernel: 2048.00M 2.72M 2045.28M
    Allocate: 256.00M 37.11M 218.89M (128M Guaranteed)
    Commit: 128.00M 22.36M 105.64M (52.9% of Allocated)
    Swap: 0.51M (2.6% of Committed)

    November 10, 2010 @ 12:27 pm | Reply
  22. razor:

    NordicVPS
    512 – OVZ

    Total Used Free
    Kernel: 2048.00M 5.56M 2042.44M
    Allocate: 1024.00M 142.35M 881.65M (512M Guaranteed)
    Commit: 512.00M 83.90M 428.10M (55.0% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    November 10, 2010 @ 12:31 pm | Reply
  23. Very neat.

    Now for something to test oversold disk IO :)

    November 10, 2010 @ 12:42 pm | Reply
  24. JockTwo:

    Yard VPS (lead-1 the $15 a year plan)
    Swapped out: 1 page or 4 Kib.
    Another run-
    Swapped out: 0 pages or 0 Kib.

    This guy was pretty fast till about yesterday; now there is a noticeable lag when entering commands; but no other issues. Ok one: All the OS images come with Apache+sendmail by default. I don’t know how to use anything except nginx.

    November 10, 2010 @ 1:00 pm | Reply
  25. Alfred:

    bluemile vz512

    Total Used Free
    Kernel: 14.11M 2.89M 11.21M
    Allocate: 1024.00M 28.67M 995.33M (512M Guaranteed)
    Commit: 512.00M 19.65M 492.35M (58.5% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    November 10, 2010 @ 2:01 pm | Reply
  26. BUYVM does swap, and badly.

    Total Used Free
    Kernel: 2048.00M 5.26M 2042.74M
    Allocate: 2048.00M 596.22M 1451.78M (1024M Guaranteed)
    Commit: 1024.00M 429.15M 594.85M (71.1% of Allocated)
    Swap: 117.46M (27.7% of Committed)

    a lot of swap as you can see.

    November 10, 2010 @ 2:05 pm | Reply
  27. dannix:

    I would propose that instead of

    sudo cat /proc/user_beancounters | grep -E '(uid|physpages|oomguarpages)'

    use

    sudo grep -E '(uid|physpages|oomguarpages)' /proc/user_beancounters

    Here a small benchmark

    $> time for i in `seq 1 10000`; do cat /proc/user_beancounters | grep -E '(uid|physpages|oomguarpages)' >/dev/null; done

    real 0m31.412s
    user 0m9.864s
    sys 0m21.486s
    $> time for i in `seq 1 10000`; do grep -E '(uid|physpages|oomguarpages)' /proc/user_beancounters >/dev/null; done

    real 0m17.727s
    user 0m6.532s
    sys 0m11.193s
    $>

    Or read about useless use of cat award.

    November 10, 2010 @ 2:23 pm | Reply
    • LOL. cat or grep –> which one would I rather give root privilege to?! :)

      November 10, 2010 @ 10:21 pm | Reply
      • dannix:

        If you didn’t restrict the permissions, then both cat and grep can be executed by the user. What you need here are terms to this one file. You can configure sudo either cat or grep for ubc file . And since we are dealing here will lowend machines I would go for grep.

        November 11, 2010 @ 6:42 am | Reply
        • Joshbaptiste:

          Indeed “cat | grep” is UUOC (Useless Use if Cat)..
          also seq(1) is GNU/Linux”ish”, for i in {1..1000}; .. (bash 3) is more portable .. for the BSD centric people here.

          November 13, 2010 @ 3:57 am | Reply
        • rm:

          @Joshbaptiste
          Okay, optimizing cat vs grep for microsecond-scale performance gain was already dumb enough, but “for the BSD centric people here”, really? And your BSD runs OpenVZ too, I suppose? Being a shell syntax nazi helps no one in a script that is run once in a while (no one cares if it’s 0.01 sec or 0.02 sec), and only on one platform (GNU/Linux).

          November 13, 2010 @ 4:54 am | Reply
  28. Jab~:

    GigeVPS cheapest Package:

    Total Used Free
    Kernel: 2048.00M 4.64M 2043.36M
    Allocate: 768.00M 97.62M 670.38M (384M Guaranteed)
    Commit: 384.00M 46.75M 337.25M (43.1% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    November 10, 2010 @ 2:36 pm | Reply
  29. Gary:

    Ok, here goes. :)

    ITExperts (VPS ITE FR- 256)

    Total Used Free
    Kernel: 10.54M 4.15M 6.40M
    Allocate: 256.00M 78.34M 177.66M (256M Guaranteed)
    Commit: 256.00M 51.52M 204.48M (60.5% of Allocated)
    Swap: 2.01M (4.2% of Committed)

    hostrail (1 unit)

    Total Used Free
    Kernel: 2048.00M 1.35M 2046.65M
    Allocate: 256.00M 9.33M 246.67M (256M Guaranteed)
    Commit: 256.00M 6.25M 249.75M (52.5% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    GigeVPS (Silver)

    Total Used Free
    Kernel: 2048.00M 1.69M 2046.31M
    Allocate: 1024.00M 26.40M 997.60M (512M Guaranteed)
    Commit: 512.00M 13.59M 498.41M (45.1% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    TinyVPS (Standard package)

    Total Used Free
    Kernel: 2048.00M 1.78M 2046.22M
    Allocate: 128.00M 15.64M 112.36M (64M Guaranteed)
    Commit: 64.00M 11.96M 52.04M (65.1% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    AvailableVPS ($14/year deal from here)

    Total Used Free
    Kernel: 2048.00M 2.51M 2045.49M
    Allocate: 512.00M 48.89M 463.11M (128M Guaranteed)
    Commit: 128.00M 26.42M 101.58M (48.9% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    KnowinServers (KS L 300)

    Total Used Free
    Kernel: 2048.00M 2.65M 2045.35M
    Allocate: 784.00M 29.79M 754.21M (512M Guaranteed)
    Commit: 512.00M 14.28M 497.72M (39.0% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    Hostfolks (Deluxe)

    Total Used Free
    Kernel: 2048.00M 1.10M 2046.90M
    Allocate: 512.00M 16.38M 495.62M (409M Guaranteed)
    Commit: 409.00M 10.11M 398.89M (55.0% of Allocated)
    Swap: 2.01M (22.3% of Committed)

    November 10, 2010 @ 3:21 pm | Reply
  30. Daniel:

    NixcomCA

    Total Used Free
    Kernel: 2048.00M 1.91M 2046.09M
    Allocate: 1024.00M 40.75M 983.25M (512M Guaranteed)
    Commit: 512.00M 33.02M 478.98M (76.3% of Allocated)
    Swap: 5.43M (17.5% of Committed)

    Don’t know if its good or bad.

    November 10, 2010 @ 3:53 pm | Reply
    • At least it’s not 100% swapped. :)

      Thanks for this. Kind of wondered how some hosts were guaranteeing all this memory.

      November 10, 2010 @ 7:23 pm | Reply
      • rm:

        Certain amount of swap is actually okay — some program could load tens or hundreds megabytes of data into RAM, and then not access it for hours. What’s the point of keeping that in RAM, it is perfectly fine for the OS to shift those pages from memory to disk, to allow for more file cache, for example.

        It is ONLY when you notice unexplained slowdowns on your VPS, that you should care about the swap percentage. And then if it is high, then definitely the problem is too much RAM overselling.

        November 10, 2010 @ 7:31 pm | Reply
        • Daniel:

          Havent noticed any slowness in my VPS.

          November 10, 2010 @ 7:35 pm | Reply
        • I guess the problem with OpenVZ is — it is the host OS who decides which pages should be swapped out, whereas it is your own kernel that decides. If I do prefer most my pages to be resident and don’t use cache much, I can tune my swapiness down on Xen/VMWare. I can’t do that on OpenVZ!

          November 10, 2010 @ 10:31 pm | Reply
  31. root@roubaix:~# sudo cat /proc/user_beancounters | grep -E '(uid|physpages|oomguarpages)'
    uid resource held maxheld barrier limit failcnt
    physpages 8715 16028 0 2147483647 0
    oomguarpages 8715 16028 32768 2147483647 0
    root@roubaix:~#

    Why does mine display like this?

    November 10, 2010 @ 5:07 pm | Reply
    • Perhaps you might want to read LEA’s comment #14?

      Anyway both yours showed 8715 pages, indicating that there’s no swap used.

      November 10, 2010 @ 5:36 pm | Reply
  32. Anyone care to write a Nagios plugin? If not I will put it on my to-do list… it’ll probably take forever for me to get it though.

    November 10, 2010 @ 5:54 pm | Reply
    • I can write a Nagios check for this in under 5 minutes. You can find my address on my site.

      Or you can download my Nagios check skeleton and fill in the parts yourself.

      Also, here is how to do the check in one line:

      awk ‘{if ($1==”physpages”){p=$2} else if ($1==”oomguarpages”){o=$2} } END{s=(o-p)/256; print s}’ /proc/user_beancounters

      Change the denominator on the end calculation if you want it in units other than megabytes.

      November 10, 2010 @ 6:22 pm | Reply
      • Thanks Richard, that looks good. Will try out later.

        November 10, 2010 @ 6:28 pm | Reply
  33. Jhonathan:

    YardVPS LEAF 2, 3.5$/mo

                 Total     Used     Free
    Kernel:   2048.00M    5.92M 2042.08M
    Allocate:  512.00M  191.99M  320.01M (256M Guaranteed)
    Commit:    256.00M   60.37M  195.63M (28.4% of Allocated)
    Swap:                 0.00M          (0.0% of Committed)
    

    gigevps bronze, 4.46$/mo

                 Total     Used     Free
    Kernel:   2048.00M    5.61M 2042.39M
    Allocate:  768.00M   49.68M  718.32M (384M Guaranteed)
    Commit:    384.00M   42.73M  341.27M (74.7% of Allocated)
    Swap:                 0.00M          (0.0% of Committed)
    

    thrustvps Aquatic, 4.95$/mo

                 Total     Used     Free
    Kernel:   2048.00M    6.29M 2041.71M
    Allocate: 1024.00M  221.98M  802.02M (512M Guaranteed)
    Commit:    512.00M   61.02M  450.98M (24.7% of Allocated)
    Swap:                 0.00M          (0.0% of Committed)
    
    November 11, 2010 @ 12:02 am | Reply
  34. Is these check method correctly ?

    My result:

    root@sunset:~# ./t.sh
    uid resource held maxheld barrier limit failcnt
    physpages 55880 100224 0 2147483647 0
    oomguarpages 55890 100233 98304 2147483647 0

    Swapped out: 106 pages, or 424 KiB
    root@sunset:~# ./vzfree
    Total Used Free
    Kernel: 2048.00M 3.93M 2044.07M
    Allocate: 512.00M 252.55M 259.45M (384M Guaranteed)
    Commit: 384.00M 222.13M 161.87M (86.4% of Allocated)
    Swap: 0.04M (0.0% of Committed)

    what does these words mean?

    November 11, 2010 @ 6:02 am | Reply
  35. Matrix:

    Total Used Free
    Kernel: 2048.00M 6.06M 2041.94M
    Allocate: 512.00M 243.74M 268.26M (384M Guaranteed)
    Commit: 384.00M 175.79M 208.21M (69.6% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    Mine from Quickweb..

    November 11, 2010 @ 5:12 pm | Reply
  36. Josh:

    PhotonVPS BEAM2 $20.95/mo

                 Total     Used     Free
    Kernel:   2048.00M   12.90M 2035.10M
    Allocate: 2048.00M  145.48M 1902.52M (1024M Guaranteed)
    Commit:   1024.00M  102.42M  921.58M (61.5% of Allocated)
    Swap:                 9.33M          (10.4% of Committed)
    

    YardVPS LEAF2 $3.5/mo

                 Total     Used     Free
    Kernel:   2048.00M    3.35M 2044.65M
    Allocate:  512.00M  176.14M  335.86M (256M Guaranteed)
    Commit:    256.00M  164.68M   91.32M (91.6% of Allocated)
    Swap:                 0.00M          (0.0% of Committed)
    

    EnotchNetworks HADES $5.95/mo

                 Total     Used     Free
    Kernel:   2048.00M    6.70M 2041.30M
    Allocate:  512.00M   80.64M  431.36M (512M Guaranteed)
    Commit:    512.00M   49.42M  462.58M (53.0% of Allocated)
    Swap:                 0.00M          (0.0% of Committed)
    

    Virpus Virtulpulse $5/mo

                 Total     Used     Free
    Kernel:   2048.00M    6.74M 2041.26M
    Allocate: 2048.00M   89.13M 1958.87M (512M Guaranteed)
    Commit:    512.00M   36.58M  475.42M (33.5% of Allocated)
    Swap:                 0.00M          (0.0% of Committed)
    

    i need your advice guys… i dont know it is good or not
    thanks

    November 12, 2010 @ 4:45 pm | Reply
    • Yomero:

      Of course is good n_n

      November 13, 2010 @ 8:18 am | Reply
  37. Does this work on Debian?

    November 12, 2010 @ 6:27 pm | Reply
    • dannix:

      Sure it works. I’m using only debian on all my servers.

      November 12, 2010 @ 6:58 pm | Reply
      • Daniel:

        for debian, to use/compile LEAs program, I had to apt-get install gcc, so didn’t work from bare install.

        November 12, 2010 @ 8:35 pm | Reply
        • Yomero:

          Properly, apt-get install build-essential

          November 13, 2010 @ 8:17 am | Reply
  38. William:

    C’mon guys…I’m sure you realize the value of a low end box is to learn and to run simple or low traffic sites. You wouldn’t be using a cheap VPS for your folding@home clone (or whatever you want to do) lol

    November 12, 2010 @ 10:48 pm | Reply
  39. Nnyan:

    yardVPS $15/year VPS

    [root@gallifrey ~]# sudo ./vzfree
    audit_log_user_command(): Connection refused
    Total Used Free
    Kernel: 2048.00M 2.66M 2045.34M
    Allocate: 256.00M 32.20M 223.80M (128M Guaranteed)
    Commit: 128.00M 17.58M 110.42M (46.3% of Allocated)
    Swap: 0.00M (0.0% of Committed)
    [root@gallifrey ~]#

    November 13, 2010 @ 1:57 am | Reply
    • i love that server name

      November 13, 2010 @ 9:18 am | Reply
    • I thought it had already been destroyed by the Dalek?

      No worries :) I used to have a server named “Alderaan”. Bad choice!

      November 13, 2010 @ 10:15 am | Reply
  40. Cecito:

    VPS FiberFirefly 5€/mo

    [code] Total Used Free
    Kernel: 2048.00M 8.03M 2039.97M
    Allocate: 384.00M 128.46M 255.54M (256M Guaranteed)
    Commit: 256.00M 109.17M 146.83M (78.7% of Allocated)
    Swap: 0.00M (0.0% of Committed)
    [/code]

    November 13, 2010 @ 3:42 pm | Reply
  41. Tom:

    Node 7 of citynethost =/

    Kernel: 2048.00M 3.33M 2044.67M
    Allocate: 1024.00M 247.96M 776.04M (512M Guaranteed)
    Commit: 512.00M 81.47M 430.53M (31.5% of Allocated)
    Swap: 4.57M (5.8% of Committed)

    November 23, 2010 @ 8:43 am | Reply
  42. On my HostRail (1 Power Units) VPS.

    endor:~# sudo ./vzfree
    Total Used Free
    Kernel: 2048.00M 2.26M 2045.74M
    Allocate: 256.00M 81.19M 174.81M (256M Guaranteed)
    Commit: 256.00M 70.99M 185.01M (84.7% of Allocated)
    Swap: 0.00M (0.0% of Committed)
    endor:~#

    November 24, 2010 @ 9:47 pm | Reply
  43. Mizrahi:

    GigeVPS 384MB in UK
    [root@uk2 ~]# ./vzfree
    Total Used Free
    Kernel: 2048.00M 2.80M 2045.20M
    Allocate: 768.00M 21.07M 746.93M (384M Guaranteed)
    Commit: 384.00M 15.45M 368.55M (60.1% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    BuyVM 1GB
    -01:31:04- zebes:~ root% ./vzfree
    Total Used Free
    Kernel: 2048.00M 2.77M 2045.23M
    Allocate: 1024.00M 19.28M 1004.72M (512M Guaranteed)
    Commit: 512.00M 12.86M 499.14M (52.4% of Allocated)
    Swap: 0.00M (0.0% of Committed)

    December 8, 2010 @ 10:35 pm | Reply
  44. Daniel:

    Nice.

    December 19, 2010 @ 9:12 pm | Reply
  45. My BuyVM VPS:

                 Total     Used     Free
    Kernel:   2048.00M    3.54M 2044.46M
    Allocate:  512.00M  129.89M  382.11M (256M Guaranteed)
    Commit:    256.00M   63.93M  192.07M (46.5% of Allocated)
    Swap:                 3.05M          (5.1% of Committed)

    My other 2 are not swapping at all, but that might be because they are only allocating 16 to 20mb/committing to 10 to 6mb

    May 3, 2011 @ 12:54 pm | Reply
  46. UptimeVPS 5 EUR / year

                   Total       Used       Free
    Kernel:     2048.00M      2.80M   2045.20M
    Allocate:    256.00M     60.41M    195.59M (128M Guaranteed)
    Commit:      128.00M     31.91M     96.09M (48.2% of Allocated)
    Swap:                     0.00M            (0.0% of Committed)
    
    September 9, 2011 @ 10:13 pm | Reply
    • This is in a Centos 5 node? Because in Centos 6 is so… funny (UptimeVPS)

      # ./vzfree
                     Total       Used       Free
      Kernel:      192.00M     15.77M    176.23M
      Allocate: 36028797018963968.00M     51.24M 36028797018963916.00M (36028797018963967M Guaranteed)
      Commit:   36028797018963968.00M     34.14M 36028797018963932.00M (35.9% of Allocated)
      Swap:                  -100.63M            (-547.5% of Committed)
      
      September 9, 2011 @ 10:52 pm | Reply
      • Mizrahi:

        @Yomero:
        CentOS 6 and OpenVZ for 2.6.32 report values differently with the introduction of vSwap/deprecation of UBC.

        September 9, 2011 @ 10:56 pm | Reply
      • Yeah with a typical VSwap host, it usually max out all the bean counter values so “vzfree” output would not make sense.

        September 10, 2011 @ 12:11 pm | Reply
  47. Aaron:

    up2vps – Made me sad :(
    Total Used Free
    Kernel: 2048.00M 7.40M 2040.60M
    Allocate: 1024.00M 678.14M 345.86M (1024M Guaranteed)
    Commit: 1024.00M 336.08M 687.92M (48.5% of Allocated)
    Swap: 55.24M (16.8% of Committed)

    November 21, 2011 @ 3:58 pm | Reply
  48. matthew morgan:

    virtualsrv 4gb ram open vz
    [root@matthew ~]# free -m
    total used free shared buffers cached
    Mem: 4096 447 3648 0 0 0
    -/+ buffers/cache: 447 3648
    Swap: 0 0 0
    [root@matthew ~]#

    [root@matthew ~]# cat /proc/user_beancounters | grep -E ‘(uid|physpages|oomguarpages)’
    uid resource held maxheld barrier limit failcnt
    physpages 26459 28331 0 2147483647 0
    oomguarpages 26459 28331 524288 2147483647 0
    [root@matthew ~]#

    oomguarpages-physpages=0mb
    not oversold

    February 18, 2012 @ 4:11 am | Reply
  49. K-Ray:

    what if this is negative?

    my first VPS:

           uid  resource                     held              maxheld              barrier                limit              failcnt
                physpages                    5136               141432                    0           2147483647                    0
                oomguarpages                 5151               141432               131072           2147483647                    0
    

    Pretty good I guess. Because I was only using a very small bit of the resources I downgraded from 512M to 256M RAM. But now I have this result:

           uid  resource                     held              maxheld              barrier                limit              failcnt
                physpages                    2035                 5109                    0                65536                    0
                oomguarpages                  409                  419  9223372036854775807  9223372036854775807                    0    
    

    What should I make of this ??

    December 30, 2012 @ 3:46 pm | Reply
  50. Dalibut:

    Getting same as poster above , RocketVPS getting negative value , what to make of negative value anyone ?

    physpages 120899
    oomguarpages 40836

    Kernel: 2048.00M 15.83M 2032.17M
    Allocate: 1024.00M 579.37M 444.63M (512M Guaranteed)
    Commit: 512.00M 176.55M 335.45M (27.7% of Allocated)
    Swap: -312.91M (-194.7% of Committed)

    free command:
    total used free shared buffers cached
    Mem: 1048576 482496 566080 0 0 304136
    -/+ buffers/cache: 178360 870216
    Swap: 0 0 0

    March 3, 2013 @ 1:11 pm | Reply
  51. root@coral [~]# cat /proc/user_beancounters | grep -E ‘(uid|physpages|oomguarpages)’
    uid resource held maxheld barrier limit failcnt
    physpages 374003 461463 0 393216 0
    oomguarpages 100566 195973 9223372036854775807 9223372036854775807 0

    Wellcome ;D

    April 12, 2013 @ 2:26 pm | Reply
  52. tecjam:

    having swapped pages does not allways mean that the maschine is overselled.

    e.g. having /proc/sys/vm/swappiness set to 60 and the maschines ram usage is 70% the kernel may decided to move some unused pages to swap to get more space for io-cache.
    if the value of swapped pages is quite high, its an indicator for heavy overselling.

    i run openvz maschines for some time and your can oversell memory quite a lot cause the kernel merges memorypages: 100 VMs with same distribution and same services won’t use (real) 100*n mb memory.

    i wrote a script which sums all pages used by each container: overall usage: >40G while host’s ram was used only 12-14G.

    this behavior i noticed while doing a live migration of a bigger container: after migration a container using ~ 4G ram, the host memory usage only increased by come hindret mb.

    June 29, 2013 @ 1:55 am | Reply
  53. maxwell:

    [root@Indiaovz data0]# sudo ./vzfree
    Total Used Free
    Kernel: 256.00M 51.83M 204.17M
    Allocate: 36028797018963968.00M 230.80M 36028797018963736.00M (36028797018963967M Guaranteed)
    Commit: 36028797018963968.00M 99.26M 36028797018963868.00M (20.6% of Allocated)
    Swap: -458.82M (-967.4% of Committed)

    What’s up?

    August 11, 2013 @ 2:46 pm | Reply
  54. What if oomguarpages is less than physpages? I got confused...

    OneAsiaHost 128MB OpenVZ SSD:

    root@oah:~# cat /proc/user_beancounters | grep -E '(uid|physpages|oomguarpages)'
           uid  resource                     held              maxheld              barrier                limit              failcnt
                physpages                   13769                18772                    0                65536                    0
                oomguarpages                 6026                 6026                32768           2147483647                    0
    
    

    and

    root@oah:~# ./vzfree
                   Total       Used       Free
    Kernel:     2048.00M      4.89M   2043.11M
    Allocate:    256.00M    146.02M    109.98M (128M Guaranteed)
    Commit:      128.00M     28.35M     99.65M (16.1% of Allocated)
    Swap:                   -45.21M            (-192.7% of Committed)
    
    
    root@oah:~# uname -a
    Linux oah 2.6.32-042stab079.5 #1 SMP Fri Aug 2 17:16:15 MSK 2013 i686 i686 i386 GNU/Linux
    
    
    February 3, 2014 @ 8:02 am | Reply
  55. T. Rutter:

    To those later commenters who are finding negative values when using this method:

    You are using a newer implementation of OpenVZ memory management which uses vSwap – a fairer and more transparent system. In this system, the user_beancounters are mostly irrelevant – apart from the physpages.limit which shows the amount of guaranteed physical RAM you’ve been allocated.

    To view the swap usage, just use “free -m”. For modern vSwap enabled OpenVZ systems, that value _is_ accurate.

    On a non-oversold system, this vSwap is actually in memory, not on disk. It’s just slowed down a bit to emulate disk-based swap. This is a fair system that ensures everyone gets the physical memory they’re supposed to, but can use a little more as virtual swap. If host resources are tight, some of this vSwap may be actual disk-based swap.

    Either way, you don’t need to resort to these scripts (which read user_beancounters) any more. “free -m” works fine now to show swap usage.

    June 17, 2014 @ 6:50 am | Reply

Leave a Reply to Jackk Cancel reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

Your email address will not be published. Required fields are marked *