2 * Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 main(int argc, char **argv)
38 int c, i, j, n, err = 0;
40 long iterations = 100;
41 long psize, bsize, leaksize = 32 * 1024 * 1024;
43 char *readbuffer, *writebuffer;
47 psize = bsize = getpagesize();
48 resvsize = bsize * (off64_t) 10000;
50 while ((c = getopt(argc, argv, "b:i:l:s:")) != EOF) {
56 iterations = atol(optarg);
59 leaksize = atol(optarg);
62 resvsize = (off64_t) atoll(optarg);
70 if (optind > argc + 1)
74 printf("Usage: %s [-b blksize] [-l leaksize] [-r resvsize]\n",
79 filename = argv[optind];
81 readbuffer = memalign(psize, bsize);
82 writebuffer = memalign(psize, bsize);
83 if (!readbuffer || !writebuffer) {
87 memset(writebuffer, 'A', sizeof(writebuffer));
90 writefd = open(filename, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
95 readfd = open(filename, O_RDONLY);
101 /* preallocate file space */
104 resvsp.l_len = resvsize;
105 if (ioctl(writefd, XFS_IOC_RESVSP64, &resvsp) < 0) {
106 fprintf(stdout, "attempt to reserve %lld bytes for %s "
107 "using %s failed: %s (%d)\n",
108 resvsize, filename, "XFS_IOC_RESVSP64",
109 strerror(errno), errno);
111 fprintf(stdout, "reserved %lld bytes for %s using %s\n",
112 resvsize, filename, "XFS_IOC_RESVSP64");
115 /* Space is now preallocated, start IO --
116 * write at current offset, pressurize, seek to zero on reader
117 * and read up to current write offset.
121 while (++n < iterations) {
125 if (write(writefd, writebuffer, sizeof(writebuffer)) < 0) {
130 /* Apply some memory pressure
131 * (allocate another chunk and touch all pages)
133 for (i = 0; i < (leaksize / psize); i++) {
139 lseek(readfd, SEEK_SET, 0);
141 for (j = 0; j < n; j++) {
142 if (read(readfd, readbuffer, sizeof(readbuffer)) < 0) {
146 for (i = 0; i < sizeof(readbuffer); i++) {
147 if (readbuffer[i] != 'A') {
149 "errors detected in file, pos: %d (%lld+%d), nwrites: %d [val=0x%x].\n",
150 j, (long long)j * 4096,
151 i, n, readbuffer[i]);
157 if (numerrors > 10) {
159 } else if (numerrors) {
160 fprintf(stdout, "\n");