I have tried to change the swappiness to 100, and used the malloc() code in order to set the swap to 0 on my rhel system But this not seem to be helpful . The system memory allocation looks like this :

-bash-4.1$ cat /proc/meminfo
 MemTotal:       15331636 kB
 MemFree:        14552168 kB
 SwapTotal:      15826924 kB
 SwapFree:       15657580 kB

The malloc program ran a couple of thousands of iterations before the kernel killed the same. But i did not see an explicit "killed process" or any other information in the kernel log file.

I looked for the status using dmesg after executing this code snippet :

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

 int main(int argc, char** argv) {
int max = -1;
int mb = 0;
char* buffer;

if(argc > 1)
    max = atoi(argv[1]);

while((buffer=malloc(1024*1024*1024)) != NULL && mb != max) {
    memset(buffer, 0, 1024*1024);
    printf("Allocated %d MB\n", mb);
return 0;

Is there a better way to set the swap to a very low value or 0 ?

  • 5
    Have you tried swapoff? – DopeGhoti Apr 29 '16 at 9:33
  • Thanks this worked like a charm. I can mark this as a answer if you add this as a comment – bhavs May 2 '16 at 6:28
  • Cool beans; done and done. – DopeGhoti May 3 '16 at 2:09

The following command (run as root) will disable all swap space, moving anything in swap into actual RAM before disabling it. Be wary though, as if you end up needing more memory than you have without swap, you will have issues ranging from the kernel killing processes at its discretion to a full-on kernel panic.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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