Linux out of memory on VPS
Solution 1:
OpenVZ providers typically sell RAM capacity of their virtual machines as two numbers: "guaranteed" and "burst" RAM. You are supposed to always get the "guaranteed" amount of RAM, and may use up to the "burst" amount if host resources permit. For example a VPS might be sold as "512MiB guaranteed 1GiB burst RAM".
You should always have a successful memory allocation below the "guaranteed" amount, but memory allocations may sometimes fail above that amount, if other virtual machines on the host are consuming RAM as well, or if the provider has oversubscribed the machine (almost always).
To learn what these numbers are, look at the barrier
for vmguarpages
which represents the "guaranteed" RAM, and the limit
for privvmpages
which represents the "burst" RAM. Each of these numbers is expressed in a number of 4KiB pages.
So in your case, we can see that you have 1GiB (262144) "guaranteed" RAM, and 4GiB (1048576) "burst" RAM. (If these aren't the numbers you were promised, you need to have a very unpleasant talk with your VPS provider.)
Since you are already well over 2GiB used in the VM, your memory allocation may fail, because it is above the "guaranteed" amount.