Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Even though I have set swappiness to 100 and enabled swap, nothing is being swapped out. This is probably because I don't have high memory pressure at the moment. For testing purposes though, I want to force kswapd to swap out as much as it can. Is there a way to kick it into action even though there isn't high memory pressure?

share|improve this question

Not that I know of, but you can force it to swap just by allocating (and using) some ram.

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main(int argc, char **argv)
    if (argc < 2)
      return 1;
    int megs = atoi(argv[1]);
    if (megs <= 0)
      return 2;
    int i;
    for (i=0; i<megs; i++) {
        void *data = malloc(1024*1024);
        memset(data, 1, 1024*1024);
    return 0;

Save that to eater.c and compiler with gcc -o eater eater.c. (Or whatever your favorite compiler's command line is.) Then simply run that with a number of megabytes as arguments. Hit enter to release it all.

Warning: this will run fast until you actually hit a need for swap. Then your whole system will grind to a halt/start getting OOMs/random apps will start failing if you eat up too much RAM.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.