4 * Hard disk write workload: write random (or zeroed) data at random
5 * locations in a file, and optionally validate by re-reading some
6 * blocks after a while.
9 * gcc -O2 -Wall -o test-ssd-write test-ssd-write.c
11 * Hard disks known to stop responding with this program (requires a
12 * warm machine reboot to get the drive to respond, as soft reset is not
15 * Vendor Model Firmware Controller # drives tested
16 * Intel (Lenovo) SSDSC2BW180A3L LE1i SandForce 2281 1
17 * Intel (Lenovo) SSDSC2BW180A3L LF1i SandForce 2281 3
19 * We ensured that the problem is not coming from other parts by running
20 * this test on other SSD drives, which don't show this problem:
22 * Vendor Model Firmware Controller # drives tested
23 * Intel SSDSA2M160G2GC 2CV102HD Intel 1
24 * Intel SSDSA2CW300G310 ??????? Intel 1 (over USB on 3.8 kernel)
25 * Intel SSDSA2CT040G3 4PC10302 Intel 1 (3.2 kernel)
26 * Intel SSDSA2CT040G3 4PC10362 Intel 1 (3.2 kernel)
27 * Intel SSDSC2CT120A3K5 ??????? SandForce 2281 1 (on HP SmartArray P212 with 3.2 kernel)
29 * Under Linux (Debian, Ubuntu, various kernels), after about 5 minutes,
32 * ata1.00: exception Emask 0x0 SAct 0x1 SErr 0x0 action 0x6 frozen
33 * ata1.00: failed command: WRITE FPDMA QUEUED
34 * ata1.00: cmd 61/28:00:a8:a9:7f/00:00:02:00:00/40 tag 0 ncq 20480 out
35 * res 40/00:00:00:4f:c2/00:00:00:00:00/00 Emask 0x4 (timeout)
36 * ata1.00: status: { DRDY }
37 * ata1.00: COMRESET failed (errno=-16)
38 * ata1.00: COMRESET failed (errno=-16)
40 * This happens with random data, zeroed data (-z), and has been tested
41 * with file sizes of 1MB, 200MB, 3.1GB and 21GB. The error happens with
42 * and without the validation (-v) option.
44 * Copyright 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
46 * Permission is hereby granted, free of charge, to any person obtaining
47 * a copy of this software and associated documentation files (the
48 * "Software"), to deal in the Software without restriction, including
49 * without limitation the rights to use, copy, modify, merge, publish,
50 * distribute, sublicense, and/or sell copies of the Software, and to
51 * permit persons to whom the Software is furnished to do so, subject to
52 * the following conditions:
54 * The above copyright notice and this permission notice shall be
55 * included in all copies or substantial portions of the Software.
57 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67 #include <sys/types.h>
82 static enum write_mode write_mode
;
83 static int verify_mode
;
85 #define PRINT_FREQ 100000
86 #define VALIDATE_FREQ 10000
89 static void rand_buf(char *buf
, size_t buflen
)
93 for (i
= 0; i
< buflen
; i
+= sizeof(int)) {
99 memcpy(&buf
[i
], u
.c
, sizeof(int));
103 static uint64_t validate(int fd
, const char *validate_buf
, off_t offset
)
109 uint64_t diffcnt
= 0;
114 pos
= lseek(fd
, offset
, SEEK_SET
);
119 rret
= read(fd
, buf
, BUFLEN
);
120 if (rret
!= BUFLEN
) {
121 fprintf(stderr
, "Error at read from offset: %zu\n",
126 for (i
= 0; i
< BUFLEN
; i
++) {
127 if (buf
[i
] != validate_buf
[i
]) {
134 static int rand_write(int fd
, size_t len
)
137 uint64_t write_nr
= 0;
140 char validate_buf
[BUFLEN
];
141 off_t validate_offset
= 0;
145 memset(buf
, 0, BUFLEN
);
148 if (len
> UINT32_MAX
) {
149 offset
= (((size_t) rand() << 32) + (size_t) rand()) % len
;
151 offset
= rand() % len
;
154 if ((offset
>= validate_offset
&&
155 offset
< validate_offset
+ BUFLEN
)
156 || (validate_offset
>= offset
&&
157 validate_offset
< offset
+ BUFLEN
)) {
158 /* Don't overwrite the range we want to validate. */
161 if (write_mode
== WRITE_RANDOM
)
162 rand_buf(buf
, BUFLEN
);
163 /* Save validation buffer and position */
164 if (write_nr
% VALIDATE_FREQ
== 0 && verify_mode
) {
165 memcpy(validate_buf
, buf
, BUFLEN
);
166 validate_offset
= offset
;
168 pos
= lseek(fd
, offset
, SEEK_SET
);
173 wret
= write(fd
, buf
, BUFLEN
);
174 if (wret
!= BUFLEN
) {
175 fprintf(stderr
, "Error at write to offset: %zu\n",
182 * Advise that we won't be re-reading the blocks. This
183 * will ask the kernel to drop pages related to this
184 * file quickly from its page cache, thus forcing a read
192 ret
= posix_fadvise(fd
, offset
, BUFLEN
, POSIX_FADV_DONTNEED
);
194 perror("posix_fadvise");
199 if (write_nr
% PRINT_FREQ
== 0) {
200 printf("Status: %" PRIu64
" writes.\n", write_nr
);
204 * Use the validation buffer and position saved
205 * VALIDATE_FREQ operations earlier.
207 if (write_nr
% VALIDATE_FREQ
== 0 && verify_mode
) {
208 valcount
= validate(fd
, validate_buf
, validate_offset
);
210 printf("VALIDATION ERROR at offset %zu, %" PRIu64
" bytes differ\n",
211 validate_offset
, valcount
);
218 int main(int argc
, char **argv
)
220 int fd
, ret
, i
, seed
;
226 printf("Usage: %s <output file> <len (64-bit)> <seed (32-bit)> <-z to write zeroes> <-v to verify written data>\n", argv
[0]);
230 fd
= open(argv
[1], O_RDWR
| O_CREAT
| O_EXCL
, S_IRUSR
| S_IWUSR
);
236 len
= atoll(argv
[2]);
237 seed
= atoi(argv
[3]);
240 printf("Creating file %s of length %zu, random seed %u\n", argv
[1], len
,
243 for (i
= 4; i
< argc
; i
++) {
244 if (strcmp(argv
[i
], "-z") == 0) {
245 write_mode
= WRITE_ZEROES
;
246 } else if (strcmp(argv
[i
], "-v") == 0) {
251 switch (write_mode
) {
253 printf("Generating random data\n");
256 printf("Filling with zeroes (compressible pattern)\n");
259 printf("Unsupported write-mode\n");
264 printf("Verification mode activated.\n");
268 pos
= lseek(fd
, len
- 1, SEEK_SET
);
273 wret
= write(fd
, "", 1);
279 /* Advise the OS that we are performing random accesses */
280 ret
= posix_fadvise(fd
, 0, len
, POSIX_FADV_RANDOM
);
282 perror("posix_fadvise");
286 ret
= rand_write(fd
, len
);
This page took 0.035495 seconds and 4 git commands to generate.