2 * Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
19 * Mountain View, CA 94043, USA, or: http://www.sgi.com
25 main(int argc, char **argv)
27 int c, i, j, n, err = 0;
29 long iterations = 100;
30 long psize, bsize, leaksize = 32 * 1024 * 1024;
32 char *readbuffer, *writebuffer;
36 psize = bsize = getpagesize();
37 resvsize = bsize * (off64_t) 10000;
39 while ((c = getopt(argc, argv, "b:i:l:s:")) != EOF) {
45 iterations = atol(optarg);
48 leaksize = atol(optarg);
51 resvsize = (off64_t) atoll(optarg);
59 if (optind > argc + 1)
63 printf("Usage: %s [-b blksize] [-l leaksize] [-r resvsize]\n",
68 filename = argv[optind];
70 readbuffer = memalign(psize, bsize);
71 writebuffer = memalign(psize, bsize);
72 if (!readbuffer || !writebuffer) {
76 memset(writebuffer, 'A', bsize);
79 writefd = open(filename, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
84 readfd = open(filename, O_RDONLY);
90 /* preallocate file space */
93 resvsp.l_len = resvsize;
94 if (xfsctl(filename, writefd, XFS_IOC_RESVSP64, &resvsp) < 0) {
95 fprintf(stdout, "attempt to reserve %lld bytes for %s "
96 "using %s failed: %s (%d)\n",
97 (long long int)resvsize, filename, "XFS_IOC_RESVSP64",
98 strerror(errno), errno);
100 fprintf(stdout, "reserved %lld bytes for %s using %s\n",
101 (long long int)resvsize, filename, "XFS_IOC_RESVSP64");
104 /* Space is now preallocated, start IO --
105 * write at current offset, pressurize, seek to zero on reader
106 * and read up to current write offset.
110 while (++n < iterations) {
114 if (write(writefd, writebuffer, bsize) < 0) {
119 /* Apply some memory pressure
120 * (allocate another chunk and touch all pages)
122 for (i = 0; i < (leaksize / psize); i++) {
128 lseek(readfd, SEEK_SET, 0);
130 for (j = 0; j < n; j++) {
131 if (read(readfd, readbuffer, bsize) < 0) {
135 for (i = 0; i < bsize; i++) {
136 if (readbuffer[i] != 'A') {
138 "errors detected in file, pos: %d (%lld+%d), nwrites: %d [val=0x%x].\n",
139 j, (long long)j * 4096,
140 i, n, readbuffer[i]);
146 if (numerrors > 10) {
148 } else if (numerrors) {
149 fprintf(stdout, "\n");