mirror_zfs/tests/zfs-tests/tests/functional/mmap/mmap_mixed.ksh
Brian Behlendorf 89cd2197b9
Fix buffered/direct/mmap I/O race
When a page is faulted in for memory mapped I/O the page lock
may be dropped before it has been read and marked up to date.
If a buffered read encounters such a page in mappedread() it
must wait until the page has been updated. Failure to do so
will result in a panic on debug builds and incorrect data on
production builds.

The critical part of this change is in mappedread() where pages
which are not up to date are now handled. Additionally, it
includes the following simplifications.

- zfs_getpage() and zfs_fillpage() could be passed an array of
  pages. This could be more efficient if it was used but in
  practice only a single page was ever provided. These
  interfaces were simplified to acknowledge that.

- update_pages() was modified to correctly set the PG_error bit
  on a page when it cannot be read by dmu_read().

- Setting PG_error and PG_uptodate was moved to zfs_fillpage()
  from zpl_readpage_common(). This is consistent with the
  handling in update_pages() and mappedread().

- Minor additional refactoring to comments and variable
  declarations to improve readability.

- Add a test case to exercise concurrent buffered, direct,
  and mmap IO to the same file.

- Reduce the mmap_sync test case default run time.

Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13608 
Closes #14498
2023-02-23 10:57:24 -08:00

87 lines
2.5 KiB
Bash
Executable File

#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or https://opensource.org/licenses/CDDL-1.0.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2023 by Lawrence Livermore National Security, LLC.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/mmap/mmap.cfg
#
# DESCRIPTION:
# Verify mixed buffered and mmap IO.
#
# STRATEGY:
# 1. Create an empty file.
# 2. Start a background buffered read/write fio to the file.
# 3. Start a background mmap read/write fio to the file.
#
verify_runnable "global"
function cleanup
{
log_must rm -f "$tmp_file"
}
log_assert "Verify mixed buffered and mmap IO"
log_onexit cleanup
mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
tmp_file=$mntpnt/file
bs=$((128 * 1024))
blocks=64
size=$((bs * blocks))
runtime=60
log_must dd if=/dev/zero of=$tmp_file bs=$bs count=$blocks
# Buffered IO writes
log_must eval "fio --filename=$tmp_file --name=buffer-write \
--rw=randwrite --size=$size --bs=$bs --direct=0 --numjobs=1 \
--ioengine=sync --fallocate=none --group_reporting --minimal \
--runtime=$runtime --time_based --norandommap &"
# Buffered IO reads
log_must eval "fio --filename=$tmp_file --name=buffer-read \
--rw=randread --size=$size --bs=$bs --direct=0 --numjobs=1 \
--ioengine=sync --fallocate=none --group_reporting --minimal \
--runtime=$runtime --time_based --norandommap &"
# mmap IO writes
log_must eval "fio --filename=$tmp_file --name=mmap-write \
--rw=randwrite --size=$size --bs=$bs --numjobs=1 \
--ioengine=mmap --fallocate=none --group_reporting --minimal \
--runtime=$runtime --time_based --norandommap &"
# mmap IO reads
log_must eval "fio --filename=$tmp_file --name=mmap-read \
--rw=randread --size=$size --bs=$bs --numjobs=1 \
--ioengine=mmap --fallocate=none --group_reporting --minimal \
--runtime=$runtime --time_based --norandommap &"
log_must wait
log_pass "Verfied mixed buffered and mmap IO"