Skip to content

Instantly share code, notes, and snippets.

@vi
Created March 26, 2013 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vi/5247235 to your computer and use it in GitHub Desktop.
Save vi/5247235 to your computer and use it in GitHub Desktop.
Test [UKSM][1]: fill up memory pages with the same blocks of random data. [1]:http://kerneldedup.org/en/projects/uksm/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
if (argc<3) {
fprintf(stderr, "Usage uksm_tease page_size number_of_pages < /dev/urandom\n");
return 1;
}
size_t page_size = atoi(argv[1]);
long long int number_of_pages = atoi(argv[2]);
char buf[page_size];
fread(&buf, 1, page_size, stdin);
char* a = calloc(number_of_pages, page_size);
if (!a) {
perror("calloc");
return 1;
}
int i;
for (i=0; i<number_of_pages; ++i) {
memcpy(a+page_size*i, buf, page_size);
}
printf("finished\n");
for (;;) {
sleep(3600);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment