From bf5ce0253c1d6693a6d869ca74047a6d3115627e Mon Sep 17 00:00:00 2001 From: adilger Date: Sat, 10 Jul 2004 00:37:12 +0000 Subject: [PATCH] Branch: b1_4_smallfix Merge fixes from b1_2_smallfix, other minor changes to get branches closer. - return -ENOENT instead of asserting if ost getattr+unlink race (b=3558) - avoid deadlock after precreation failure (b=3758) - fix race and lock order deadlock in orphan handling (b=3450, b=3750, b=3789) --- lustre/tests/memhog.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 lustre/tests/memhog.c diff --git a/lustre/tests/memhog.c b/lustre/tests/memhog.c new file mode 100644 index 0000000..098e787 --- /dev/null +++ b/lustre/tests/memhog.c @@ -0,0 +1,102 @@ +#include +#include +#include +#include + +#define CHUNK (128 * 1024) + +void usage(const char *prog, FILE *out) +{ + fprintf(out, "usage: %s allocsize\n", prog); + fprintf(out, " allocsize is kbytes, or number[KMGP] (P = pages)\n"); + exit(out == stderr); +} + +int main(int argc, char *argv[]) +{ + long long kbtotal = 0, kballoc; + int i, j, k, numchunk, alloc, sum, rc = 0; + char **mem, *tmp; + + if (argc == 2) { + char *end = NULL; + kbtotal = strtoull(argv[1], &end, 0); + + switch(*end) { + case 'g': + case 'G': + kbtotal *= 1024; + case 'm': + case 'M': + kbtotal *= 1024; + case '\0': + case 'k': + case 'K': + break; + case 'p': + case 'P': + kbtotal *= 4; + break; + default: + usage(argv[0], stderr); + break; + } + } + + if (argc != 2 || kbtotal == 0) + usage(argv[0], stderr); + + numchunk = (kbtotal + CHUNK - 1) / CHUNK; + mem = calloc(numchunk, sizeof(*mem)); + if (mem == NULL) { + fprintf(stderr, "error allocating initial chunk array\n"); + exit(1); + } + + alloc = CHUNK; + printf("[%d] allocating %lld kbytes in %u kbyte chunks\n", + getpid(), kbtotal, alloc); + for (i = kballoc = 0; i < numchunk; i++, kballoc += alloc) { + if (kbtotal - kballoc < alloc) + alloc = kbtotal - kballoc; + + tmp = mem[i] = malloc(alloc * 1024); + if (tmp == NULL) { + fprintf(stderr, "malloc(%u) failed (%lld/%lld)\n", + alloc * 1024, kballoc, kbtotal); + } else { + printf("touching %p (%lld/%lld)\n", + tmp, kballoc, kbtotal); + for (j = 0; j < alloc; j += 4) { + for (k = 0, sum = 0; k < 4095; k++, tmp++) + sum += *tmp; + *tmp = sum; + } + } + } + printf("touched %lld kbytes\n", kballoc); + + alloc = CHUNK; + printf("verifying %lld kbytes in %u kbyte chunks\n", kbtotal, alloc); + for (i = kballoc = 0; i < numchunk; i++, kballoc += alloc) { + if (kbtotal - kballoc < alloc) + alloc = kbtotal - kballoc; + + tmp = mem[i]; + if (tmp != NULL) { + printf("verifying %p (%lld/%lld)\n", + tmp, kballoc, kbtotal); + for (j = 0; j < alloc; j += 4) { + for (k = 0, sum = 0; k < 4095; k++, tmp++) + sum += *tmp; + if (*tmp != sum) { + fprintf(stderr, "sum %x != %x at %p\n", + *tmp, sum, tmp - 4092); + rc = 1; + } + } + } + } + printf("verified %lld kbytes\n", kballoc); + return rc; +} -- 1.8.3.1