Skip to content

Instantly share code, notes, and snippets.

@bkrepo
Created June 8, 2016 09:16
Show Gist options
  • Save bkrepo/f9b305e71ff79070ace18e057a7515b8 to your computer and use it in GitHub Desktop.
Save bkrepo/f9b305e71ff79070ace18e057a7515b8 to your computer and use it in GitHub Desktop.
Swap test program
// $ gcc swap_test.c -o swap_test
// $ sudo sysctl vm.swappiness=100
// $ ./swap_test
#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(10*1024*1024)) != NULL && mb != max) {
memset(buffer, 0, 10*1024*1024);
mb+=10;
printf("Allocated %d MB\n", mb);
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment