Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
int main(int argc, char *argv[])
{
size_t s;
int i, niter = 1;
unsigned char fill, *base, *ptr, *last;
if (argc != 3) {
fprintf(stderr, "usage: memfun <fillbyte> <nbytes>\n");
exit(1);
}
i = atoi(argv[1]);
if (i < 0 || i > 255) {
fprintf(stderr, "fillbyte needs to be 0...255\n");
exit(1);
}
fill = i;
s = atoll(argv[2]); /* not good */
if (! ((base = malloc(s)))) {
fprintf(stderr, "unable to malloc %lld\n", s);
exit(1);
}
if (mlock(base, s) < 0) {
perror("warning, mlock failed");
}
last = base + s;
for (ptr = base; ptr < last; ptr++) {
*ptr = fill;
}
for (;; niter++) {
fprintf(stderr, "start iter %d\r", niter);
for (ptr = base; ptr < last; ptr++) {
if (*ptr != fill) {
fprintf(stderr, "err at loc %d iter %d\n", ptr - base, niter);
}
}
}
}
well anyways it shows lazy in several ways, including that it only works up to 4GB, but hey you can run several copies. Be sure to run it as root. Then I'll tell you I didn't work real hard on it so it's probably full of bugs and 100% guaranteed not-proper-coding things.