Virtual Memory

Hey,

I’m using OpenSUSE, i would like to use some virtual memory of the hard drive, so i can use more memory for my applications. I cant add an new memory block in the computer, bcoz its an virtual computer.

So is there any command i can use to use a part of the hard drive as virtual memory?

Thx,
Alexw

GNU/Linux can use swap files as well as swap partitions. It shouldn’t be difficult to find the exact procedure with uncle Google (it involves creating the file with dd, using mkswap and putting it in your fstab). In addition, if your virtual partition is filling up, you could perhaps add another virtual drive to your guest OS and place the swap file there.

If this is a Virtual Machine (you said virtual computer) running on another machine, then

  1. The virtual machine application(eg vmware, xen, virtualbox, etc) manages the physical resources on the Host machine used by the Guests

  2. There is little purpose to trying to manage memory usage in the Guest VMs themselves. You might partition for other purposes but don’t waste energy specially modifying swap files/partitions for the purpose of memory management.

How much RAM the host has? And how much is allocated to the VM?
The best way is to increase the VM allocated memory. You may have to add more RAM to the host.
In openSUSE 11, my experience is that it is best to leave at least 300 MB to the host, else it starts swapping too much. So if you have, say, 1 GB RAM, you may allocate up to 700 MB to the VM, assuming you are running only one. Of course, YMMV.

Besides that, in linux (doesn’t matter if it is real or a VM) you can create a temporary swap file, similar to that mess that windows does. You are not limited to swap partitions, but they do work much better.

To create a 128 MB swap file in /swap, for example, type as root:

dd if=/dev/zero of=/swap bs=1024 count=131072

mkswap /swap

swapon /swap

Change the number 131072 (128 x 1024) to the size you want. It doesn’t have to be a multiple of 1024, you can use 250000 for example, to make a ~244 MB file.

The /swap file is temporary, should deactivate after rebooting. You can remove it at any time with:

swapoff /swap

rmdir /swap

See the respective man pages for more info.