|
| 1 | +#!/bin/ksh -p |
| 2 | +# SPDX-License-Identifier: CDDL-1.0 |
| 3 | +# |
| 4 | +# CDDL HEADER START |
| 5 | +# |
| 6 | +# The contents of this file are subject to the terms of the |
| 7 | +# Common Development and Distribution License (the "License"). |
| 8 | +# You may not use this file except in compliance with the License. |
| 9 | +# |
| 10 | +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
| 11 | +# or https://opensource.org/licenses/CDDL-1.0. |
| 12 | +# See the License for the specific language governing permissions |
| 13 | +# and limitations under the License. |
| 14 | +# |
| 15 | +# When distributing Covered Code, include this CDDL HEADER in each |
| 16 | +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
| 17 | +# If applicable, add the following below this CDDL HEADER, with the |
| 18 | +# fields enclosed by brackets "[]" replaced with your own identifying |
| 19 | +# information: Portions Copyright [yyyy] [name of copyright owner] |
| 20 | +# |
| 21 | +# CDDL HEADER END |
| 22 | +# |
| 23 | + |
| 24 | +# |
| 25 | +# Copyright (c) 2025, Klara, Inc. |
| 26 | +# |
| 27 | + |
| 28 | +. $STF_SUITE/include/libtest.shlib |
| 29 | + |
| 30 | +# |
| 31 | +# This verifies that async writeback of dirty mmap()'d pages completes quickly. |
| 32 | +# ftruncate() is an operation that will trigger async writeback, but is not |
| 33 | +# itself a syncing operation, making it a useful proxy for any way the kernel |
| 34 | +# might trigger async writeback. |
| 35 | +# |
| 36 | +# The guts of this test is in the mmap_ftruncate program. This driver sets a |
| 37 | +# larger zfs_txg_timeout. Test failure occurs ftruncate() blocks waiting for |
| 38 | +# the writeback until the txg timeout is reached and the changes are forcibly |
| 39 | +# written out. Success means the DMU has accepted the changes and cleared the |
| 40 | +# page dirty flags. |
| 41 | +# |
| 42 | + |
| 43 | +TIMEOUT=180 |
| 44 | +TESTFILE=/$TESTPOOL/truncfile |
| 45 | +TESTSIZE=$((2*1024*1024*1024)) # 2G |
| 46 | + |
| 47 | +verify_runnable "global" |
| 48 | + |
| 49 | +typeset claim="async writeback of dirty mmap()'d pages completes quickly" |
| 50 | + |
| 51 | +log_assert $claim |
| 52 | + |
| 53 | +log_must save_tunable TXG_TIMEOUT |
| 54 | + |
| 55 | +function cleanup |
| 56 | +{ |
| 57 | + log_must restore_tunable TXG_TIMEOUT |
| 58 | + rm -f $TESTFILE |
| 59 | +} |
| 60 | +log_onexit cleanup |
| 61 | + |
| 62 | +log_must set_tunable32 TXG_TIMEOUT $TIMEOUT |
| 63 | +log_must zpool sync -f |
| 64 | + |
| 65 | +# run mmap_ftruncate and record the run time |
| 66 | +typeset -i start=$(date +%s) |
| 67 | +log_must mmap_ftruncate $TESTFILE $TESTSIZE |
| 68 | +typeset -i end=$(date +%s) |
| 69 | +typeset -i delta=$((end - start)) |
| 70 | + |
| 71 | +# in practice, mmap_ftruncate needs a few seconds to dirty all the pages, and |
| 72 | +# when this test passes, the ftruncate() call itself should be near-instant. |
| 73 | +# when it fails, then its only the txg sync that allows ftruncate() to |
| 74 | +# complete, in that case, the run time will be extremely close to the timeout, |
| 75 | +# so to avoid any confusion at the edges, we require that it complets within |
| 76 | +# half the transaction time. for any timeout higher than ~30s that should be a |
| 77 | +# very bright line down the middle. |
| 78 | +log_must test $delta -lt $((TIMEOUT / 2)) |
| 79 | + |
| 80 | +log_pass $claim |
0 commit comments