Skip to content

Commit

Permalink
ZTS: limit mmapwrite file size
Browse files Browse the repository at this point in the history
mmapwrite spawns several threads, all of which perform writes on a file
for the purpose of testing the behavior of mmap(2)-ed files.  One
thread performs an mmap and a write to the beginning of that region,
while the others perform regular writes after lseek(2)-ing the end of
the file.

Because these regular writes are set in a while (1) loop, they will
write an unbounded amount of data to disk.  The mmap_write_001_pos test
script SIGKILLs them after 30 seconds, but on fast testbeds, this may
be enough time to exhaust the available space in the filesystem,
leading to spurious test failures.

Instead, limit the total file size by checking that the lseek return
value is no greater than 250 * 1024*1024 bytes, which is less than the
default minimum vdev size defined in includes/default.cfg .

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes openzfs#14277 
Closes openzfs#14345
  • Loading branch information
aerusso authored Jan 5, 2023
1 parent 8352e9d commit ee6bf97
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/zfs-tests/cmd/mmapwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
*/

#define NORMAL_WRITE_TH_NUM 2
#define MAX_WRITE_BYTES 262144000

static void *
normal_writer(void *filename)
Expand All @@ -67,18 +68,21 @@ normal_writer(void *filename)
}

char buf = 'z';
while (1) {
off_t bytes_written = 0;

while (bytes_written < MAX_WRITE_BYTES) {
write_num = write(fd, &buf, 1);
if (write_num == 0) {
err(1, "write failed!");
break;
}
if (lseek(fd, page_size, SEEK_CUR) == -1) {
if ((bytes_written = lseek(fd, page_size, SEEK_CUR)) == -1) {
err(1, "lseek failed on %s: %s", file_path,
strerror(errno));
break;
}
}
return (NULL);
}

static void *
Expand Down

0 comments on commit ee6bf97

Please sign in to comment.