Is this Linux? If so, you could try the following:
# sysctl vm.swappiness=100
(You might want to use sysctl vm.swappiness
first to see the default value, on my system it was 10
)
And then either use a program(s) that uses lots of RAM or write a small application that just eats up RAM. The following will do that (source: Experiments and fun with the Linux disk cache):
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char** argv) {
int max = -1;
int mb = 0;
int multiplier = 1; // allocate 1 MB every time unit. Increase this to e.g.100 to allocate 100 MB every time unit.
char* buffer;
if(argc > 1)
max = atoi(argv[1]);
while((buffer=malloc(multiplier * 1024*1024)) != NULL && mb != max) {
memset(buffer, 1, multiplier * 1024*1024);
mb++;
printf("Allocated %d MB\n", multiplier * mb);
sleep(1); // time unit: 1 second
}
return 0;
}
Coded the memset line to initialise blocks with 1s rather than 0s,
because the Linux virtual memory manager may be smart enough
not to actually allocate any RAM otherwise.
I added the sleep(1) in order to give you more time to watch the processes as it gobbles up ram and swap. The OOM killer should kill this once you are out of RAM and SWAP to give to the program. You can compile it with
gcc filename.c -o memeater
where filename.c is the file you save the above program in. Then you can run it with ./memeater.
I wouldn't do this on a production machine.
It is normal for Linux systems to use some swap even if there is still RAM free. The Linux kernel will move to swap memory pages that are very seldom used (e.g., the getty
instances when you only use X11, and some other inactive daemon).
Swap space usage becomes an issue only when there is not enough RAM available, and the kernel is forced to continuously move memory pages to swap and back to RAM, just to keep applications running. In this case, system monitor applications would show a lot of disk I/O activity.
For comparison, my Ubuntu 10.04 system, with two users logged in with X11 sessions both running GNOME desktop, uses ~600MB of swap and ~1GB of RAM (not counting buffers and fs cache), so I'd say that your figures for swap usage look normal.
Best Answer
A swap file is more flexible but also more fallible than a swap partition. A filesystem error could damage the swap file. A swap file can be a pain for the administrator, since the file can't be moved or deleted. A swap file can't be used for hibernation. A swap file was slightly slower in the past, though the difference is negligible nowadays.
The advantage of a swap file is not having to decide the size in advance. However, under Linux, you still can't resize a swap file online: you have to unregister it, resize, then reregister (or create a different file and remove the old one). So there isn't that much benefit to a swap file under Linux, compared to a swap partition. It's mainly useful when you temporarily need more virtual memory, rather than as a permanent fixture.