Releasing swap space
Solution 1:
You could do a swapoff
-- will need root privileges,
but, I guess that is not a problem for you.
Solution 2:
You could do what nik suggested and use swapoff. However, there is another, more elegant way to tweak "swappiness", or how aggressively the kernel swaps programs out to disk in systems running the 2.6 kernels.
There have been heated debates on the linux kernel mailing lists about the policy the kernel should follow regarding swapping behaviour. The upshot is that we now have a patch in 2.6 kernels that lets us tweak this behaviour to a large extent.
Note that you need root privileges to do this, as you would to run the swapoff/swapon commands.
The current value of "swappiness" can be inspected in the /proc/sys/vm/swappiness file, or by running this sysctl command:
sudo sysctl vm.swappiness
The "swappiness" values can range from 0 (no swapping) to 100 (swap to disk as much as possible). Ubuntu ships with the default swappiness set to 60.
To change this for a session, call sysctl again and pass it a swappiness value to use:
sudo sysctl vm.swappiness=30
Besides free, you can of course monitor the effects of doing this via the excellent htop or iotop utilities.
If you like what you see, and want to retain this value across reboots, just place "vm.swappiness=30" in the /etc/sysctl.conf file.
$ sudo sysctl vm.swappiness
vm.swappiness = 30
$ sudo sysctl vm.swappiness=40
vm.swappiness = 40
$ sudo sysctl vm.swappiness
vm.swappiness = 40
$ sudo tail /etc/sysctl.conf
#net.ipv4.conf.all.accept_source_route = 0
#net.ipv6.conf.all.accept_source_route = 0
#
# Log Martian Packets
#net.ipv4.conf.all.log_martians = 1
#
# The contents of /proc/<pid>/maps and smaps files are only visible to
# readers that are allowed to ptrace() the process
# kernel.maps_protect = 1
vm.swappiness=30
You can play with different values till you find one that entails an acceptable level of swapping on your machine.