1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# This file and its contents are supplied under the terms of the 6# Common Development and Distribution License ("CDDL"), version 1.0. 7# You may only use this file in accordance with the terms of version 8# 1.0 of the CDDL. 9# 10# A full copy of the text of the CDDL should have accompanied this 11# source. A copy of the CDDL is also available via the Internet at 12# http://www.illumos.org/license/CDDL. 13# 14# CDDL HEADER END 15# 16 17. $STF_SUITE/include/libtest.shlib 18. $STF_SUITE/tests/functional/trim/trim.kshlib 19. $STF_SUITE/tests/functional/trim/trim.cfg 20 21# 22# DESCRIPTION: 23# Verify trimming of L2ARC 24# 25# STRATEGY: 26# 1. Set 'l2arc_trim_ahead = 1' and `l2arc_write_size = 64MB`. 27# 2. Create a pool on file vdevs to trim. 28# 3. Verify the cache device was trimmed. 29# 4. Fill the pool with a file larger than the L2ARC vdev. 30# 5. Randomly read the previous written file long enough for the 31# L2ARC vdev to be filled and overwritten 5 times. 32# 6. Verify trim IOs of the expected type were issued for the pool. 33# 7. Verify the allocated space on the cache device is less than 34# its size. 35# 36 37verify_runnable "global" 38 39command -v fio > /dev/null || log_unsupported "fio missing" 40 41log_assert "Trim of L2ARC succeeds." 42 43function cleanup 44{ 45 if poolexists $TESTPOOL; then 46 destroy_pool $TESTPOOL 47 fi 48 49 log_must rm -f $VDEVS 50 log_must set_tunable32 L2ARC_TRIM_AHEAD $l2arc_trimahead 51 log_must set_tunable32 L2ARC_WRITE_MAX $l2arc_writemax 52} 53log_onexit cleanup 54 55# The cache device $TRIM_VDEV2 has to be small enough, so that 56# dev->l2ad_hand loops around and dev->l2ad_first=0. Otherwise 57# l2arc_evict() exits before evicting/trimming. 58typeset l2arc_trimahead=$(get_tunable L2ARC_TRIM_AHEAD) 59typeset l2arc_writemax=$(get_tunable L2ARC_WRITE_MAX) 60log_must set_tunable32 L2ARC_TRIM_AHEAD 1 61log_must set_tunable32 L2ARC_WRITE_MAX $((64 * 1024 * 1024)) 62VDEVS="$TRIM_VDEV1 $TRIM_VDEV2" 63log_must truncate -s $((MINVDEVSIZE)) $TRIM_VDEV2 64log_must truncate -s $((4 * MINVDEVSIZE)) $TRIM_VDEV1 65typeset VDEV_MIN_MB=$((MINVDEVSIZE * 0.30 / 1024 / 1024)) 66 67log_must zpool create -f $TESTPOOL $TRIM_VDEV1 cache $TRIM_VDEV2 68verify_vdevs "-le" "$VDEV_MIN_MB" $TRIM_VDEV2 69 70typeset fill_mb=$(( floor(3 * MINVDEVSIZE) )) 71export DIRECTORY=/$TESTPOOL 72export NUMJOBS=1 73export FILE_SIZE=${fill_mb} 74export PERF_RANDSEED=1234 75export PERF_COMPPERCENT=66 76export PERF_COMPCHUNK=0 77export RUNTIME=30 78export BLOCKSIZE=128K 79export SYNC_TYPE=0 80export DIRECT=1 81 82# Write to the pool. 83log_must fio $FIO_SCRIPTS/mkfiles.fio 84 85# Read randomly from the pool to fill L2ARC. 86export RUNTIME=30 87log_must fio $FIO_SCRIPTS/random_reads.fio 88 89export RUNTIME=1 90typeset do_once=true 91while $do_once || [[ $l2_size1 -le $l2_size2 ]]; do 92 typeset l2_size1=$(get_arcstat l2_size) 93 log_must fio $FIO_SCRIPTS/random_reads.fio 94 typeset l2_size2=$(get_arcstat l2_size) 95 do_once=false 96done 97 98verify_trim_io $TESTPOOL "ind" 5 $TRIM_VDEV2 99 100typeset cache_size cache_alloc _ 101read -r _ cache_size cache_alloc _ < <(zpool list -vp | grep $TRIM_VDEV2) 102 103log_must test $cache_alloc -lt $cache_size 104 105log_must zpool destroy $TESTPOOL 106log_must rm -f $VDEVS 107 108log_pass "Trim of L2ARC succeeds." 109