Created
June 8, 2016 09:16
-
-
Save bkrepo/f9b305e71ff79070ace18e057a7515b8 to your computer and use it in GitHub Desktop.
Swap test program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ 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