4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
30 #include <sys/types.h>
35 #define CHUNK (128 * 1024)
37 static void usage(const char *prog, FILE *out)
39 fprintf(out, "usage: %s allocsize\n", prog);
40 fprintf(out, " allocsize is kbytes, or number[KMGP] (P = pages)\n");
44 int main(int argc, char *argv[])
46 long long kbtotal = 0, kballoc;
47 int i, j, k, numchunk, alloc, sum, rc = 0;
53 kbtotal = strtoull(argv[1], &end, 0);
71 usage(argv[0], stderr);
76 if (argc != 2 || kbtotal == 0)
77 usage(argv[0], stderr);
79 numchunk = (kbtotal + CHUNK - 1) / CHUNK;
80 mem = calloc(numchunk, sizeof(*mem));
82 fprintf(stderr, "error allocating initial chunk array\n");
87 printf("[%d] allocating %lld kbytes in %u kbyte chunks\n",
88 getpid(), kbtotal, alloc);
89 for (i = kballoc = 0; i < numchunk && alloc > 0; i++,
91 if (kbtotal - kballoc < alloc)
92 alloc = kbtotal - kballoc;
94 while (alloc > 0 && (mem[i] = malloc(alloc * 1024)) == NULL) {
95 fprintf(stderr, "malloc(%u) failed (%lld/%lld)\n",
96 alloc * 1024, kballoc, kbtotal);
102 printf("touching %p ([%lld-%lld]/%lld)\n", mem[i], kballoc,
103 kballoc + alloc - 1, kbtotal);
104 for (j = 0, tmp = mem[i]; j < alloc; j += 4) {
105 for (k = 0, sum = 0; k < 4095; k++, tmp++)
114 printf("touched %lld kbytes\n", kballoc);
117 printf("verifying %lld kbytes in %u kbyte chunks\n", kbtotal, alloc);
118 for (i = kballoc = 0; i < numchunk; i++, kballoc += alloc) {
119 if (kbtotal - kballoc < alloc)
120 alloc = kbtotal - kballoc;
124 printf("verifying %p (%lld/%lld)\n",
125 tmp, kballoc, kbtotal);
126 for (j = 0; j < alloc; j += 4) {
127 for (k = 0, sum = 0; k < 4095; k++, tmp++)
130 fprintf(stderr, "sum %x != %x at %p\n",
131 *tmp, sum, tmp - 4092);
137 printf("verified %lld kbytes\n", kballoc);