ColinIanKing / stress-ng

This is the stress-ng upstream project git repository. stress-ng will stress test a computer system in various selectable ways. It was designed to exercise various physical subsystems of a computer as well as the various operating system kernel interfaces.
https://github.com/ColinIanKing/stress-ng
GNU General Public License v2.0
1.79k stars 284 forks source link

hdd: Data is never read back if written sequentially #428

Closed chrfranke closed 1 month ago

chrfranke commented 1 month ago

Testcase with current git e8c6318 on Cygwin:

$ ./stress-ng --hdd 1 -t 60 -M
...
stress-ng: metrc: [26857] hdd                    0.00 MB/sec read rate (harmonic mean of 1 instance)
stress-ng: metrc: [26857] hdd                  729.22 MB/sec write rate (harmonic mean of 1 instance)
stress-ng: metrc: [26857] hdd                  729.22 MB/sec read/write combined rate (harmonic mean of 1 instance)
...

Expected: Nonzero read rate.

Same result occurs with --hdd-opts rd-seq or --hdd-opts rd-rnd. If --hdd-opts wr-rnd is used, a nonzero read rate is shown.

The root of the problem is that the if (hdd_flags & HDD_OPT_WR_SEQ) { ... } code section does not set hdd_bytes_max. This may do the trick:

diff --git a/stress-hdd.c b/stress-hdd.c
index f58717f35..397b9ae42 100644
--- a/stress-hdd.c
+++ b/stress-hdd.c
@@ -912,6 +912,7 @@ seq_wr_retry:
                                        continue;
                                }
                                stress_bogo_inc(args);
+                               hdd_bytes_max = i;
                        }
                }
                if (shim_fstat(fd, &statbuf) < 0) {

Independent but related:

$ man -l stress-ng.1
...
            -d N, --hdd N
                   start N workers continually writing, reading and removing temporary  files.  The  de‐
                   fault  mode is to stress test sequential writes and reads.  ...
...
                   rd-rnd          read data randomly. By default, written data is not read  back,  ...
...

"By default, written data is not read back." does neither match "The default mode is to stress test sequential writes and reads." nor the source code below comment /* Must have some read option */.

chrfranke commented 1 month ago

Yes hdd_bytes_max = i + ret is correct, sorry.

I suggested hdd_bytes_max = i because the HDD_OPT_WR_RND loop uses hdd_bytes_max = offset. A closer look shows that the first value of offset is hdd_bytes which is larger than the last offset written by the HDD_OPT_WR_SEQ loop. As consequence, the file written by random writes is larger than the one written by sequential writes. Is this intentional?

Regarding 957f460: The same text should also be removed from the rd-seq section.