virtualization - high virtual memory usage in openvz?

24
2014-04
  • freedrull

    We're having a lot of memory problems on a new OpenVZ box. It is supposed to have 1 gig of memory, I'm not sure how much of that is burstable or guaranteed memory. Programs in general seem to take up more virtual memory than they do on my box at home, and on our other OpenVZ box.

    I wrote this simple C program:

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(){
      char *thingy = malloc(500);
      getchar():
      return 0;
    }
    

    So it simply allocates 500 bytes and then returns. I ran the program on 3 computers. On my home machine, and our other OpenVZ box it shows about 1k bytes of virtual memory being used. On the new problematic machine its about 3k.

    I know this is just virtual memory and not resident memory, but why is this machine allocating so much virtual memory? Are there some settings I need to adjust to the OpenVZ memory settings?

    I tried changing the stack size with ulimit -s 256 and restarting some demons, but I still saw the same results.

    I'm doing all of my monitoring with htop, is this even a good program to use with a OpenVZ vps? I've read I should be parsing the output of /proc/user_beancounters intead or something.

    I should note this memory usage appears to be leading to crashes. :\

  • Answers
  • David Schwartz

    Because virtual memory is effectively free, nobody bothers to optimize the use of it. Most likely, it's just allocating a large amount to avoid having to allocate more later.

    A larger allocation costs the same as a small allocation. But two small allocations cost more than one large one.


  • Related Question

    windows - Physical memory usage always high!
  • AntonioCS

    I recently installed windows XP Pro and also installed a few programs (avast, tortoise, apache, php, mysql). Nothing that should be a resource hog.

    I have an image of process explorer: http://imagebin.org/73193
    It shows that the physical memory is always high (I only have 1gb).

    The list in process explorer and in windows taks manager tells me that firefox has the highest memory consumption (which is normal).

    I can't figure out what is consuming so much memory. Anyone know how I can find out??

    This is an Acer laptop 1694 WLMI running WinXP PRO with all updates


  • Related Answers
  • invert

    The list in process explorer and in windows taks manager tells me that firefox has the highest memory consumption (which is normal).

    the list tells me, the bloody Spybot S&D TeaTimer has the highest memory consumption (> 300 MB). knock it off!

    other resource hogs, apart from your antivirus software, are MSN/WLM (alternative: Miranda IM) and Launchy (alternative: SlickRun), replacing those will save you another 100 meg.

  • Chris

    ashserv.exe is part of the Avast Anti-virus Suite. Reading this forum post, it seems that Avast is somewhat of a resource hog. You might want to rethink your anti-virus software and find something that may use less resouces. Microsoft Essentials is a free anti-virus program that is supposed to run in the background and not use many resources. You might want to try that approach.

    Good luck and hope this helps some.

  • JMD

    In addition to the recommendations about Avast, if you really have to run the database and web servers on this laptop then you really ought to consider trimming down the "optional" memory consumption. For example, do you also have to run Skype? And Firefox is consuming ~169MB of RAM. That's 16% of your RAM right there. Granted, you're doing web development. But if you really have to run all these services then you'll have to trim somewhere. Can you unload FF plugins? What about not having a bunch of "extra" tabs open?

    But all of that will ultimately make little difference. Your two biggest concerns are:

    1. Get the DB server, and preferably the Apache server too, moved off this laptop.
    2. Get more RAM for this laptop. RAM is cheap. Laptop RAM is less so, admittedly, but that will have the biggest impact on improving your machine's capacity to handle all the stuff you're throwing at it.

    Freeing up 10-20MB in two or three pales compared to removing the entire DB server and adding another GB of RAM. :)

  • shf301

    To tell how much actual RAM a program is using, run Task Manager (hit Ctrl+Esc), and look ad the Mem Usage tab in the Processes tab. That will show how much RAM a process is using at the current time. That peak working set column in Process Explorer shows the maximum amount of RAM a process used at any point, so it may or may not be relevant.

    But your memory usage doesn't seem to be that bad, according to the Physical Memory section of the screen shot.

    Total:          1,046,576KB
    Available:        221,946KB
    System Cache:     265,212KB
    

    So about 25% of your RAM is free and about 25% is being used for Windows file cache, leaving 559,419KB in use by applications. So applications are using around 512MB (or 50%) of your RAM. That physical memory graph counts the file cache in what it shows, so it's showing you at 75% usage.

    According to the Kernel Memory section of your screen shot, the Windows kernel is using 50MB. Firefox is probably taking 100MB itself and is your PHP IDE. So with those three things you've already accounted for more than half of your memory usage.