From patchwork Wed Oct 5 05:46:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12999013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A16CFC43217 for ; Wed, 5 Oct 2022 05:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbiJEFqz (ORCPT ); Wed, 5 Oct 2022 01:46:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbiJEFqw (ORCPT ); Wed, 5 Oct 2022 01:46:52 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6581672B62; Tue, 4 Oct 2022 22:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1664948811; x=1696484811; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UQ2IUQJMF4R3aEPD69wWuI8fkmboUToQc43FPIw02LY=; b=iaLuTfoTsK5As/JEkEuB0aFYlJ7OF2VkZBeSxhOTmtZbwtJ5eF8u06ys cuVb7IBKhzrDv1rZ36B/VA3vOE3ZdYP/A0LOs2Oc2hWqOXtqszxR++6ej ei0OCZL2O3BjW+Wa2U6Pj8psTrr3CocawRHV3y0QvxdL2ADLy9b6+QoMR 6wOcieatSuOw1mMP2K1l9hZRO8U/TW+3SE2o5qPDqqxpY7T/xZSOLz6xa COOGoDjFAQj/6jejy+4xaYRkWSL/pVWGJ8CDInu6Ta+jw0kjLm/nkgQ8B 7+bQEFVEMNWns8GYJSJ4SJEWhzvvixRqNwFBnI7ermid+mrOBTccOajDA A==; X-IronPort-AV: E=Sophos;i="5.95,159,1661788800"; d="scan'208";a="317309477" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2022 13:46:51 +0800 IronPort-SDR: NWN3yqZKQ0HpfOAI9JHY92p6RoE97KF93zud8WK1KUIH0ZpryGmbzXFW27qqg8QQZm0+FKTrso 2cKYxWZ0gh1YyYGY5rFXxc7qnDU1mBAiS0YOseUNPnmfHDTuVRfu3BDSGklv2lglsHkgQDd6jp nK4/8wJNxtl9CC6lIunpjxdi8Hrp1W3TxhwhLrPppODg5xCgYx2Ev9hIqZOBsWFSxPa+EuSpK8 +rwtfZMgic0wSDByNMNo+J5meFXQ9AcgI0cH19sWn0SqBj5r1st6qdQ06/SpZtCjhMih/xvrxR ia9MWtfy7b3LuDv2HkEHIBir Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Oct 2022 22:01:04 -0700 IronPort-SDR: AGtflkBt0OjjmtG6CWZ/InwCpyoQBwhp52J6fGq3xILtBQhLe0Jd5wUsO1iSH+mWXsoxx5aSBi fhhL1djJfFUkfYDHbxRHDnAV0Vy3ymEXMGyfLABH8g2l6pZFpi6oQTMyPleLUSBX5V0Qxhx5b/ 8lGli9pEScMESKOxCT7T3DYSKUoSLN7twerSLcgp0wMhSrZ70XRXIXU1MO/XWbvKJkeFm4U1nr 1dtyprDm/z5p+7rh/LnHg1zFaP6sxVxPBQWbwOuIwyK0iZq3+AmZ0TBE3vw1gw6CCuOfVlroqy E6A= WDCIronportException: Internal Received: from 5cg2075dx4.ad.shared (HELO naota-xeon.wdc.com) ([10.225.48.62]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Oct 2022 22:46:50 -0700 From: Naohiro Aota To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Naohiro Aota , Zorro Lang , Johannes Thumshirn Subject: [PATCH v3 1/2] common: introduce zone_capacity() to return a zone capacity Date: Wed, 5 Oct 2022 14:46:43 +0900 Message-Id: X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce _zone_capacity() to return a zone capacity of the given address in the given device (optional). Move _filter_blkzone_report() for it, and rewrite btrfs/237 with it. Reviewed-by: Zorro Lang Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- common/filter | 13 ------------- common/zoned | 28 ++++++++++++++++++++++++++++ tests/btrfs/237 | 8 ++------ 3 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 common/zoned diff --git a/common/filter b/common/filter index 6433a30e53c2..3e3fea7ea02e 100644 --- a/common/filter +++ b/common/filter @@ -651,18 +651,5 @@ _filter_bash() sed -e "s/^bash: line 1: /bash: /" } -# -# blkzone report added zone capacity to be printed from v2.37. -# This filter will add an extra column 'cap' with the same value of -# 'len'(zone size) for blkzone version < 2.37 -# -# Before: start: 0x000100000, len 0x040000, wptr 0x000000 .. -# After: start: 0x000100000, len 0x040000, cap 0x040000, wptr 0x000000 .. -_filter_blkzone_report() -{ - $AWK_PROG -F "," 'BEGIN{OFS=",";} $3 !~ /cap/ {$2=$2","$2;} {print;}' |\ - sed -e 's/len/cap/2' -} - # make sure this script returns success /bin/true diff --git a/common/zoned b/common/zoned new file mode 100644 index 000000000000..d1bc60f784a1 --- /dev/null +++ b/common/zoned @@ -0,0 +1,28 @@ +# +# Common zoned block device specific functions +# + +# +# blkzone report added zone capacity to be printed from v2.37. +# This filter will add an extra column 'cap' with the same value of +# 'len'(zone size) for blkzone version < 2.37 +# +# Before: start: 0x000100000, len 0x040000, wptr 0x000000 .. +# After: start: 0x000100000, len 0x040000, cap 0x040000, wptr 0x000000 .. +_filter_blkzone_report() +{ + $AWK_PROG -F "," 'BEGIN{OFS=",";} $3 !~ /cap/ {$2=$2","$2;} {print;}' |\ + sed -e 's/len/cap/2' +} + +_zone_capacity() { + local phy=$1 + local dev=$2 + + [ -z "$dev" ] && dev=$SCRATCH_DEV + + size=$($BLKZONE_PROG report -o $phy -l 1 $dev |\ + _filter_blkzone_report |\ + grep -Po "cap 0x[[:xdigit:]]+" | cut -d ' ' -f 2) + echo $((size << 9)) +} diff --git a/tests/btrfs/237 b/tests/btrfs/237 index bc6522e2200a..733ce9c8bd8e 100755 --- a/tests/btrfs/237 +++ b/tests/btrfs/237 @@ -13,7 +13,7 @@ _begin_fstest auto quick zone balance # Import common functions. -. ./common/filter +. ./common/zoned # real QA test starts here @@ -56,11 +56,7 @@ fi start_data_bg_phy=$(get_data_bg_physical) start_data_bg_phy=$((start_data_bg_phy >> 9)) - -size=$($BLKZONE_PROG report -o $start_data_bg_phy -l 1 $SCRATCH_DEV |\ - _filter_blkzone_report |\ - grep -Po "cap 0x[[:xdigit:]]+" | cut -d ' ' -f 2) -size=$((size << 9)) +size=$(_zone_capacity $start_data_bg_phy) reclaim_threshold=75 echo $reclaim_threshold > /sys/fs/btrfs/"$uuid"/bg_reclaim_threshold From patchwork Wed Oct 5 05:46:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12999014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2898C433F5 for ; Wed, 5 Oct 2022 05:46:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiJEFq4 (ORCPT ); Wed, 5 Oct 2022 01:46:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbiJEFqx (ORCPT ); Wed, 5 Oct 2022 01:46:53 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C66472B6A; Tue, 4 Oct 2022 22:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1664948812; x=1696484812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zz8EGP68GFfz00z+TD7RpSCgY56irAOtcxjJkFkvxcY=; b=kqCz/WtEk/6jQ2SRaWVGjeN27gwiCBV3DMIU4t0l36oMhBhmV8Etpma7 zfdtR3vLPNqBkTmj6Dmo1RACMWj4SXsr/0vXgwc0PGH+KeBiHe89COB4K lOn5UY1e50uphR8Gi4sczqRxoaiDxAj09V1m0u/yLy0+odcqnIdDqSn1K gfIDQuyHPA2px3QDJ/R5HL26bL3Lx0W4lNO6y7nY/Cl2X+VPcJl28+9rc /CbDHV0WLbM/YY9R+GsEpxd9KG4CTTDMwfWeubIND16ooT4rD+GYWVGW5 h3jQkjZfZrgGtNxElcc57HEEH/cmw4EsM1jhaVP0Qtu8j9bUfWjdJAwFZ w==; X-IronPort-AV: E=Sophos;i="5.95,159,1661788800"; d="scan'208";a="317309478" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2022 13:46:51 +0800 IronPort-SDR: anfD7eSWrV9U/CQ5ww8XxZc040TBpNjGEVEdgGl2Kr/DXXMPlQ6KcODXUb9r5oV/mudlRJOQau Pg0A8HCS4iQp6i5tde0yQgTmvudg2rAOvV3oB0YXigtxfgP9tg111Xxpt5xBM1rAWI9TOsvD8v vX33p5GriZpAUKD56QXvig/nmgFtG3oSyj+EOzn5M2R5JRZpk8nyAdbPvnLTGItDDrRyCQrnbR S1mmwEB1T66TXSODY0XzVbhziuvypldYnnBZW/wVOAVVsLFxgDLjD3UYpy6sgfgLa48vJex6Kf 9zm7ofEyF80UN2czC9rZZBKH Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Oct 2022 22:01:04 -0700 IronPort-SDR: 00iWFwHkLBtzBX2I2AuTu8aPb3230OQzo7nGdlB+zKVHh9G9wmbPEimTVw5kOVssZilZXB0m/G Ab8vjpLHFjdfCu08VHOLkgkRfJEctIsiphdHcAz0oHoFO1G99cHqLzQbJmentBeKNPi9JbzC7b o1rKAG7+VTxExtdQpKBeW1iBBjo4EN9p8qMjmaY3aVWPDQXVlMCX9dV3ZkcSH3eeWZxRFkMrIS yM8/PSGngffMPD0qc55pfyOzqqxAG/cQMFHkn3SREU5AD+Xy3aIfLye2jFKS/R5OCptdoOGSqD Njc= WDCIronportException: Internal Received: from 5cg2075dx4.ad.shared (HELO naota-xeon.wdc.com) ([10.225.48.62]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Oct 2022 22:46:51 -0700 From: Naohiro Aota To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 2/2] btrfs: test active zone tracking Date: Wed, 5 Oct 2022 14:46:44 +0900 Message-Id: <244083eb330f899de5f4aef3716a716208796d73.1664948475.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org A ZNS device limits the number of active zones, which is the number of zones can be written at the same time. To deal with the limit, btrfs's zoned mode tracks which zone (corresponds to a block group on the SINGLE profile) is active, and finish a zone if necessary. This test checks if the active zone tracking and the finishing of zones works properly. First, it fills zones mostly. And, run some data/metadata stress workload to force btrfs to use a new zone. This test fails on an older kernel (e.g, 5.18.2) like below. btrfs/292 [failed, exit status 1]- output mismatch (see /host/btrfs/292.out.bad) --- tests/btrfs/292.out 2022-09-15 07:52:18.000000000 +0000 +++ /host/btrfs/292.out.bad 2022-09-15 07:59:14.290967793 +0000 @@ -1,2 +1,5 @@ QA output created by 292 -Silence is golden +stress_data_bgs failed +stress_data_bgs_2 failed +failed: '/bin/btrfs subvolume snapshot /mnt/scratch /mnt/scratch/snap825' +(see /host/btrfs/292.full for details) ... (Run 'diff -u /var/lib/xfstests/tests/btrfs/292.out /host/btrfs/292.out.bad' to see the entire diff) The failure is fixed with a series "btrfs: zoned: fix active zone tracking issues" [1] (upstream commits from 65ea1b66482f ("block: add bdev_max_segments() helper") to 2ce543f47843 ("btrfs: zoned: wait until zone is finished when allocation didn't progress")). [1] https://lore.kernel.org/linux-btrfs/cover.1657321126.git.naohiro.aota@wdc.com/ Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- common/zoned | 11 ++++ tests/btrfs/292 | 143 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/292.out | 2 + 3 files changed, 156 insertions(+) create mode 100755 tests/btrfs/292 create mode 100644 tests/btrfs/292.out diff --git a/common/zoned b/common/zoned index d1bc60f784a1..eed0082a15cf 100644 --- a/common/zoned +++ b/common/zoned @@ -15,6 +15,17 @@ _filter_blkzone_report() sed -e 's/len/cap/2' } +_require_limited_active_zones() { + local dev=$1 + local sysfs=$(_sysfs_dev ${dev}) + local attr="${sysfs}/queue/max_active_zones" + + [ -e "${attr}" ] || _notrun "cannot find queue/max_active_zones. Maybe non-zoned device?" + if [ $(cat "${attr}") == 0 ]; then + _notrun "this test requires limited active zones" + fi +} + _zone_capacity() { local phy=$1 local dev=$2 diff --git a/tests/btrfs/292 b/tests/btrfs/292 new file mode 100755 index 000000000000..00b8e165b102 --- /dev/null +++ b/tests/btrfs/292 @@ -0,0 +1,143 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Western Digital Corporation. All Rights Reserved. +# +# FS QA Test 292 +# +# Test that an active zone is properly reclaimed to allow the further +# allocations, even if the active zones are mostly filled. +# +. ./common/preamble +_begin_fstest auto quick snapshot zone + +# Override the default cleanup function. +_cleanup() +{ + cd / + + # kill commands in stress_data_bgs_2 + [ -n "$pid1" ] && kill $pid1 + [ -n "$pid2" ] && kill $pid2 + wait +} + +# Import common functions. +. ./common/zoned + +# real QA test starts here + +_supported_fs btrfs +_fixed_by_kernel_commit 2ce543f47843 \ + "btrfs: zoned: wait until zone is finished when allocation didn't progress" +# which is further fixed by +_fixed_by_kernel_commit d5b81ced74af \ + "btrfs: zoned: fix API misuse of zone finish waiting" +_require_zoned_device "$SCRATCH_DEV" +_require_limited_active_zones "$SCRATCH_DEV" + +_require_command "$BLKZONE_PROG" blkzone +_require_btrfs_command inspect-internal dump-tree + +# This test requires specific data space usage, skip if we have compression +# enabled. +_require_no_compress + +max_active=$(cat $(_sysfs_dev ${SCRATCH_DEV})/queue/max_active_zones) + +# Fill the zones leaving the last 1MB +fill_active_zones() { + # Asuumes we have the same capacity between zones. + local capacity=$(_zone_capacity 0) + local fill_size=$((capacity - 1024 * 1024)) + + for x in $(seq ${max_active}); do + dd if=/dev/zero of=${SCRATCH_MNT}/fill$(printf "%02d" $x) \ + bs=${fill_size} count=1 oflag=direct 2>/dev/null + $BTRFS_UTIL_PROG filesystem sync ${SCRATCH_MNT} + + local nactive=$($BLKZONE_PROG report ${SCRATCH_DEV} | grep oi | wc -l) + if [[ ${nactive} == ${max_active} ]]; then + break + fi + done + + echo "max active zones: ${max_active}" >> $seqres.full + $BLKZONE_PROG report ${SCRATCH_DEV} | grep oi | cat -n >> $seqres.full +} + +workout() { + local func="$1" + + _scratch_mkfs >/dev/null 2>&1 + _scratch_mount + + fill_active_zones + eval "$func" || _fail "${func} failed" + + _scratch_unmount + _check_btrfs_filesystem ${SCRATCH_DEV} +} + +stress_data_bgs() { + # This dd fails with ENOSPC, which should not :( + dd if=/dev/zero of=${SCRATCH_MNT}/large bs=64M count=1 oflag=sync \ + >>$seqres.full 2>&1 +} + +stress_data_bgs_2() { + # This dd fails with ENOSPC, which should not :( + dd if=/dev/zero of=${SCRATCH_MNT}/large bs=64M count=10 conv=fsync \ + >>$seqres.full 2>&1 & + pid1=$! + + dd if=/dev/zero of=${SCRATCH_MNT}/large2 bs=64M count=10 conv=fsync \ + >>$seqres.full 2>&1 & + pid2=$! + + wait $pid1; local ret1=$?; unset pid1 + wait $pid2; local ret2=$?; unset pid2 + + if [ $ret1 -ne 0 -o $ret2 -ne 0 ]; then + return 1 + fi + return 0 +} + +get_meta_bgs() { + $BTRFS_UTIL_PROG inspect-internal dump-tree -t EXTENT ${SCRATCH_DEV} | + grep BLOCK_GROUP -A 1 |grep -B1 'METADATA|' | + grep -oP '\(\d+ BLOCK_GROUP_ITEM \d+\)' +} + +# This test case does not return the result because +# _run_btrfs_util_prog will call _fail() in the error case anyway. +stress_metadata_bgs() { + local metabgs=$(get_meta_bgs) + local count=0 + + while : ; do + _run_btrfs_util_prog subvolume snapshot ${SCRATCH_MNT} ${SCRATCH_MNT}/snap$i + _run_btrfs_util_prog filesystem sync ${SCRATCH_MNT} + cur_metabgs=$(get_meta_bgs) + if [[ "${cur_metabgs}" != "${metabgs}" ]]; then + break + fi + i=$((i + 1)) + done +} + +WORKS=( + stress_data_bgs + stress_data_bgs_2 + stress_metadata_bgs +) + +for work in "${WORKS[@]}"; do + workout "${work}" +done + +echo "Silence is golden" + +# success, all done +status=0 +exit diff --git a/tests/btrfs/292.out b/tests/btrfs/292.out new file mode 100644 index 000000000000..627309d3fbd2 --- /dev/null +++ b/tests/btrfs/292.out @@ -0,0 +1,2 @@ +QA output created by 292 +Silence is golden