From patchwork Wed Dec 4 08:17:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272271 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38FFD17EF for ; Wed, 4 Dec 2019 08:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 168662073B for ; Wed, 4 Dec 2019 08:19:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="DDMuTaAP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727298AbfLDITb (ORCPT ); Wed, 4 Dec 2019 03:19:31 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32747 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfLDIT1 (ORCPT ); Wed, 4 Dec 2019 03:19:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447568; x=1606983568; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dI1kCb/VRDJYiFLG8VGEf67pizlAWg6fFeBbRKlx4yk=; b=DDMuTaAPb8pGBIEI+aLUstPXAn8tb0kIJctDxktP7H6jL/F3z93EIB1c Ejmk7M/9lu6DIo/jEE3TymovpCwh0tEobw8bxDuxBORp2W0uUol1JZQ/h Vb3rbWTndvK1F2yIE5G1dLpMJh9PD72dBS8GV+23s6K9vWCpQb8tR3oCc jEx0/WfBzqw4P3OMUqznlAmrFfaZycDY6WtUWSiJXnaWSMckvGNrvkOpA hJAZPKGWzJUWXERI1zg+U9syZxd7ISFLUxPmoQd+O21N1nstBOSyRBriS J4MGGjZEpyUU7AfiOtKJbCLZtoOtbur49AV43gwZS0RORK0d5zH5FZGqO A==; IronPort-SDR: 18vFp6JOygJk5TLDdy92KlCP6hL1ES2vYLFM1EjuVQUZ9VDGbi5BohQ1nI2n4pJwqcNcTEt6p/ eMx8FJssmI5WFDZQVUwbj+sQQ8gAPeudwBpIiOKOdNkYU4R6ohRlK26UQ+bqqnUSlWpfjsnWak l296Kjgh2OoSMLLNUi34VFSvHsrSJVmVa6CUQIbEfDuP95wIQVnbsw0xRd12jUxEp77nBRbnaV dBEpOJ23/YRkGpgFw/B2X5Kc6gFWZqhRWpeM6JJFh+6aj/3gMjjxbnCsI71c8exJzFtL3Hx9Cl Zbo= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355014" 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; 04 Dec 2019 16:19:23 +0800 IronPort-SDR: fisbZhC2jFdkMZIGCsCJaFxa5jTmgnUpwsfiu37ZFfybYlOOjBrt6XAKFvUhauZB5yeSUdwnmq 5djD3mlgr9gHGQrmvaxzYHu4u7VKTKoWWHsYfZD2d0veXWFtoKK2l+F5+JJVA6LVLI6hHRTWo7 f3xcEOI9Esi/VIxm7roVbovhLdIYimllLwSH72ShJARscLYZt7J21d/P1k5YiRXAA31tAdqW/x IszNEGOPIsFwLJXuT6cZOcLaBYbNiZd68jqSJvvO58QxfjrL1DlcUQ0i/lJl7Ht9M0mxyYVkN9 7p5lgZgC+ElJFvE3XE8tTHih Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:13:47 -0800 IronPort-SDR: 2S8WF8yotesq/tOZmauvDM8LFCh9GaPYxsXEribcHXnlK3r026mSOqQ0ZvJuNTpINQfAgOH+dF yrjaOC8yhddUT+9Cl0Z3/MEIzt7Yg+SxtLm9AD453OUQLo++kjqCZrersZkhtOqMSkugPq0aIk 3+4XLJuoVCps7lGWMaQNzEI0xl580pqLUFUv922z1WOsVMM5YImLOfkEonc9tGGnF0z7urwoxH fvyoL9GuWO0VBdqoqjtH0MqQ6XMGf0hEabyIn8tOUopqcJaHlF+leLoVKJOmMfq31ZModLDneH KsI= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:20 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 01/28] btrfs: introduce HMZONED feature flag Date: Wed, 4 Dec 2019 17:17:08 +0900 Message-Id: <20191204081735.852438-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This patch introduces the HMZONED incompat flag. The flag indicates that the volume management will satisfy the constraints imposed by host-managed zoned block devices. Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn Signed-off-by: Damien Le Moal Signed-off-by: Naohiro Aota --- fs/btrfs/sysfs.c | 2 ++ include/uapi/linux/btrfs.h | 1 + 2 files changed, 3 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 5ebbe8a5ee76..230c7ad90e22 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -260,6 +260,7 @@ BTRFS_FEAT_ATTR_INCOMPAT(no_holes, NO_HOLES); BTRFS_FEAT_ATTR_INCOMPAT(metadata_uuid, METADATA_UUID); BTRFS_FEAT_ATTR_COMPAT_RO(free_space_tree, FREE_SPACE_TREE); BTRFS_FEAT_ATTR_INCOMPAT(raid1c34, RAID1C34); +BTRFS_FEAT_ATTR_INCOMPAT(hmzoned, HMZONED); static struct attribute *btrfs_supported_feature_attrs[] = { BTRFS_FEAT_ATTR_PTR(mixed_backref), @@ -275,6 +276,7 @@ static struct attribute *btrfs_supported_feature_attrs[] = { BTRFS_FEAT_ATTR_PTR(metadata_uuid), BTRFS_FEAT_ATTR_PTR(free_space_tree), BTRFS_FEAT_ATTR_PTR(raid1c34), + BTRFS_FEAT_ATTR_PTR(hmzoned), NULL }; diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index 7a8bc8b920f5..62c22bf1f702 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -271,6 +271,7 @@ struct btrfs_ioctl_fs_info_args { #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9) #define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10) #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) +#define BTRFS_FEATURE_INCOMPAT_HMZONED (1ULL << 12) struct btrfs_ioctl_feature_flags { __u64 compat_flags; From patchwork Wed Dec 4 08:17:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272273 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E90F16C1 for ; Wed, 4 Dec 2019 08:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF49B2068E for ; Wed, 4 Dec 2019 08:19:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="a8VsCtO8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727273AbfLDITa (ORCPT ); Wed, 4 Dec 2019 03:19:30 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32750 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725951AbfLDIT2 (ORCPT ); Wed, 4 Dec 2019 03:19:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447569; x=1606983569; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wVGBNjAWlvWz3MwTcyINEyxuDIZ2trs71zRfftU9VzM=; b=a8VsCtO862DyIfOSn/sJv68HdVq6D6Ez28DS3yI7DOxfGT9TgW5yfz8t PmFjOHDW6jr6uwJJTLkc27+j7x05xE6tpfCZNlcrzum/ku/H4nA5nzOWv lvbBj5Bd/zwnV3gFxoNbv6+UJLl7/5LwUPnyHl+I0fsVpM8L5BFZ37BDN /2xOIW+OuFl2JLybykxUqCh4IYo9nHMoOevC5xrmZjLG0frlPSlNoQWTW 68/vJ0X9knn8YuCN+hcYk99rTuPFsdzQ63uryMkaVDsFLLkxYf4uQbudO NZbg9dN7ZLm1SRWLmNOJ5YbgmpDVLT8Nh38v+OKF9g0TwvZCUDp6iBqv/ Q==; IronPort-SDR: j39S+1E09hMcCeMPEK+D1xX+DeRKCHK6aYOkJemL0kl0ixXa1GcjblnIarfxCGEWhHqyQozd3r Mtj+HI81V/V1NsxwqqfT03K53IF+OSzxcXamUbdbFw3Rwpt4V0uFcDB9fJxTK+JSRvfQIDhK2P hihJ/ijVLFRimkBfelTurwLCHqARMYUuJKcEJCj6huixMaTdGpAqfQXcZ2Uwq6+CUZ2hVZBaBA jnGZXSq8whNKzoI/ty6JgTYbJL1n/EMJD9xbmjEynRwpU/K9ZwBJTGVEMMl20Q1xEh4dxVFtoj Pb0= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355020" 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; 04 Dec 2019 16:19:25 +0800 IronPort-SDR: RboGRRioxPVVAnESJ6FvQEat9lNjAiu3dk+HpI4Ku6W/xPwixLDV5xDu7hqN7MaVOlkm63h3yx gOAfSHYUCiG3e73+Xv0LxUGU4n+5/nQGM0fEsr9pgI2KoSXVGopxFsfu4fcjhmw1ExtK5xhlvj JSQJY9vZbx/xeupLmwHF+2z950HDjQErgrqPHT+eWgaiO99ny7/Zdt6XLXBIOzdA9jSv1SoNnf sv6Ahs2sgnqdKrcqXRW1s6oOImafYqD1GLsp5z5FXX1pUDkFNUVoYcv5kPdikibXSdpZM4HQ1U fGW0m6nhFNIUeL4BFNlpUxIN Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:13:50 -0800 IronPort-SDR: GJCGumFBk1J/OG7pshExQOGdbCBiVyOC6QzT2ySKFCEO7MauiDVxdaZStvCKP7u16g0AVMCp1G jiRXFDjh3kVqHtzaKrmH+2m4j09JdP0Gv33dc7HAdb/Klr5MkM6s30W8buicOwMrcAKVzOAI45 +0Q4EXIHkFgDu93oEEMs3WcDCmXGGFe9ot+fT3UnWkDC8SNNDIC45ttJ8eeElrm8gDVNAmJ/KM sK2MGfKLYB/SoKDbUSew3HZTINBCn+thxquiIgJvwZo5lcHXcyVKbQ0/DXTqSwcAZjyvcF2pJw 0jU= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:22 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 02/28] btrfs: Get zone information of zoned block devices Date: Wed, 4 Dec 2019 17:17:09 +0900 Message-Id: <20191204081735.852438-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If a zoned block device is found, get its zone information (number of zones and zone size) using the new helper function btrfs_get_dev_zone_info(). To avoid costly run-time zone report commands to test the device zones type during block allocation, attach the seq_zones bitmap to the device structure to indicate if a zone is sequential or accept random writes. Also it attaches the empty_zones bitmap to indicate if a zone is empty or not. This patch also introduces the helper function btrfs_dev_is_sequential() to test if the zone storing a block is a sequential write required zone and btrfs_dev_is_empty_zone() to test if the zone is a empty zone. Signed-off-by: Damien Le Moal Signed-off-by: Naohiro Aota --- fs/btrfs/Makefile | 1 + fs/btrfs/hmzoned.c | 174 +++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 92 ++++++++++++++++++++++++ fs/btrfs/volumes.c | 18 ++++- fs/btrfs/volumes.h | 4 ++ 5 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 fs/btrfs/hmzoned.c create mode 100644 fs/btrfs/hmzoned.h diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 82200dbca5ac..64aaeed397a4 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -16,6 +16,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o btrfs-$(CONFIG_BTRFS_FS_REF_VERIFY) += ref-verify.o +btrfs-$(CONFIG_BLK_DEV_ZONED) += hmzoned.o btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \ tests/extent-buffer-tests.o tests/btrfs-tests.o \ diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c new file mode 100644 index 000000000000..e37335625f76 --- /dev/null +++ b/fs/btrfs/hmzoned.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 Western Digital Corporation or its affiliates. + * Authors: + * Naohiro Aota + * Damien Le Moal + */ + +#include +#include +#include "ctree.h" +#include "volumes.h" +#include "hmzoned.h" +#include "rcu-string.h" + +/* Maximum number of zones to report per blkdev_report_zones() call */ +#define BTRFS_REPORT_NR_ZONES 4096 + +static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos, + struct blk_zone *zones, unsigned int *nr_zones) +{ + int ret; + + ret = blkdev_report_zones(device->bdev, pos >> SECTOR_SHIFT, zones, + nr_zones); + if (ret != 0) { + btrfs_err_in_rcu(device->fs_info, + "get zone at %llu on %s failed %d", pos, + rcu_str_deref(device->name), ret); + return ret; + } + if (!*nr_zones) + return -EIO; + + return 0; +} + +int btrfs_get_dev_zone_info(struct btrfs_device *device) +{ + struct btrfs_zoned_device_info *zone_info = NULL; + struct block_device *bdev = device->bdev; + sector_t nr_sectors = bdev->bd_part->nr_sects; + sector_t sector = 0; + struct blk_zone *zones = NULL; + unsigned int i, nreported = 0, nr_zones; + unsigned int zone_sectors; + int ret; +#define LEN (sizeof(device->fs_info->sb->s_id) + sizeof("(device )") - 1) + char devstr[LEN]; + const int len = LEN; +#undef LEN + + if (!bdev_is_zoned(bdev)) + return 0; + + zone_info = kzalloc(sizeof(*zone_info), GFP_KERNEL); + if (!zone_info) + return -ENOMEM; + + zone_sectors = bdev_zone_sectors(bdev); + ASSERT(is_power_of_2(zone_sectors)); + zone_info->zone_size = (u64)zone_sectors << SECTOR_SHIFT; + zone_info->zone_size_shift = ilog2(zone_info->zone_size); + zone_info->nr_zones = nr_sectors >> ilog2(bdev_zone_sectors(bdev)); + if (nr_sectors & (bdev_zone_sectors(bdev) - 1)) + zone_info->nr_zones++; + + zone_info->seq_zones = kcalloc(BITS_TO_LONGS(zone_info->nr_zones), + sizeof(*zone_info->seq_zones), + GFP_KERNEL); + if (!zone_info->seq_zones) { + ret = -ENOMEM; + goto free_zone_info; + } + + zone_info->empty_zones = kcalloc(BITS_TO_LONGS(zone_info->nr_zones), + sizeof(*zone_info->empty_zones), + GFP_KERNEL); + if (!zone_info->empty_zones) { + ret = -ENOMEM; + goto free_seq_zones; + } + + zones = kcalloc(BTRFS_REPORT_NR_ZONES, + sizeof(struct blk_zone), GFP_KERNEL); + if (!zones) { + ret = -ENOMEM; + goto free_empty_zones; + } + + /* Get zones type */ + while (sector < nr_sectors) { + nr_zones = BTRFS_REPORT_NR_ZONES; + ret = btrfs_get_dev_zones(device, sector << SECTOR_SHIFT, zones, + &nr_zones); + if (ret) + goto free_zones; + + for (i = 0; i < nr_zones; i++) { + if (zones[i].type == BLK_ZONE_TYPE_SEQWRITE_REQ) + set_bit(nreported, zone_info->seq_zones); + if (zones[i].cond == BLK_ZONE_COND_EMPTY) + set_bit(nreported, zone_info->empty_zones); + nreported++; + } + sector = zones[nr_zones - 1].start + zones[nr_zones - 1].len; + } + + if (nreported != zone_info->nr_zones) { + btrfs_err_in_rcu(device->fs_info, + "inconsistent number of zones on %s (%u / %u)", + rcu_str_deref(device->name), nreported, + zone_info->nr_zones); + ret = -EIO; + goto free_zones; + } + + kfree(zones); + + device->zone_info = zone_info; + + devstr[0] = 0; + if (device->fs_info) + snprintf(devstr, len, " (device %s)", + device->fs_info->sb->s_id); + + rcu_read_lock(); + pr_info( +"BTRFS info%s: host-%s zoned block device %s, %u zones of %llu sectors", + devstr, + bdev_zoned_model(bdev) == BLK_ZONED_HM ? "managed" : "aware", + rcu_str_deref(device->name), zone_info->nr_zones, + zone_info->zone_size >> SECTOR_SHIFT); + rcu_read_unlock(); + + return 0; + +free_zones: + kfree(zones); +free_empty_zones: + kfree(zone_info->empty_zones); +free_seq_zones: + kfree(zone_info->seq_zones); +free_zone_info: + kfree(zone_info); + + return ret; +} + +void btrfs_destroy_dev_zone_info(struct btrfs_device *device) +{ + struct btrfs_zoned_device_info *zone_info = device->zone_info; + + if (!zone_info) + return; + + kfree(zone_info->seq_zones); + kfree(zone_info->empty_zones); + kfree(zone_info); + device->zone_info = NULL; +} + +int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, + struct blk_zone *zone) +{ + unsigned int nr_zones = 1; + int ret; + + ret = btrfs_get_dev_zones(device, pos, zone, &nr_zones); + if (ret != 0 || !nr_zones) + return ret ? ret : -EIO; + + return 0; +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h new file mode 100644 index 000000000000..0f8006f39aaf --- /dev/null +++ b/fs/btrfs/hmzoned.h @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2019 Western Digital Corporation or its affiliates. + * Authors: + * Naohiro Aota + * Damien Le Moal + */ + +#ifndef BTRFS_HMZONED_H +#define BTRFS_HMZONED_H + +struct btrfs_zoned_device_info { + /* + * Number of zones, zone size and types of zones if bdev is a + * zoned block device. + */ + u64 zone_size; + u8 zone_size_shift; + u32 nr_zones; + unsigned long *seq_zones; + unsigned long *empty_zones; +}; + +#ifdef CONFIG_BLK_DEV_ZONED +int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, + struct blk_zone *zone); +int btrfs_get_dev_zone_info(struct btrfs_device *device); +void btrfs_destroy_dev_zone_info(struct btrfs_device *device); +#else /* CONFIG_BLK_DEV_ZONED */ +static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, + struct blk_zone *zone) +{ + return 0; +} +static inline int btrfs_get_dev_zone_info(struct btrfs_device *device) +{ + return 0; +} +static inline void btrfs_destroy_dev_zone_info(struct btrfs_device *device) { } +#endif + +static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) +{ + struct btrfs_zoned_device_info *zone_info = device->zone_info; + + if (!zone_info) + return false; + + return test_bit(pos >> zone_info->zone_size_shift, + zone_info->seq_zones); +} + +static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos) +{ + struct btrfs_zoned_device_info *zone_info = device->zone_info; + + if (!zone_info) + return true; + + return test_bit(pos >> zone_info->zone_size_shift, + zone_info->empty_zones); +} + +static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device, + u64 pos, bool set) +{ + struct btrfs_zoned_device_info *zone_info = device->zone_info; + unsigned int zno; + + if (!zone_info) + return; + + zno = pos >> zone_info->zone_size_shift; + if (set) + set_bit(zno, zone_info->empty_zones); + else + clear_bit(zno, zone_info->empty_zones); +} + +static inline void btrfs_dev_set_zone_empty(struct btrfs_device *device, + u64 pos) +{ + btrfs_dev_set_empty_zone_bit(device, pos, true); +} + +static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, + u64 pos) +{ + btrfs_dev_set_empty_zone_bit(device, pos, false); +} + +#endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d8e5560db285..18ea8dfce244 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -30,6 +30,7 @@ #include "tree-checker.h" #include "space-info.h" #include "block-group.h" +#include "hmzoned.h" const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { [BTRFS_RAID_RAID10] = { @@ -366,6 +367,7 @@ void btrfs_free_device(struct btrfs_device *device) rcu_string_free(device->name); extent_io_tree_release(&device->alloc_state); bio_put(device->flush_bio); + btrfs_destroy_dev_zone_info(device); kfree(device); } @@ -650,6 +652,11 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); device->mode = flags; + /* Get zone type information of zoned block devices */ + ret = btrfs_get_dev_zone_info(device); + if (ret != 0) + goto error_brelse; + fs_devices->open_devices++; if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) && device->devid != BTRFS_DEV_REPLACE_DEVID) { @@ -2421,6 +2428,14 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path } rcu_assign_pointer(device->name, name); + device->fs_info = fs_info; + device->bdev = bdev; + + /* Get zone type information of zoned block devices */ + ret = btrfs_get_dev_zone_info(device); + if (ret) + goto error_free_device; + trans = btrfs_start_transaction(root, 0); if (IS_ERR(trans)) { ret = PTR_ERR(trans); @@ -2437,8 +2452,6 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path fs_info->sectorsize); device->disk_total_bytes = device->total_bytes; device->commit_total_bytes = device->total_bytes; - device->fs_info = fs_info; - device->bdev = bdev; set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state); device->mode = FMODE_EXCL; @@ -2571,6 +2584,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path sb->s_flags |= SB_RDONLY; if (trans) btrfs_end_transaction(trans); + btrfs_destroy_dev_zone_info(device); error_free_device: btrfs_free_device(device); error: diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index fc1b564b9cfe..70cabe65f72a 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -53,6 +53,8 @@ struct btrfs_io_geometry { #define BTRFS_DEV_STATE_REPLACE_TGT (3) #define BTRFS_DEV_STATE_FLUSH_SENT (4) +struct btrfs_zoned_device_info; + struct btrfs_device { struct list_head dev_list; /* device_list_mutex */ struct list_head dev_alloc_list; /* chunk mutex */ @@ -66,6 +68,8 @@ struct btrfs_device { struct block_device *bdev; + struct btrfs_zoned_device_info *zone_info; + /* the mode sent to blkdev_get */ fmode_t mode; From patchwork Wed Dec 4 08:17:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272285 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64D2D17EF for ; Wed, 4 Dec 2019 08:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A8F82068E for ; Wed, 4 Dec 2019 08:19:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nkqP8kbo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727333AbfLDITf (ORCPT ); Wed, 4 Dec 2019 03:19:35 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32747 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727219AbfLDITa (ORCPT ); Wed, 4 Dec 2019 03:19:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447570; x=1606983570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=weOQDIbg5A3au1LrS36I3ofNEuVjw1L2FVj2RaFk/cs=; b=nkqP8kbopGP+dgUWGDVljxnierEgFUaV9XHnh7kE+OoD6OXpSgmq+zJj 6vyNqLeCtF0CBjj8RdHQI/GkDT+YrsJE9OsL64Zoei6MYBV6PFIqU9a+w vML5qdAv097jz2DIAlinUba+SFcIO32DhEU13R3lP/n23V8rWDqUwCIB7 ZDm31uQdEVsNeNs8zMfeaCQfC/dZgECSVXMf6fUzOmbnnbMKqBfZWuy97 xAZAPT+v4qo06H9abIW+6g+ml9WP9uMLPd7xvuA0clHQd2v1dCXJdv6ms xRsEN5ITheuE8TsI3+n6klR8Dd+UEC39i/k2DifEUsUpzQuoL/VDktRYH g==; IronPort-SDR: pYCWB8Tyq/q3LaVp14IlbknMQDT8+XD4tkHsQ2tjRIQmZuoa/5nZMeUenX8ylijIYkGBSMNwwT oLYt8JbyyXRxSbh4OBVeIcK2ojCZ4Rb5l6epqWvTXzu06Vtud+NPIpqTCWEp8RJypoM4hRFGr/ Uxjv/+xuhkXpZEqo0HT2tI0Of4ePfnVDwE2ll6RIqIZ3w2pFjUgeHGlESDsbVLPNf0CHqkRhyB oWKe00Ky5vaNDtpjqxMiLmYyFFPsDIglwG8hxlYbnLVqW66GMaH32z88LSV5lzI65ssyrEunA/ DkQ= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355024" 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; 04 Dec 2019 16:19:28 +0800 IronPort-SDR: nCA0aeVAso6shZtVrwQ/nNuhPLSIDgPQexrkoz7rlWVJkq88YDZmX1L1/TokOnrqpzszt37+W5 Shu/h/g8HmHiJK63093abfih/bK6u73IzTUC9E7swB2bzsODlPjWgbQaeRWjDeUEkvJDinn8rM AQH7WsxP/GS7ui05l4ae/guYLvC/ksFvcW1p7GA60JOG7bo81jBD/lC3xWjzTNxwHBT+lMi98o Rjfx6sOz/oZkIDHY5aaLvwKWF+5dsM8lgvzelPKT3ia0ijs11BW1rrQTC9nfE5L9eoebO77Wfv ZAKZucaO4+ofKJ7o56lWUve7 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:13:53 -0800 IronPort-SDR: 0Ytsj2Tp5UVizCwxBzOr4sy/vpNqxuB8Wq/3OHXRHCiI2bOoqKEeKAO096kYPlL+R5YcQap8dv EARvM8x+kxvr+QMLx7T4aV9dDFsMPOBVcS+sqF7oB0FMy8KP67dG1NLz58wGe2QYBArDziZi+e ceOq3dP+jTbLB0K0f2pm7BD+7PWX3o4Tvauc2Pln0OXXmv9tJXi/WIr23YK3FTbcfVx3+Ugnt/ sFa3uQX6LqSUU6l15aIBk9pQdHoEiD+tm29ckWYPzUkL/PTGJq0qcg0GhCaIQycP/gBq5v5io3 14U= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:24 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 03/28] btrfs: Check and enable HMZONED mode Date: Wed, 4 Dec 2019 17:17:10 +0900 Message-Id: <20191204081735.852438-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org HMZONED mode cannot be used together with the RAID5/6 profile for now. Introduce the function btrfs_check_hmzoned_mode() to check this. This function will also check if HMZONED flag is enabled on the file system and if the file system consists of zoned devices with equal zone size. Additionally, as updates to the space cache are in-place, the space cache cannot be located over sequential zones and there is no guarantees that the device will have enough conventional zones to store this cache. Resolve this problem by completely disabling the space cache. This does not introduce any problems in HMZONED mode: all the free space is located after the allocation pointer and no free space is located before the pointer. There is no need to have such cache. For the same reason, NODATACOW is also disabled. Also INODE_MAP_CACHE is also disabled to avoid preallocation in the INODE_MAP_CACHE inode. In summary, HMZONED will disable: | Disabled features | Reason | |-------------------+-----------------------------------------------------| | RAID5/6 | 1) Non-full stripe write cause overwriting of | | | parity block | | | 2) Rebuilding on high capacity volume (usually with | | | SMR) can lead to higher failure rate | |-------------------+-----------------------------------------------------| | space_cache (v1) | In-place updating | | NODATACOW | In-place updating | |-------------------+-----------------------------------------------------| | fallocate | Reserved extent will be a write hole | | INODE_MAP_CACHE | Need pre-allocation. (and will be deprecated?) | |-------------------+-----------------------------------------------------| | MIXED_BG | Allocated metadata region will be write holes for | | | data writes | | async checksum | Not to mix up bios by multiple workers | Signed-off-by: Damien Le Moal Signed-off-by: Naohiro Aota --- fs/btrfs/ctree.h | 3 ++ fs/btrfs/dev-replace.c | 8 +++++ fs/btrfs/disk-io.c | 8 +++++ fs/btrfs/hmzoned.c | 74 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 26 +++++++++++++++ fs/btrfs/super.c | 1 + fs/btrfs/volumes.c | 5 +++ 7 files changed, 125 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index b2e8fd8a8e59..44517802b9e5 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -541,6 +541,9 @@ struct btrfs_fs_info { struct btrfs_root *uuid_root; struct btrfs_root *free_space_root; + /* Zone size when in HMZONED mode */ + u64 zone_size; + /* the log root tree is a directory of all the other log roots */ struct btrfs_root *log_root_tree; diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index f639dde2a679..9286c6e0b636 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -21,6 +21,7 @@ #include "rcu-string.h" #include "dev-replace.h" #include "sysfs.h" +#include "hmzoned.h" static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, int scrub_ret); @@ -202,6 +203,13 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, return PTR_ERR(bdev); } + if (!btrfs_check_device_zone_type(fs_info, bdev)) { + btrfs_err(fs_info, + "zone type of target device mismatch with the filesystem!"); + ret = -EINVAL; + goto error; + } + sync_blockdev(bdev); devices = &fs_info->fs_devices->devices; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index e0edfdc9c82b..ff418e393f82 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -41,6 +41,7 @@ #include "tree-checker.h" #include "ref-verify.h" #include "block-group.h" +#include "hmzoned.h" #define BTRFS_SUPER_FLAG_SUPP (BTRFS_HEADER_FLAG_WRITTEN |\ BTRFS_HEADER_FLAG_RELOC |\ @@ -3082,6 +3083,13 @@ int __cold open_ctree(struct super_block *sb, btrfs_free_extra_devids(fs_devices, 1); + ret = btrfs_check_hmzoned_mode(fs_info); + if (ret) { + btrfs_err(fs_info, "failed to init hmzoned mode: %d", + ret); + goto fail_block_groups; + } + ret = btrfs_sysfs_add_fsid(fs_devices, NULL); if (ret) { btrfs_err(fs_info, "failed to init sysfs fsid interface: %d", diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index e37335625f76..9a04240910f6 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -172,3 +172,77 @@ int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, return 0; } + +int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info) +{ + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + struct btrfs_device *device; + u64 hmzoned_devices = 0; + u64 nr_devices = 0; + u64 zone_size = 0; + int incompat_hmzoned = btrfs_fs_incompat(fs_info, HMZONED); + int ret = 0; + + /* Count zoned devices */ + list_for_each_entry(device, &fs_devices->devices, dev_list) { + if (!device->bdev) + continue; + if (bdev_zoned_model(device->bdev) == BLK_ZONED_HM || + (bdev_zoned_model(device->bdev) == BLK_ZONED_HA && + incompat_hmzoned)) { + hmzoned_devices++; + if (!zone_size) { + zone_size = device->zone_info->zone_size; + } else if (device->zone_info->zone_size != zone_size) { + btrfs_err(fs_info, + "Zoned block devices must have equal zone sizes"); + ret = -EINVAL; + goto out; + } + } + nr_devices++; + } + + if (!hmzoned_devices && !incompat_hmzoned) + goto out; + + if (!hmzoned_devices && incompat_hmzoned) { + /* No zoned block device found on HMZONED FS */ + btrfs_err(fs_info, "HMZONED enabled file system should have zoned devices"); + ret = -EINVAL; + goto out; + } + + if (hmzoned_devices && !incompat_hmzoned) { + btrfs_err(fs_info, + "Enable HMZONED mode to mount HMZONED device"); + ret = -EINVAL; + goto out; + } + + fs_info->zone_size = zone_size; + + if (hmzoned_devices != nr_devices) { + btrfs_err(fs_info, + "zoned devices cannot be mixed with regular devices"); + ret = -EINVAL; + goto out; + } + + /* + * stripe_size is always aligned to BTRFS_STRIPE_LEN in + * __btrfs_alloc_chunk(). Since we want stripe_len == zone_size, + * check the alignment here. + */ + if (!IS_ALIGNED(zone_size, BTRFS_STRIPE_LEN)) { + btrfs_err(fs_info, + "zone size is not aligned to BTRFS_STRIPE_LEN"); + ret = -EINVAL; + goto out; + } + + btrfs_info(fs_info, "HMZONED mode enabled, zone size %llu B", + fs_info->zone_size); +out: + return ret; +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index 0f8006f39aaf..8e17f64ff986 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -9,6 +9,8 @@ #ifndef BTRFS_HMZONED_H #define BTRFS_HMZONED_H +#include + struct btrfs_zoned_device_info { /* * Number of zones, zone size and types of zones if bdev is a @@ -26,6 +28,7 @@ int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone); int btrfs_get_dev_zone_info(struct btrfs_device *device); void btrfs_destroy_dev_zone_info(struct btrfs_device *device); +int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -37,6 +40,14 @@ static inline int btrfs_get_dev_zone_info(struct btrfs_device *device) return 0; } static inline void btrfs_destroy_dev_zone_info(struct btrfs_device *device) { } +static inline int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info) +{ + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return 0; + + btrfs_err(fs_info, "Zoned block devices support is not enabled"); + return -EOPNOTSUPP; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) @@ -89,4 +100,19 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, btrfs_dev_set_empty_zone_bit(device, pos, false); } +static inline bool btrfs_check_device_zone_type(struct btrfs_fs_info *fs_info, + struct block_device *bdev) +{ + u64 zone_size; + + if (btrfs_fs_incompat(fs_info, HMZONED)) { + zone_size = (u64)bdev_zone_sectors(bdev) << SECTOR_SHIFT; + /* Do not allow non-zoned device */ + return bdev_is_zoned(bdev) && fs_info->zone_size == zone_size; + } + + /* Do not allow Host Manged zoned device */ + return bdev_zoned_model(bdev) != BLK_ZONED_HM; +} + #endif diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index a98c3c71fc54..616f5abec267 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -44,6 +44,7 @@ #include "backref.h" #include "space-info.h" #include "sysfs.h" +#include "hmzoned.h" #include "tests/btrfs-tests.h" #include "block-group.h" diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 18ea8dfce244..ab3590b310af 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2395,6 +2395,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path if (IS_ERR(bdev)) return PTR_ERR(bdev); + if (!btrfs_check_device_zone_type(fs_info, bdev)) { + ret = -EINVAL; + goto error; + } + if (fs_devices->seeding) { seeding_dev = 1; down_write(&sb->s_umount); From patchwork Wed Dec 4 08:17:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272275 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E52D96C1 for ; Wed, 4 Dec 2019 08:19:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C387F2068E for ; Wed, 4 Dec 2019 08:19:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Degszd2B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbfLDITd (ORCPT ); Wed, 4 Dec 2019 03:19:33 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32750 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727268AbfLDITa (ORCPT ); Wed, 4 Dec 2019 03:19:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447571; x=1606983571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PbWaR4sjrNTc1oHZ4k8YsfgtzKO5GNAOEB8mw/dXAwI=; b=Degszd2Bkp4BZ6O7Qox8rOgkwUgr7qQYLNZh5AE+fBhCYDW+V0TWmy2y +P9xIt3+ZBV0FPePEalnshheEUdY6mTA5q6Z9cmt5jPKMfr/HScPwkya0 hcLBGJsNV2QAn3KFas2Ue0BH1CX2BJe7gNMU/n4NgN2T0XQmFlGIzzXfw KJoS31kkuNZfM1Z3niV+xkrbCcS0Ttk0JoSxXHotKdSkCr60GSGR53bfU nfRggRFksdK25Yn24WtUgsIMhIMjx9rv0H25y11El7ugc+G64Iq7hB0bw 09RWLF4eQ83nVn3kyJsY0duJvCshaF4//uIbYGVG4SWV6U1MIb1iYAXQS A==; IronPort-SDR: eLxry8xYfrlujwJVpMtZkYA5SwYmxXHyONdEIumYMhECXiB2QmgVeR6pgAYJPbR/eTpZzdMhjA 29SAO+YPUvTwsumd3SVd5rtRute7LU6y7dMMuMoJ1ltwlFQNAR3RWx8yenyTt0hSHxzssGS+OM 47eSzYtIsDWJ2ybTZZVffk3oGivAvnHVUVglykmyyeKphbQiUQc2S0Xi7C5bkhG+REEwXWOtcR aQUiWG0o5DC7ykuyiZVBH1oFz0XJo3ijSaDZL3y6vaOrCrIQu5yejGWW8Kz6qM+qbojLp6Kkbh NFw= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355028" 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; 04 Dec 2019 16:19:30 +0800 IronPort-SDR: jn7aLJwloHOBsfB23eOvu1++hf7emf9T1IAY6wnK40oGtlzhUs7YaO0Mvho/+jXD7tvayIpcDj N4ThqIW2ocJCDVaPpcagTuo/K2/uZVUKaIs6o5FFMZ4S5H+VISGPSNbHVpZn2kJvHquyF3zAei LhMtF9LuKl+nQNNbiGOCvBTPKuQHnEgB7mohs7HhaDJbN0MjwozuhLIxRZJsQHwrgn8AyccK+K vd10dzll0n4y+NQ9OnrDAsaADf3WnOl/W+q8Ivqxt7Vlu0CNDDo0qMl2m9FkxzfrRbNKMWqwl3 jhp3IicvXCfgWNZKmOoiFu4Q Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:13:55 -0800 IronPort-SDR: UmW8DpnUa4qNLOBDv8n/rvJJqLcpdTYH+fe0E8wrZbXQY0ALCe6gxNA7+uSPEmxrsNL74fNpkF ezMzTK6FZgpHrnD+5EtIjlr9HjMWtAFeRBiiCXkF37aQ4XjivBNwsIrMaStXCo4MzIEsKJhCuc V6wc2G88ZOgzi6fHL/EzoKBFvmKule9As/TPDvbhACPvBP0KP7mfF11FC89xh0QqGtpk/3zISd eJTj4hMjTll+cMJa46RR94uP/eKI53U//zz2wQW/uQUMzV4o6jVeUzirAeO3dtGtosMAajfFcA bWo= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:28 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 04/28] btrfs: disallow RAID5/6 in HMZONED mode Date: Wed, 4 Dec 2019 17:17:11 +0900 Message-Id: <20191204081735.852438-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Supporting the RAID5/6 profile in HMZONED mode is not trivial. For example, non-full stripe writes will cause overwriting parity blocks. When we do a non-full stripe write, it writes to the parity block with the data at that moment. Then, another write to the stripes will try to overwrite the parity block with new parity value. However, sequential zones do not allow such parity overwriting. Furthermore, using RAID5/6 on SMR drives, which usually have a huge capacity, incur large overhead of rebuild. Such overhead can lead to higher to higher volume failure rate (e.g. additional drive failure during rebuild) because of the increased rebuild time. Thus, let's disable RAID5/6 profile in HMZONED mode for now. Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota --- fs/btrfs/hmzoned.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 9a04240910f6..b74581133a72 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -241,6 +241,13 @@ int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info) goto out; } + /* RAID56 is not allowed */ + if (btrfs_fs_incompat(fs_info, RAID56)) { + btrfs_err(fs_info, "HMZONED mode does not support RAID56"); + ret = -EINVAL; + goto out; + } + btrfs_info(fs_info, "HMZONED mode enabled, zone size %llu B", fs_info->zone_size); out: From patchwork Wed Dec 4 08:17:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272287 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A3AF76C1 for ; Wed, 4 Dec 2019 08:19:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 81E772068E for ; Wed, 4 Dec 2019 08:19:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="i3VNVMm9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727328AbfLDITf (ORCPT ); Wed, 4 Dec 2019 03:19:35 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32758 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfLDITd (ORCPT ); Wed, 4 Dec 2019 03:19:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447573; x=1606983573; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QBsiVYR4rO2XcDZTvs+beR5Uiu6ji7PzJZEi+KlKlog=; b=i3VNVMm9cyx3S27SmztibvKRp7jxTw4qNCp9JyhTVmlwyNk38qrq0MPz rzf9A9qxDnYnJDZ66TywdBp1DmGaNRfsPbQySrHYnIMCpSrwkBJBJwTeS 8wQZIqW3Z81mad67H8TC0rgw9SvLT5BHAzBNp4DEQNt9iEL6k2ukVc3QI /lsRzgQSds6JIpYGuKyRmHRpj+PuUeWm8jtmB7kht/yn4Rfx+kjAC2k2A VAEh5fCBlvIwWMgi2cu7TdwUWkKdD3M0wy+vjvaKcUT/8zJTWUWrN3gfy A2TSFw9ppfSZCAtF1dIkNstQ0an6YPWMLiVq3olyvrVpWTSmXQMCpsSyK g==; IronPort-SDR: 2XmtujSn/4gT4e5oU6omv4doGj1hTbdVM1nnXLWjKjAGbY0tecCiLBeRVl4363j6gBHtiYWwu2 xh+F1IMqhN3ftLFf3fPJ9hOKxij0ew/kGmVVoQsg2FPb3VLY5jT0QS1MN04XM0Mttzox18M2aG IxYWZlrzYGDnGOUYrUq2HvyuO8QYjqG6UPB4AF0B4G9+v5wKktoga9FdmFJfXFHLGyBpSc/B/9 WjBCIKfFmPHiRLW3KF2CB5O66OmvLMHoQLSE5D+nWop+gR/KUPb5vVF/mccP+FMMIp9+CnhffD no4= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355039" 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; 04 Dec 2019 16:19:33 +0800 IronPort-SDR: MptxuiiQck5oMz846xnv2SwvYbBPKSR0aT74PDDvf9DTRpLbrR1+C6JJ0MwBJ1p81Vvq5fbOp+ jINcbzWRRYYmH/XsMZnGVgeg4vgFxODdNgWBrij2Pz+X50Yshswvraj5HQXmlNAb8clFjC+ee9 m4CmvXFAJzur3TFyroFn/ZHXHpk0M1c0Jg1fwuMrg8wZqQzJkGHQoqxgTBy9xJHytEN1qEqiUe GQnrvgkAIGNJ+D67KPWqa6RJ09Eh8oz6x2YekrhOrzlm+6EdsyJICmqWLig8232dRN+Hkh18Zl rfuDyF9ki78oQ1vG7zKLceQr Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:13:57 -0800 IronPort-SDR: G8hzCQYkwffnwcfqEl/RfYI7tDw8xnooM0EgbFD/Vvh/AwULZvVoO6SWJetJjHPWHuOgRdGz7q AW4+PahAWk/hJV4UjKYfLh8Z0929nxbPICQxNkQhu1Cc4WaTUc3A05ZFr44Ibju12TwaIQQBsC UI0ZZ+AOhthxKq2gwdE3Fmi2niiilZy2p6b+E9bWNVuKYwWj1kMfaxJuV2PCWGPID6jE2BSzt1 ETe6f1WN4oZS6o+1+yYuml3I49HBU6vJt0J/O7RODqeugw1sjrjuqNRd8U8vZHksKXebA8iESA W50= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:30 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 05/28] btrfs: disallow space_cache in HMZONED mode Date: Wed, 4 Dec 2019 17:17:12 +0900 Message-Id: <20191204081735.852438-6-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As updates to the space cache are in-place, the space cache cannot be located over sequential zones and there is no guarantees that the device will have enough conventional zones to store this cache. Resolve this problem by disabling completely the space cache. This does not introduces any problems with sequential block groups: all the free space is located after the allocation pointer and no free space before the pointer. There is no need to have such cache. Signed-off-by: Naohiro Aota --- fs/btrfs/hmzoned.c | 18 ++++++++++++++++++ fs/btrfs/hmzoned.h | 5 +++++ fs/btrfs/super.c | 10 ++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index b74581133a72..1c015ed050fc 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -253,3 +253,21 @@ int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info) out: return ret; } + +int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info) +{ + if (!btrfs_fs_incompat(info, HMZONED)) + return 0; + + /* + * SPACE CACHE writing is not CoWed. Disable that to avoid + * write errors in sequential zones. + */ + if (btrfs_test_opt(info, SPACE_CACHE)) { + btrfs_err(info, + "cannot enable disk space caching with HMZONED mode"); + return -EINVAL; + } + + return 0; +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index 8e17f64ff986..d9ebe11afdf5 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -29,6 +29,7 @@ int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, int btrfs_get_dev_zone_info(struct btrfs_device *device); void btrfs_destroy_dev_zone_info(struct btrfs_device *device); int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info); +int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -48,6 +49,10 @@ static inline int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info) btrfs_err(fs_info, "Zoned block devices support is not enabled"); return -EOPNOTSUPP; } +static inline int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info) +{ + return 0; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 616f5abec267..d411574298f4 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -442,8 +442,12 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, cache_gen = btrfs_super_cache_generation(info->super_copy); if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE)) btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE); - else if (cache_gen) - btrfs_set_opt(info->mount_opt, SPACE_CACHE); + else if (cache_gen) { + if (btrfs_fs_incompat(info, HMZONED)) + WARN_ON(1); + else + btrfs_set_opt(info->mount_opt, SPACE_CACHE); + } /* * Even the options are empty, we still need to do extra check @@ -879,6 +883,8 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, ret = -EINVAL; } + if (!ret) + ret = btrfs_check_mountopts_hmzoned(info); if (!ret && btrfs_test_opt(info, SPACE_CACHE)) btrfs_info(info, "disk space caching is enabled"); if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE)) From patchwork Wed Dec 4 08:17:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6DAD817EF for ; Wed, 4 Dec 2019 08:19:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C2232068E for ; Wed, 4 Dec 2019 08:19:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="gljjA7dV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbfLDITj (ORCPT ); Wed, 4 Dec 2019 03:19:39 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32758 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfLDITf (ORCPT ); Wed, 4 Dec 2019 03:19:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447575; x=1606983575; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wWVf0lcmjygoveqYvU8ay6sHk4wiR0WqOto3mwXnybY=; b=gljjA7dVOv74sBvLC+T1MRbW+zKqel3i/bwNXa59eCgs06RsEOiubbgk UzrlDVMe71EQ/tckYQA205E4Xa5O+6Uxq3Pb6tl0bz4jCnzoO2Qj1lJS7 Pp7rEANZXBOsu+WVtQjOsIXl/MtmQAagkFtUFtL/bj92IOPyNCg+ACJ7z RsVH/1SfMZcXyZFxt/f4TI61ifLr6kyaMC2jtnibtDQtJddy1w9YpFtaV 7F+a8cR2fMjOeYiWfN3gqAhilnE6x4oEjfdGHKuIB/1buHOmJgrw+6Et6 DyJVan7ES1EWb2aH7OXoZfOxGnyWsL6DOq3zBOBCkiRZX3AvkYVjC2Yig A==; IronPort-SDR: WWucve8mRjCpO0j13mjqY+4YL0ebsFzOgVxc7OIW5lVpfz/Ucfpmcchu1Pnq2TRWbQl/G69rch SGInYeElQ26bYVKyc2oiTK65gav5wyl1Ax2MZtX6AZ11FJxx6ADVTyy9Bgk625jGNhHb4HU1YN dbmLQscFEUzoZy/xwTBv8a2O9L8FwQ4V/W0u1K3Y+uJh/kOT2vzXYZE4XBbKfhyusbO/4kB0d6 1vhSSZuO//wNOy0x+3uw5YajO5UJ3ZZg8jI+NexBHLDPgS55UsnWw2jh2sYn5qzX0mXcOWXdrT n/k= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355044" 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; 04 Dec 2019 16:19:35 +0800 IronPort-SDR: Vss65OUv2CM64D4zQu6tkVs5Oj7qWcpfrPhRo6ReDblC9gwI4c38gQP+AIB2CrFMAuuqWi7KBu KbKOVL2k0XkQ/4r9YWvWUA80RTeuQgMCd34ZWEtCPRVI00Jh93Sgu6bSRaPLqiaG1uKaj6r5fL sjl9M0Bc6Ps8IV4vpTbAG56Ms71urEsLQ2Sir0IHlCAo92aDyazAM61L2P2JWBKe1joqnY1qZU muqQZPFZ5vneNHPfH/93M3kUAHOkNnPCE9xPmgSWfzZdEkjEduXxvlwxoQg2ahPOKETJwvsSd/ f55+WfwYC+ezdJsHB5thmsCT Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:00 -0800 IronPort-SDR: ZL5KajSgX7aCIrTA0Jj6luvtF/ZgsEX+3xTFLBB91aWQKJr5BwIBGcu4/U29ziKvKIBvt8Otoi 1KfO444CNVtdvizlT4Jv6P8v4Bpj4dkcImNptmu00rVuSu7DMBVflTxA9H3mkmXUj1K9J4xGZx q+f4VK8MRaVFfZRYouN81ia8vIK6vblT9KwaFzevOwfn8hjeeEvkoKL3DVj8gdtpYXMbso7Bv0 IrXAuiNq5iJiITaz1BVTRTWEsfPcSygH05BYeKwjYtUTwMzKzRtev6JK+uSGtAqGQg+EG1NewG zq0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:32 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 06/28] btrfs: disallow NODATACOW in HMZONED mode Date: Wed, 4 Dec 2019 17:17:13 +0900 Message-Id: <20191204081735.852438-7-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org NODATACOW implies overwriting the file data on a device, which is impossible in sequential required zones. Disable NODATACOW globally with mount option and per-file NODATACOW attribute by masking FS_NOCOW_FL. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/hmzoned.c | 6 ++++++ fs/btrfs/ioctl.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 1c015ed050fc..e890d2ab8cd9 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -269,5 +269,11 @@ int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info) return -EINVAL; } + if (btrfs_test_opt(info, NODATACOW)) { + btrfs_err(info, + "cannot enable nodatacow with HMZONED mode"); + return -EINVAL; + } + return 0; } diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a1ee0b775e65..a67421eb8bd5 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -94,6 +94,9 @@ static int btrfs_clone(struct inode *src, struct inode *inode, static unsigned int btrfs_mask_fsflags_for_type(struct inode *inode, unsigned int flags) { + if (btrfs_fs_incompat(btrfs_sb(inode->i_sb), HMZONED)) + flags &= ~FS_NOCOW_FL; + if (S_ISDIR(inode->i_mode)) return flags; else if (S_ISREG(inode->i_mode)) From patchwork Wed Dec 4 08:17:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E0386C1 for ; Wed, 4 Dec 2019 08:19:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C37B206DF for ; Wed, 4 Dec 2019 08:19:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="GgFUR8SI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727360AbfLDITl (ORCPT ); Wed, 4 Dec 2019 03:19:41 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32758 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727219AbfLDITh (ORCPT ); Wed, 4 Dec 2019 03:19:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447577; x=1606983577; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jxw4CEGwoy8t1QezrDvEjaSMaFQakiEMAHs/uxO0A6s=; b=GgFUR8SItMEzeEkgVcUiAaS5aiZsQBxgf/uetWHPjhC/BRutm97aDQKp pVidrzoPKrYP9o7TW0mdPLssLCI35NQx4zjH49oJQmbskVY2ZeDtbjP7u /d1oND6sc/A3YJydklXajgcsdIbpdKfrDAoJ1qXBCk3Yd2R5NitCM0+O4 GZrQx8tZBr2AiRcOzRlYrIByIxfaErwW+Sk7VX8zfNOD8W1awZjVDe1zS oNhc9MK//XxCRW3kHS28OoKEabLFdo1BI2UtxMBuU99w1e/+8suhYcAXW AV/Ey5IjR5ds1NQnJzPJXHIvEGz37mg7/NPYbQVXMjEi/miG8GiEt/MSj A==; IronPort-SDR: fyaSEeTcVk48QFnsMZqjO1Qk7Wy05TTWzCRmDtV5FuO7OPm+xRHoqmHJl0cIRWFG190wytrA00 7zToSkOLaHLI7zQmAWNMZkDqw/0zQIWgDn6upPxyKFg8U6798gTBJKKDIC496tL8B6uPwHcuP6 wkgzduGC07p/UftAeBz38Uw50dDP+Xs6K7ZXsqylfD/ZRDCOGtDgKa6T9NY9qIBKtgJfCGHPXP ubuIOjj6R4Iwv5IZWz4yrorHNurdPtoZllO6DdXV+ZK1Q7hrZYNTyTbq/jizRoA2r9rII504z1 m9Q= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355047" 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; 04 Dec 2019 16:19:37 +0800 IronPort-SDR: aze5q2GJWXlUO8x8HrPFDpVSsH3kW/Dw8ZE0pDBe0gGfdYsx8UrMJaS2sf7RHvu26nYcso5msX AFylg1WquFe7Mq5rMDnZ86MJNzWdO20me1j54iP7Ksyt/uMYWAx/AZjTT4jNL5zGsSEsQbh1ag x1OsTx41qX7aTKP/VwWJz3FZ01vtFZj8ALlrZUqx7QAuXp//Sxos/9Ao0zeXWJVqYVxGBMOHbW pCmhDAS72tqYuLzSRaDwjieB3GGLvf486hr5qILxdFkAfJQnsDgnKqtOkJnVPmOXms3tgLuqEG Vu7VmlIgKv5PPQ51rOkyudYY Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:02 -0800 IronPort-SDR: 9O3kZpe57YeEC7ciHDWOz4yHRhJUjwjU6Vz3bwgWbl8qUZdtNwoB6gZS8VuJUpjQNAzHefedKF oLMQLcPhmgs+XLzaHAtaeS0nL41P6h7BnPv6V4nhOw31NJ6RUY0oIduqW0y7hb0A+B07l5JwQM irBXoFB7F6uF7NbOiz1pjszP6hdglltyO+ZzjSYUtfQBQCeT20uzQjFNT7X0gLKjDynHQLR/5W E38VQqYOyRj5uUcEHvTBYTHRsYkSPQ44T5wpRv9OOG3LoRYdei4nrGgLNixcJDZjYvu3ujqTUK +uU= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:34 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 07/28] btrfs: disable fallocate in HMZONED mode Date: Wed, 4 Dec 2019 17:17:14 +0900 Message-Id: <20191204081735.852438-8-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org fallocate() is implemented by reserving actual extent instead of reservations. This can result in exposing the sequential write constraint of host-managed zoned block devices to the application, which would break the POSIX semantic for the fallocated file. To avoid this, report fallocate() as not supported when in HMZONED mode for now. In the future, we may be able to implement "in-memory" fallocate() in HMZONED mode by utilizing space_info->bytes_may_use or so. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 0cb43b682789..22373d00428b 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3170,6 +3170,10 @@ static long btrfs_fallocate(struct file *file, int mode, alloc_end = round_up(offset + len, blocksize); cur_offset = alloc_start; + /* Do not allow fallocate in HMZONED mode */ + if (btrfs_fs_incompat(btrfs_sb(inode->i_sb), HMZONED)) + return -EOPNOTSUPP; + /* Make sure we aren't being give some crap mode */ if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) From patchwork Wed Dec 4 08:17:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272299 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F0A717EF for ; Wed, 4 Dec 2019 08:19:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDE09206DF for ; Wed, 4 Dec 2019 08:19:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="VPXJcux6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727379AbfLDITo (ORCPT ); Wed, 4 Dec 2019 03:19:44 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32758 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727350AbfLDITj (ORCPT ); Wed, 4 Dec 2019 03:19:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447580; x=1606983580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GmDmouJEcBAkjoHoXOkAiNFj2vkL83uf+AHWFskaApM=; b=VPXJcux6cvmSHCk2QwmQwgYQQ7Ga1n7g8LUKOxzn/PUGmP4JKkttj17V Zh+mjsUC131BmoyPFNHJDofntu7TVbEI4kIvK7WWoHJy8rmSm0Sj3ikKv qLjpm/rivez72pVNFJcBs85QMXVUvJ/CiaA48dQw+bbrP2H23lRK04w++ LW5dHQYmS0LMJ7UgaUBPemwtcLL+mCglGefpwze/mBWHZT5MJGUzjyAME jC70CAw/FGav1H4Jli9tUqDMdqB2Or22+E2VOg3D0qiWTzh/37jXrfXBK CjsXKlu5XMvjRGyvey5WD5Dgx9ftHEiL81DcGf/zvXjKMI5nHGyBrIcyr Q==; IronPort-SDR: p2wqKvnp5O3qM0ArAUJsedU7RJGhNuDy6zByf1h/6QBNFIg+H4h5lLtErmUGnlQw8X3eLJyHfZ 8HVILa79DIFC4VsuJkLmBJ2fI1abjLJwGXJcMJQtPbR3VUhwI+QhqQ4boX7vIJ+ibPD9LEXirO rm61TlLa8NCDVjjpHlzc/E9hNGjysVvIGMPBYHN5cW0z3KqpDoo+00BevUeHOoTcEYqOFMEeXH D6eH+D/4hVenAESFtTpARaZDIBClvfPk8LhDbwkcmAAvwW93domCTZfErpEeDm/Xjw5arQerM5 8fs= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355052" 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; 04 Dec 2019 16:19:39 +0800 IronPort-SDR: cttNUQuWn+qTkihR6DHA8ibEWkBuuEjiRoN4dR+Z1SEI+5G+xXvCPLZU9G7IkUGx6Xhk/PTbZv zL8rwmmMO3TeFGEr+D1b82KWrEOl9ZD+ZWJjbP3kWKtnnSfcBy+YLIF5jEmU3Zu1xpWc9HxQui nmYLqKYB7TG0dZa3c6M2UNlJBX4ISrq6NvXrEcO/Maqcu4qY5P7t9AxQoTHmiTiEp1dgjNblYr sJI9ai75/Y9AWdOIJbmVrUoYg2+5gekDRh4KNigNfMIpAL5Ol4SUZNVk/yeTSAvDDRtC903naM 9yPHhtWqkmYyLq+6PL1Wn9/s Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:04 -0800 IronPort-SDR: /7/V/WviIAEjdR81zpYZ+u0Y/7+a7w1NcyzdXp9FYnxDJjyCjnZtWkkeg7YMIe+ClqfB5Ue65B V17NwbHU3SeWwuhP3MMSobGDZqMYrdW75csDKd+9OyaFsUwwHVeIzAKN4/OjhNjXTEMAt8yKcO 8YLgBTdUXMKpOuFYsCLckyzMbBAaUf/vaRJzg6A4TC4uksNAgyZgB6QoOIoqqEWTCBzOHK+tgB cO76jaPg+tgxrkzNM5CweZc8rn/33EN3/GbIBMXvqlkyDEqvGyoXjBhYSzLleVvlou9ABxPvJy fPs= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:36 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 08/28] btrfs: implement log-structured superblock for HMZONED mode Date: Wed, 4 Dec 2019 17:17:15 +0900 Message-Id: <20191204081735.852438-9-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Superblock (and its copies) is the only data structure in btrfs which has a fixed location on a device. Since we cannot overwrite in a sequential write required zone, we cannot place superblock in the zone. One easy solution is limiting superblock and copies to be placed only in conventional zones. However, this method has two downsides: one is reduced number of superblock copies. The location of the second copy of superblock is 256GB, which is in a sequential write required zone on typical devices in the market today. So, the number of superblock and copies is limited to be two. Second downside is that we cannot support devices which have no conventional zones at all. To solve these two problems, we employ superblock log writing. It uses two zones as a circular buffer to write updated superblocks. Once the first zone is filled up, start writing into the second zone and reset the first one. We can determine the postion of the latest superblock by reading write pointer information from a device. The following zones are reserved as the circular buffer on HMZONED btrfs. - The primary superblock: zones 0 and 1 - The first copy: zones 16 and 17 - The second copy: zones 1024 or zone at 256GB which is minimum, and next to it Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 9 ++ fs/btrfs/disk-io.c | 19 ++- fs/btrfs/hmzoned.c | 276 +++++++++++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 40 ++++++ fs/btrfs/scrub.c | 3 + fs/btrfs/volumes.c | 18 ++- 6 files changed, 354 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 6934a5b8708f..acfa0a9d3c5a 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1519,6 +1519,7 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) static int exclude_super_stripes(struct btrfs_block_group *cache) { struct btrfs_fs_info *fs_info = cache->fs_info; + bool hmzoned = btrfs_fs_incompat(fs_info, HMZONED); u64 bytenr; u64 *logical; int stripe_len; @@ -1549,6 +1550,14 @@ static int exclude_super_stripes(struct btrfs_block_group *cache) if (logical[nr] + stripe_len <= cache->start) continue; + /* shouldn't have super stripes in sequential zones */ + if (hmzoned) { + btrfs_err(fs_info, + "sequentil allocation bg %llu should not have super blocks", + cache->start); + return -EUCLEAN; + } + start = logical[nr]; if (start < cache->start) { start = cache->start; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index ff418e393f82..deca9fd70771 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3386,8 +3386,12 @@ int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num, struct buffer_head *bh; struct btrfs_super_block *super; u64 bytenr; + u64 bytenr_orig; + + bytenr_orig = btrfs_sb_offset(copy_num); + if (btrfs_sb_log_location_bdev(bdev, copy_num, READ, &bytenr)) + return -EUCLEAN; - bytenr = btrfs_sb_offset(copy_num); if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode)) return -EINVAL; @@ -3400,7 +3404,7 @@ int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num, return -EIO; super = (struct btrfs_super_block *)bh->b_data; - if (btrfs_super_bytenr(super) != bytenr || + if (btrfs_super_bytenr(super) != bytenr_orig || btrfs_super_magic(super) != BTRFS_MAGIC) { brelse(bh); return -EINVAL; @@ -3466,7 +3470,7 @@ static int write_dev_supers(struct btrfs_device *device, int i; int ret; int errors = 0; - u64 bytenr; + u64 bytenr, bytenr_orig; int op_flags; if (max_mirrors == 0) @@ -3475,12 +3479,13 @@ static int write_dev_supers(struct btrfs_device *device, shash->tfm = fs_info->csum_shash; for (i = 0; i < max_mirrors; i++) { - bytenr = btrfs_sb_offset(i); + bytenr_orig = btrfs_sb_offset(i); + bytenr = btrfs_sb_log_location(device, i, WRITE); if (bytenr + BTRFS_SUPER_INFO_SIZE >= device->commit_total_bytes) break; - btrfs_set_super_bytenr(sb, bytenr); + btrfs_set_super_bytenr(sb, bytenr_orig); crypto_shash_init(shash); crypto_shash_update(shash, (const char *)sb + BTRFS_CSUM_SIZE, @@ -3518,6 +3523,8 @@ static int write_dev_supers(struct btrfs_device *device, ret = btrfsic_submit_bh(REQ_OP_WRITE, op_flags, bh); if (ret) errors++; + else if (btrfs_advance_sb_log(device, i)) + errors++; } return errors < i ? 0 : -1; } @@ -3541,7 +3548,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors) max_mirrors = BTRFS_SUPER_MIRROR_MAX; for (i = 0; i < max_mirrors; i++) { - bytenr = btrfs_sb_offset(i); + bytenr = btrfs_sb_log_location(device, i, READ); if (bytenr + BTRFS_SUPER_INFO_SIZE >= device->commit_total_bytes) break; diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index e890d2ab8cd9..599c493f44b0 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -16,6 +16,26 @@ /* Maximum number of zones to report per blkdev_report_zones() call */ #define BTRFS_REPORT_NR_ZONES 4096 +static int sb_write_pointer(struct blk_zone *zone, u64 *wp_ret); + +static inline u32 sb_zone_number(u64 zone_size, int mirror) +{ + ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX); + + switch (mirror) { + case 0: + return 0; + case 1: + return 16; + case 2: + return min(btrfs_sb_offset(mirror) / zone_size, 1024ULL); + default: + BUG(); + } + + return 0; +} + static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos, struct blk_zone *zones, unsigned int *nr_zones) { @@ -115,6 +135,39 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) goto free_zones; } + nr_zones = 2; + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { + u32 sb_zone = sb_zone_number(zone_info->zone_size, i); + u64 sb_wp; + + if (sb_zone + 1 >= zone_info->nr_zones) + continue; + + sector = sb_zone << (zone_info->zone_size_shift - SECTOR_SHIFT); + ret = btrfs_get_dev_zones(device, sector << SECTOR_SHIFT, + &zone_info->sb_zones[2 * i], + &nr_zones); + if (ret) + goto free_zones; + if (nr_zones != 2) { + btrfs_err_in_rcu(device->fs_info, + "failed to read SB log zone info at device %s zone %u", + rcu_str_deref(device->name), sb_zone); + ret = -EIO; + goto free_zones; + } + + ret = sb_write_pointer(&zone_info->sb_zones[2 * i], &sb_wp); + if (ret != -ENOENT && ret) { + btrfs_err_in_rcu(device->fs_info, + "SB log zone corrupted: device %s zone %u", + rcu_str_deref(device->name), sb_zone); + ret = -EUCLEAN; + goto free_zones; + } + } + + kfree(zones); device->zone_info = zone_info; @@ -277,3 +330,226 @@ int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info) return 0; } + +static int sb_write_pointer(struct blk_zone *zones, u64 *wp_ret) +{ + bool empty[2]; + bool full[2]; + sector_t sector; + + if (zones[0].type == BLK_ZONE_TYPE_CONVENTIONAL) { + *wp_ret = zones[0].start << SECTOR_SHIFT; + return -ENOENT; + } + + empty[0] = zones[0].cond == BLK_ZONE_COND_EMPTY; + empty[1] = zones[1].cond == BLK_ZONE_COND_EMPTY; + full[0] = zones[0].cond == BLK_ZONE_COND_FULL; + full[1] = zones[1].cond == BLK_ZONE_COND_FULL; + + /* + * Possible state of log buffer zones + * + * E I F + * E * x 0 + * I 0 x 0 + * F 1 1 x + * + * Row: zones[0] + * Col: zones[1] + * State: + * E: Empty, I: In-Use, F: Full + * Log position: + * *: Special case, no superblock is written + * 0: Use write pointer of zones[0] + * 1: Use write pointer of zones[1] + * x: Invalid state + */ + + if (empty[0] && empty[1]) { + /* special case to distinguish no superblock to read */ + *wp_ret = zones[0].start << SECTOR_SHIFT; + return -ENOENT; + } else if (full[0] && full[1]) { + /* cannot determine which zone has the newer superblock */ + return -EUCLEAN; + } else if (!full[0] && (empty[1] || full[1])) { + sector = zones[0].wp; + } else if (full[0]) { + sector = zones[1].wp; + } else { + return -EUCLEAN; + } + *wp_ret = sector << SECTOR_SHIFT; + return 0; +} + +int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, + u64 *bytenr_ret) +{ + struct blk_zone zones[2]; + unsigned int nr_zones_rep = 2; + unsigned int zone_sectors; + u32 sb_zone; + int ret; + u64 wp; + u64 zone_size; + u8 zone_sectors_shift; + sector_t nr_sectors = bdev->bd_part->nr_sects; + u32 nr_zones; + + if (!bdev_is_zoned(bdev)) { + *bytenr_ret = btrfs_sb_offset(mirror); + return 0; + } + + ASSERT(rw == READ || rw == WRITE); + + zone_sectors = bdev_zone_sectors(bdev); + if (!is_power_of_2(zone_sectors)) + return -EINVAL; + zone_size = zone_sectors << SECTOR_SHIFT; + zone_sectors_shift = ilog2(zone_sectors); + nr_zones = nr_sectors >> zone_sectors_shift; + + sb_zone = sb_zone_number(zone_size, mirror); + if (sb_zone + 1 >= nr_zones) + return -ENOENT; + + ret = blkdev_report_zones(bdev, sb_zone << zone_sectors_shift, zones, + &nr_zones_rep); + if (ret) + return ret; + if (nr_zones_rep != 2) + return -EIO; + + ret = sb_write_pointer(zones, &wp); + if (ret != -ENOENT && ret) + return -EUCLEAN; + + if (rw == READ && ret != -ENOENT) { + if (wp == zones[0].start << SECTOR_SHIFT) + wp = (zones[1].start + zones[1].len) << SECTOR_SHIFT; + wp -= BTRFS_SUPER_INFO_SIZE; + } + *bytenr_ret = wp; + + return 0; +} + +u64 btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw) +{ + struct btrfs_zoned_device_info *zinfo = device->zone_info; + u64 base, wp; + u32 zone_num; + int ret; + + if (!zinfo) + return btrfs_sb_offset(mirror); + + zone_num = sb_zone_number(zinfo->zone_size, mirror); + if (zone_num + 1 >= zinfo->nr_zones) + return U64_MAX - BTRFS_SUPER_INFO_SIZE; + + base = (u64)zone_num << zinfo->zone_size_shift; + if (!test_bit(zone_num, zinfo->seq_zones)) + return base; + + /* sb_zones should be kept valid during runtime */ + ret = sb_write_pointer(&zinfo->sb_zones[2 * mirror], &wp); + if (ret != -ENOENT && ret) + return U64_MAX - BTRFS_SUPER_INFO_SIZE; + if (rw == WRITE || ret == -ENOENT) + return wp; + if (wp == base) + wp = base + zinfo->zone_size * 2; + return wp - BTRFS_SUPER_INFO_SIZE; +} + +static inline bool is_sb_log_zone(struct btrfs_zoned_device_info *zinfo, + int mirror) +{ + u32 zone_num; + + if (!zinfo) + return false; + + zone_num = sb_zone_number(zinfo->zone_size, mirror); + if (zone_num + 1 >= zinfo->nr_zones) + return false; + + if (!test_bit(zone_num, zinfo->seq_zones)) + return false; + + return true; +} + +int btrfs_advance_sb_log(struct btrfs_device *device, int mirror) +{ + struct btrfs_zoned_device_info *zinfo = device->zone_info; + struct blk_zone *zone; + struct blk_zone *reset = NULL; + int ret; + + if (!is_sb_log_zone(zinfo, mirror)) + return 0; + + zone = &zinfo->sb_zones[2 * mirror]; + if (zone->cond != BLK_ZONE_COND_FULL) { + if (zone->cond == BLK_ZONE_COND_EMPTY) + zone->cond = BLK_ZONE_COND_IMP_OPEN; + zone->wp += (BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT); + if (zone->wp == zone->start + zone->len) { + zone->cond = BLK_ZONE_COND_FULL; + reset = zone + 1; + goto reset; + } + return 0; + } + + zone++; + ASSERT(zone->cond != BLK_ZONE_COND_FULL); + if (zone->cond == BLK_ZONE_COND_EMPTY) + zone->cond = BLK_ZONE_COND_IMP_OPEN; + zone->wp += (BTRFS_SUPER_INFO_SIZE >> SECTOR_SHIFT); + if (zone->wp == zone->start + zone->len) { + zone->cond = BLK_ZONE_COND_FULL; + reset = zone - 1; + } + +reset: + if (!reset || reset->cond == BLK_ZONE_COND_EMPTY) + return 0; + + ASSERT(reset->cond == BLK_ZONE_COND_FULL); + + ret = blkdev_reset_zones(device->bdev, reset->start, reset->len, + GFP_NOFS); + if (!ret) { + reset->cond = BLK_ZONE_COND_EMPTY; + reset->wp = reset->start; + } + return ret; +} + +int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) +{ + sector_t zone_sectors; + sector_t nr_sectors = bdev->bd_part->nr_sects; + u8 zone_sectors_shift; + u32 sb_zone; + u32 nr_zones; + + zone_sectors = bdev_zone_sectors(bdev); + zone_sectors_shift = ilog2(zone_sectors); + nr_zones = nr_sectors >> zone_sectors_shift; + + sb_zone = sb_zone_number(zone_sectors << SECTOR_SHIFT, mirror); + if (sb_zone + 1 >= nr_zones) + return -ENOENT; + + return blkdev_reset_zones(bdev, + sb_zone << zone_sectors_shift, + zone_sectors * 2, + GFP_NOFS); +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index d9ebe11afdf5..55041a26ae3c 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -10,6 +10,8 @@ #define BTRFS_HMZONED_H #include +#include "volumes.h" +#include "disk-io.h" struct btrfs_zoned_device_info { /* @@ -21,6 +23,7 @@ struct btrfs_zoned_device_info { u32 nr_zones; unsigned long *seq_zones; unsigned long *empty_zones; + struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX]; }; #ifdef CONFIG_BLK_DEV_ZONED @@ -30,6 +33,11 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device); void btrfs_destroy_dev_zone_info(struct btrfs_device *device); int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info); int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info); +int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, + u64 *bytenr_ret); +u64 btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw); +int btrfs_advance_sb_log(struct btrfs_device *device, int mirror); +int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -53,6 +61,27 @@ static inline int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info) { return 0; } +static inline int btrfs_sb_log_location_bdev(struct block_device *bdev, + int mirror, int rw, + u64 *bytenr_ret) +{ + *bytenr_ret = btrfs_sb_offset(mirror); + return 0; +} +static inline u64 btrfs_sb_log_location(struct btrfs_device *device, int mirror, + int rw) +{ + return btrfs_sb_offset(mirror); +} +static inline int btrfs_advance_sb_log(struct btrfs_device *device, int mirror) +{ + return 0; +} +static inline int btrfs_reset_sb_log_zones(struct block_device *bdev, + int mirror) +{ + return 0; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) @@ -120,4 +149,15 @@ static inline bool btrfs_check_device_zone_type(struct btrfs_fs_info *fs_info, return bdev_zoned_model(bdev) != BLK_ZONED_HM; } +static inline bool btrfs_check_super_location(struct btrfs_device *device, + u64 pos) +{ + /* + * On a non-zoned device, any address is OK. On a zoned + * device, non-SEQUENTIAL WRITE REQUIRED zones are capable. + */ + return device->zone_info == NULL || + !btrfs_dev_is_sequential(device, pos); +} + #endif diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 21de630b0730..af7cec962619 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -19,6 +19,7 @@ #include "rcu-string.h" #include "raid56.h" #include "block-group.h" +#include "hmzoned.h" /* * This is only the first step towards a full-features scrub. It reads all @@ -3709,6 +3710,8 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx, if (bytenr + BTRFS_SUPER_INFO_SIZE > scrub_dev->commit_total_bytes) break; + if (!btrfs_check_super_location(scrub_dev, bytenr)) + continue; ret = scrub_pages(sctx, bytenr, BTRFS_SUPER_INFO_SIZE, bytenr, scrub_dev, BTRFS_EXTENT_FLAG_SUPER, gen, i, diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ab3590b310af..a260648cecca 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1218,12 +1218,17 @@ static void btrfs_release_disk_super(struct page *page) put_page(page); } -static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, +static int btrfs_read_disk_super(struct block_device *bdev, int mirror, struct page **page, struct btrfs_super_block **disk_super) { void *p; pgoff_t index; + u64 bytenr; + u64 bytenr_orig = btrfs_sb_offset(mirror); + + if (btrfs_sb_log_location_bdev(bdev, 0, READ, &bytenr)) + return 1; /* make sure our super fits in the device */ if (bytenr + PAGE_SIZE >= i_size_read(bdev->bd_inode)) @@ -1250,7 +1255,7 @@ static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr, /* align our pointer to the offset of the super block */ *disk_super = p + offset_in_page(bytenr); - if (btrfs_super_bytenr(*disk_super) != bytenr || + if (btrfs_super_bytenr(*disk_super) != bytenr_orig || btrfs_super_magic(*disk_super) != BTRFS_MAGIC) { btrfs_release_disk_super(*page); return 1; @@ -1287,7 +1292,6 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags, struct btrfs_device *device = NULL; struct block_device *bdev; struct page *page; - u64 bytenr; lockdep_assert_held(&uuid_mutex); @@ -1297,14 +1301,13 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags, * So, we need to add a special mount option to scan for * later supers, using BTRFS_SUPER_MIRROR_MAX instead */ - bytenr = btrfs_sb_offset(0); flags |= FMODE_EXCL; bdev = blkdev_get_by_path(path, flags, holder); if (IS_ERR(bdev)) return ERR_CAST(bdev); - if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) { + if (btrfs_read_disk_super(bdev, 0, &page, &disk_super)) { device = ERR_PTR(-EINVAL); goto error_bdev_put; } @@ -7371,6 +7374,11 @@ void btrfs_scratch_superblocks(struct block_device *bdev, const char *device_pat if (btrfs_read_dev_one_super(bdev, copy_num, &bh)) continue; + if (bdev_is_zoned(bdev)) { + btrfs_reset_sb_log_zones(bdev, copy_num); + continue; + } + disk_super = (struct btrfs_super_block *)bh->b_data; memset(&disk_super->magic, 0, sizeof(disk_super->magic)); From patchwork Wed Dec 4 08:17:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272305 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2398F6C1 for ; Wed, 4 Dec 2019 08:19:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED3582068E for ; Wed, 4 Dec 2019 08:19:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="iib5ezi/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbfLDITo (ORCPT ); Wed, 4 Dec 2019 03:19:44 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32758 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727200AbfLDITm (ORCPT ); Wed, 4 Dec 2019 03:19:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447582; x=1606983582; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Scgk1UGcHjVUcY8q8+HTOzN6mjROoby6LofxBATJgk0=; b=iib5ezi/V2/FA5Q1arlbVXLciTmdy6ONg0He3/cacniAJSc9GY8+pqyI yjCf20IjGCf7zEbTsdKbdV0bfi7V2MPFS1xNWsVPUu4uBee813nnm06N3 ywPyBVCCvkeGy1qKKv7lNLKKG+jio+x1+dl02D5ar1VzS7WbDJR8xJuox NnwXmITjI/WdUAv9EoeuZf+zok7EKCzOvAOm0AgTiw4TAlJP82ufXR+xK RHlQx6+l0unz5nVIH3tmA6+hT2H7wgHGiHXre44ZJ9O8DYupYKKHb2FIi YGXQxG6241W7pGDghqNufGQ9EuzvxWKqwle2k4x1gDoMBdaYcBkGiDQDv Q==; IronPort-SDR: 55wiYCs0sRIdMiuCOmPkW1kfg7u0MSjskskzIuuHth+ReBYsAcl1iG/wnieqgpw9QvKXUXqcQM LkQOcWmX+KmgvkXNxiytladakjAiLCqcWccar9gjh7c/IyOeUIWaCu5S9xl25EBvIVYanhNQvn ALnfx2ybL+tmPwvOb9ikTZ6axarLXXPbfBRPnQaFJ3SZu22/tpoEy1/EaQVr7JQNBrHXSssXKb 10MrAirYi08ikYq90Hb8KiyNlsSFZFfrawaPZCIsWH83XH+W4tPntrBUGzFQxQLVv9qxijUH1b OwI= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355055" 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; 04 Dec 2019 16:19:42 +0800 IronPort-SDR: nPHcUXaiNb9vMuQ4/7yqnusDwKX3DhAHQpml9CykAzBKldL32qavlJ9rCqqYZ64rSmoK4dGN2P yL3KUAlG4dnxgNi2COUzcqvYzDVHqDLZEDkEHyK4wFq+0rqCNqHcrEbnLK7zkQNsJ+/mCYyqq7 Z/LtVmGOojx0PDm7tWIqPE1kjE+wkT4WeLEQ0Nw0nvTexZCu8ozphLJfxKyEzEKfPgf1cHdDbO 1+8Ge01h9hwNnSzvmecJhNBqW8lq3N/LR/I5URc1+1QR/3dXGsGcsyxfKfymkaGTH/wW9beH+k sB9okT76AqL5RSpZht0ZS1E8 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:07 -0800 IronPort-SDR: FDmbYRKd+IEix9ZsQbMmRdkPhSdKYvmk4BT8bk/BVdccS/X7GoPeZX6BZwvJhArauHhK+mxMef KI39QZCQXcW8YqMAEJYqqK22iEuqvn+xxAkoDbMwQ5sUbMNUa6CX39T0LhnFoOnfdHNqGY43gW CVdY9kg+oe8l16gaxvGfqybl5jSBwYxOYakGkmOw8Y0yrIg78/sdlX7Gb9fySEojq/45VnL2bT 02GqI2QvZAP+sRkH7+ZVfLV+nX/z5BPbaC8S4NBUKoRmpBg4AFHeVY/E44g7dSOL7yydyh8ZRi U54= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:39 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 09/28] btrfs: align device extent allocation to zone boundary Date: Wed, 4 Dec 2019 17:17:16 +0900 Message-Id: <20191204081735.852438-10-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In HMZONED mode, align the device extents to zone boundaries so that a zone reset affects only the device extent and does not change the state of blocks in the neighbor device extents. Also, check that a region allocation is always over empty zones and it is not over any locations of super block zones. This patch also add a verification in verify_one_dev_extent() to check if the device extent is align to zone boundary. Signed-off-by: Naohiro Aota --- fs/btrfs/hmzoned.c | 55 +++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 15 +++++++++ fs/btrfs/volumes.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 599c493f44b0..9a814ad1b0a5 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -12,6 +12,7 @@ #include "volumes.h" #include "hmzoned.h" #include "rcu-string.h" +#include "disk-io.h" /* Maximum number of zones to report per blkdev_report_zones() call */ #define BTRFS_REPORT_NR_ZONES 4096 @@ -553,3 +554,57 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) zone_sectors * 2, GFP_NOFS); } + +/* + * btrfs_check_allocatable_zones - check if spcecifeid region is + * suitable for allocation + * @device: the device to allocate a region + * @pos: the position of the region + * @num_bytes: the size of the region + * + * In non-ZONED device, anywhere is suitable for allocation. In ZONED + * device, check if + * 1) the region is not on non-empty sequential zones, + * 2) all zones in the region have the same zone type, + * 3) it does not contain super block location. + */ +bool btrfs_check_allocatable_zones(struct btrfs_device *device, u64 pos, + u64 num_bytes) +{ + struct btrfs_zoned_device_info *zinfo = device->zone_info; + u64 nzones, begin, end; + u64 sb_pos; + u8 shift; + int i; + + if (!zinfo) + return true; + + shift = zinfo->zone_size_shift; + nzones = num_bytes >> shift; + begin = pos >> shift; + end = begin + nzones; + + ASSERT(IS_ALIGNED(pos, zinfo->zone_size)); + ASSERT(IS_ALIGNED(num_bytes, zinfo->zone_size)); + + if (end > zinfo->nr_zones) + return false; + + /* check if zones in the region are all empty */ + if (btrfs_dev_is_sequential(device, pos) && + find_next_zero_bit(zinfo->empty_zones, end, begin) != end) + return false; + + if (btrfs_dev_is_sequential(device, pos)) { + for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { + sb_pos = sb_zone_number(zinfo->zone_size, i); + if (!(end < sb_pos || sb_pos + 1 < begin)) + return false; + } + + return find_next_zero_bit(zinfo->seq_zones, end, begin) == end; + } + + return find_next_bit(zinfo->seq_zones, end, begin) == end; +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index 55041a26ae3c..d54b4ae8cf8b 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -38,6 +38,8 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, u64 btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw); int btrfs_advance_sb_log(struct btrfs_device *device, int mirror); int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror); +bool btrfs_check_allocatable_zones(struct btrfs_device *device, u64 pos, + u64 num_bytes); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -82,6 +84,11 @@ static inline int btrfs_reset_sb_log_zones(struct block_device *bdev, { return 0; } +static inline bool btrfs_check_allocatable_zones(struct btrfs_device *device, + u64 pos, u64 num_bytes) +{ + return true; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) @@ -160,4 +167,12 @@ static inline bool btrfs_check_super_location(struct btrfs_device *device, !btrfs_dev_is_sequential(device, pos); } +static inline u64 btrfs_zone_align(struct btrfs_device *device, u64 pos) +{ + if (!device->zone_info) + return pos; + + return ALIGN(pos, device->zone_info->zone_size); +} + #endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a260648cecca..d058ea613627 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1393,6 +1393,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device, u64 max_hole_size; u64 extent_end; u64 search_end = device->total_bytes; + u64 zone_size = 0; int ret; int slot; struct extent_buffer *l; @@ -1403,6 +1404,14 @@ static int find_free_dev_extent_start(struct btrfs_device *device, * at an offset of at least 1MB. */ search_start = max_t(u64, search_start, SZ_1M); + /* + * For a zoned block device, skip the first zone of the device + * entirely. + */ + if (device->zone_info) + zone_size = device->zone_info->zone_size; + search_start = max_t(u64, search_start, zone_size); + search_start = btrfs_zone_align(device, search_start); path = btrfs_alloc_path(); if (!path) @@ -1467,12 +1476,21 @@ static int find_free_dev_extent_start(struct btrfs_device *device, */ if (contains_pending_extent(device, &search_start, hole_size)) { + search_start = btrfs_zone_align(device, + search_start); if (key.offset >= search_start) hole_size = key.offset - search_start; else hole_size = 0; } + if (!btrfs_check_allocatable_zones(device, search_start, + num_bytes)) { + search_start += zone_size; + btrfs_release_path(path); + goto again; + } + if (hole_size > max_hole_size) { max_hole_start = search_start; max_hole_size = hole_size; @@ -1512,6 +1530,14 @@ static int find_free_dev_extent_start(struct btrfs_device *device, hole_size = search_end - search_start; if (contains_pending_extent(device, &search_start, hole_size)) { + search_start = btrfs_zone_align(device, search_start); + btrfs_release_path(path); + goto again; + } + + if (!btrfs_check_allocatable_zones(device, search_start, + num_bytes)) { + search_start += zone_size; btrfs_release_path(path); goto again; } @@ -1529,6 +1555,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device, ret = 0; out: + ASSERT(zone_size == 0 || IS_ALIGNED(max_hole_start, zone_size)); btrfs_free_path(path); *start = max_hole_start; if (len) @@ -4778,6 +4805,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, int i; int j; int index; + int hmzoned = btrfs_fs_incompat(info, HMZONED); BUG_ON(!alloc_profile_is_valid(type, 0)); @@ -4819,10 +4847,25 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, BUG(); } + if (hmzoned) { + max_stripe_size = info->zone_size; + max_chunk_size = round_down(max_chunk_size, info->zone_size); + } + /* We don't want a chunk larger than 10% of writable space */ max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), max_chunk_size); + if (hmzoned) { + int min_num_stripes = devs_min * dev_stripes; + int min_data_stripes = (min_num_stripes - nparity) / ncopies; + u64 min_chunk_size = min_data_stripes * info->zone_size; + + max_chunk_size = max(round_down(max_chunk_size, + info->zone_size), + min_chunk_size); + } + devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), GFP_NOFS); if (!devices_info) @@ -4857,6 +4900,9 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (total_avail == 0) continue; + if (hmzoned && total_avail < max_stripe_size * dev_stripes) + continue; + ret = find_free_dev_extent(device, max_stripe_size * dev_stripes, &dev_offset, &max_avail); @@ -4875,6 +4921,9 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, continue; } + if (hmzoned && max_avail < max_stripe_size * dev_stripes) + continue; + if (ndevs == fs_devices->rw_devices) { WARN(1, "%s: found more than %llu devices\n", __func__, fs_devices->rw_devices); @@ -4893,6 +4942,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, sort(devices_info, ndevs, sizeof(struct btrfs_device_info), btrfs_cmp_device_info, NULL); +again: /* * Round down to number of usable stripes, devs_increment can be any * number so we can't use round_down() @@ -4934,6 +4984,17 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, * we try to reduce stripe_size. */ if (stripe_size * data_stripes > max_chunk_size) { + if (hmzoned) { + /* + * stripe_size is fixed in HMZONED. Reduce ndevs + * instead. + */ + ASSERT(nparity == 0); + ndevs = div_u64(max_chunk_size * ncopies, + stripe_size * dev_stripes); + goto again; + } + /* * Reduce stripe_size, round it up to a 16MB boundary again and * then use it, unless it ends up being even bigger than the @@ -4947,6 +5008,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, /* align to BTRFS_STRIPE_LEN */ stripe_size = round_down(stripe_size, BTRFS_STRIPE_LEN); + ASSERT(!hmzoned || stripe_size == info->zone_size); + map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS); if (!map) { ret = -ENOMEM; @@ -7541,6 +7604,20 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, ret = -EUCLEAN; goto out; } + + if (dev->zone_info) { + u64 zone_size = dev->zone_info->zone_size; + + if (!IS_ALIGNED(physical_offset, zone_size) || + !IS_ALIGNED(physical_len, zone_size)) { + btrfs_err(fs_info, +"dev extent devid %llu physical offset %llu len %llu is not aligned to device zone", + devid, physical_offset, physical_len); + ret = -EUCLEAN; + goto out; + } + } + out: free_extent_map(em); return ret; From patchwork Wed Dec 4 08:17:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272301 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E26386C1 for ; Wed, 4 Dec 2019 08:19:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C4882068E for ; Wed, 4 Dec 2019 08:19:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Iu1wTLUA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727387AbfLDITp (ORCPT ); Wed, 4 Dec 2019 03:19:45 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32758 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727370AbfLDITp (ORCPT ); Wed, 4 Dec 2019 03:19:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447585; x=1606983585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W6PBvVuXwoUjtawPENVTKkCpmlMoxvlFbGYtT8qskvg=; b=Iu1wTLUAKeUybnkCuNbFWMzjbVvouiRsHzBmgDi47R2khy9rTEnpdwAO 2C67d0Inc+fIE2F5mM6l2TUk6/6jjaq2Nycp7vxAKODBNjktikSs+hjmA zQfGjDVppgGXzhmgOmvKJdYBMme44pgHr2FUmYMBGMHvS/GMvJbmmtNIl LdcK9V3X+b+6DbdD/WCaemf2ow4kPJrUSma3dM3NGDIdvwXRZNuQRAuXe Daw09vJ754PyTz4D+yva1lpy5f97m5tlECmUZKtH0gE0L16OgsdNVYFmA wVbxpIjPl3wBFohftRdOK5WXdcreWaOhfN14D0rrUfhlnTyjKDX+3Sgk6 g==; IronPort-SDR: A+ulPKOmHNqS1r0Jyx3iKJohafYWB59y4lJcGffjDZkzOW8G0jwFKuF/RYbKtpmdKocWEE3HVx liQ/bb7aedDZqgFP34OMB/toPsAyNVbLAXLqEREoVMgyBKN5yOgRvBdr0MIpeIudHEyEA2qg91 ZXVM9Z6K3jN61olYjc3OjY7qmAcokpCo15BpKaUW6EfAcHysnFj0PblArWkl47GMHJ48X9KdD0 gK+hhrYzd/ORyZSlS8z/4x/OArfycl+tMhn013C//bwBgX78T/W50Tj3U2lbUNZn36YVL+mqXj 55U= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355062" 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; 04 Dec 2019 16:19:44 +0800 IronPort-SDR: l4N3cv2K5z5CAAutAcp+BavI9MewEXNEINzcCXHpSpONkTF3Su6mg5auQgeUuWiA50E6RikiwP /hi1/700py3q1DS0ZV58deG7EfUDLDBjMW1acR/H+ny2Cq06tZSMzPLCW+EurkdPvdZBb71on4 r7KpB/4+OTX1AZnc3zFW4gNCBe8HdWiAcgzhWzQ0zNQkXP/gZvO3yjLFLhO/9gpmGTks2mNjid qe5Edj0mhR0OwVhiDoUoF4ArkEChqfWGYg0eOrX5P+4ZCriRQLB5QWg6MDxYNZh3C10STHfVBZ GfLtvoh4+xCez3ZePu5DSc+4 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:09 -0800 IronPort-SDR: gW7EBkcJSUXRx19kDF7dWCBES8GUsLVqZOK9dthhzOzwdQ4ZKsfPaM+CX/p4AWtq61m0zi640O MlRlQOSmW9CZ0bm59HLPC2cftry9Ery80CFHcg2P66T1BWY8TXnAojUJjSSA2qEMtCS7UgpCP9 918cdCd+P3LSLj07T0bLMbyfv/HxB/VwsleZotXBC29Ger/ySMHGt2F70YTNnza8lnYhDOY5hn k6h0HVjsMKbB8N6SKbTHMFKsOGZNWxLv5vhuHpS62kptseNjp93qOPCNbqh96A4TnY5EmfwOtq G5E= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:41 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 10/28] btrfs: do sequential extent allocation in HMZONED mode Date: Wed, 4 Dec 2019 17:17:17 +0900 Message-Id: <20191204081735.852438-11-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On HMZONED drives, writes must always be sequential and directed at a block group zone write pointer position. Thus, block allocation in a block group must also be done sequentially using an allocation pointer equal to the block group zone write pointer plus the number of blocks allocated but not yet written. Sequential allocation function find_free_extent_zoned() bypass the checks in find_free_extent() and increase the reserved byte counter by itself. It is impossible to revert once allocated region in the sequential allocation, since it might race with other allocations and leave an allocation hole, which breaks the sequential write rule. Furthermore, this commit introduce two new variable to struct btrfs_block_group. "wp_broken" indicate that write pointer is broken (e.g. not synced on a RAID1 block group) and mark that block group read only. "zone_unusable" keeps track of the size of once allocated then freed region in a block group. Such region is never usable until resetting underlying zones. This commit also introduce "bytes_zone_unusable" to track such unusable bytes in a space_info. Pinned bytes are always reclaimed to "bytes_zone_unusable". They are not usable until resetting them first. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 74 ++++-- fs/btrfs/block-group.h | 11 + fs/btrfs/extent-tree.c | 80 +++++- fs/btrfs/free-space-cache.c | 38 +++ fs/btrfs/free-space-cache.h | 2 + fs/btrfs/hmzoned.c | 467 ++++++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 8 + fs/btrfs/space-info.c | 13 +- fs/btrfs/space-info.h | 4 +- fs/btrfs/sysfs.c | 2 + 10 files changed, 672 insertions(+), 27 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index acfa0a9d3c5a..5c04422f6f5a 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -14,6 +14,7 @@ #include "sysfs.h" #include "tree-log.h" #include "delalloc-space.h" +#include "hmzoned.h" /* * Return target flags in extended format or 0 if restripe for this chunk_type @@ -677,6 +678,9 @@ int btrfs_cache_block_group(struct btrfs_block_group *cache, int load_cache_only struct btrfs_caching_control *caching_ctl; int ret = 0; + if (btrfs_fs_incompat(fs_info, HMZONED)) + return 0; + caching_ctl = kzalloc(sizeof(*caching_ctl), GFP_NOFS); if (!caching_ctl) return -ENOMEM; @@ -1048,12 +1052,15 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, WARN_ON(block_group->space_info->total_bytes < block_group->length); WARN_ON(block_group->space_info->bytes_readonly - < block_group->length); + < block_group->length - block_group->zone_unusable); + WARN_ON(block_group->space_info->bytes_zone_unusable + < block_group->zone_unusable); WARN_ON(block_group->space_info->disk_total < block_group->length * factor); } block_group->space_info->total_bytes -= block_group->length; - block_group->space_info->bytes_readonly -= block_group->length; + block_group->space_info->bytes_readonly -= + (block_group->length - block_group->zone_unusable); block_group->space_info->disk_total -= block_group->length * factor; spin_unlock(&block_group->space_info->lock); @@ -1210,7 +1217,7 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force) } num_bytes = cache->length - cache->reserved - cache->pinned - - cache->bytes_super - cache->used; + cache->bytes_super - cache->zone_unusable - cache->used; sinfo_used = btrfs_space_info_used(sinfo, true); /* @@ -1736,6 +1743,13 @@ static int read_one_block_group(struct btrfs_fs_info *info, goto error; } + ret = btrfs_load_block_group_zone_info(cache); + if (ret) { + btrfs_err(info, "failed to load zone info of bg %llu", + cache->start); + goto error; + } + /* * We need to exclude the super stripes now so that the space info has * super bytes accounted for, otherwise we'll think we have more space @@ -1766,6 +1780,8 @@ static int read_one_block_group(struct btrfs_fs_info *info, btrfs_free_excluded_extents(cache); } + btrfs_calc_zone_unusable(cache); + ret = btrfs_add_block_group_cache(info, cache); if (ret) { btrfs_remove_free_space_cache(cache); @@ -1773,7 +1789,8 @@ static int read_one_block_group(struct btrfs_fs_info *info, } trace_btrfs_add_block_group(info, cache, 0); btrfs_update_space_info(info, cache->flags, key->offset, - cache->used, cache->bytes_super, &space_info); + cache->used, cache->bytes_super, + cache->zone_unusable, &space_info); cache->space_info = space_info; @@ -1786,6 +1803,10 @@ static int read_one_block_group(struct btrfs_fs_info *info, ASSERT(list_empty(&cache->bg_list)); btrfs_mark_bg_unused(cache); } + + if (cache->wp_broken) + inc_block_group_ro(cache, 1); + return 0; error: btrfs_put_block_group(cache); @@ -1924,6 +1945,13 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, u64 bytes_used, cache->last_byte_to_unpin = (u64)-1; cache->cached = BTRFS_CACHE_FINISHED; cache->needs_free_space = 1; + + ret = btrfs_load_block_group_zone_info(cache); + if (ret) { + btrfs_put_block_group(cache); + return ret; + } + ret = exclude_super_stripes(cache); if (ret) { /* We may have excluded something, so call this just in case */ @@ -1965,7 +1993,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, u64 bytes_used, */ trace_btrfs_add_block_group(fs_info, cache, 1); btrfs_update_space_info(fs_info, cache->flags, size, bytes_used, - cache->bytes_super, &cache->space_info); + cache->bytes_super, 0, &cache->space_info); btrfs_update_global_block_rsv(fs_info); link_block_group(cache); @@ -2121,7 +2149,8 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group *cache) spin_lock(&cache->lock); if (!--cache->ro) { num_bytes = cache->length - cache->reserved - - cache->pinned - cache->bytes_super - cache->used; + cache->pinned - cache->bytes_super - + cache->zone_unusable - cache->used; sinfo->bytes_readonly -= num_bytes; list_del_init(&cache->ro_list); } @@ -2760,6 +2789,21 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, return ret; } +void __btrfs_add_reserved_bytes(struct btrfs_block_group *cache, u64 ram_bytes, + u64 num_bytes, int delalloc) +{ + struct btrfs_space_info *space_info = cache->space_info; + + cache->reserved += num_bytes; + space_info->bytes_reserved += num_bytes; + trace_btrfs_space_reservation(cache->fs_info, "space_info", + space_info->flags, num_bytes, 1); + btrfs_space_info_update_bytes_may_use(cache->fs_info, space_info, + -ram_bytes); + if (delalloc) + cache->delalloc_bytes += num_bytes; +} + /** * btrfs_add_reserved_bytes - update the block_group and space info counters * @cache: The cache we are manipulating @@ -2778,20 +2822,16 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache, struct btrfs_space_info *space_info = cache->space_info; int ret = 0; + /* should handled by find_free_extent_zoned */ + ASSERT(!btrfs_fs_incompat(cache->fs_info, HMZONED)); + spin_lock(&space_info->lock); spin_lock(&cache->lock); - if (cache->ro) { + if (cache->ro) ret = -EAGAIN; - } else { - cache->reserved += num_bytes; - space_info->bytes_reserved += num_bytes; - trace_btrfs_space_reservation(cache->fs_info, "space_info", - space_info->flags, num_bytes, 1); - btrfs_space_info_update_bytes_may_use(cache->fs_info, - space_info, -ram_bytes); - if (delalloc) - cache->delalloc_bytes += num_bytes; - } + else + __btrfs_add_reserved_bytes(cache, ram_bytes, num_bytes, + delalloc); spin_unlock(&cache->lock); spin_unlock(&space_info->lock); return ret; diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 9b409676c4b2..347605654021 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -82,6 +82,7 @@ struct btrfs_block_group { unsigned int iref:1; unsigned int has_caching_ctl:1; unsigned int removed:1; + unsigned int wp_broken:1; int disk_cache_state; @@ -156,6 +157,14 @@ struct btrfs_block_group { /* Record locked full stripes for RAID5/6 block group */ struct btrfs_full_stripe_locks_tree full_stripe_locks_root; + + u64 zone_unusable; + /* + * Allocation offset for the block group to implement + * sequential allocation. This is used only with HMZONED mode + * enabled. + */ + u64 alloc_offset; }; #ifdef CONFIG_BTRFS_DEBUG @@ -216,6 +225,8 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, u64 bytenr, u64 num_bytes, int alloc); int btrfs_add_reserved_bytes(struct btrfs_block_group *cache, u64 ram_bytes, u64 num_bytes, int delalloc); +void __btrfs_add_reserved_bytes(struct btrfs_block_group *cache, u64 ram_bytes, + u64 num_bytes, int delalloc); void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, u64 num_bytes, int delalloc); int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 153f71a5bba9..3781a3778696 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -32,6 +32,8 @@ #include "block-rsv.h" #include "delalloc-space.h" #include "block-group.h" +#include "rcu-string.h" +#include "hmzoned.h" #undef SCRAMBLE_DELAYED_REFS @@ -2824,9 +2826,11 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info, cache = btrfs_lookup_block_group(fs_info, start); BUG_ON(!cache); /* Logic error */ - cluster = fetch_cluster_info(fs_info, - cache->space_info, - &empty_cluster); + if (!btrfs_fs_incompat(fs_info, HMZONED)) + cluster = fetch_cluster_info(fs_info, + cache->space_info, + &empty_cluster); + empty_cluster <<= 1; } @@ -2863,7 +2867,11 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info, space_info->max_extent_size = 0; percpu_counter_add_batch(&space_info->total_bytes_pinned, -len, BTRFS_TOTAL_BYTES_PINNED_BATCH); - if (cache->ro) { + if (btrfs_fs_incompat(fs_info, HMZONED)) { + /* need reset before reusing in zoned Block Group */ + space_info->bytes_zone_unusable += len; + readonly = true; + } else if (cache->ro) { space_info->bytes_readonly += len; readonly = true; } @@ -3657,6 +3665,57 @@ static int find_free_extent_unclustered(struct btrfs_block_group *bg, return 0; } +/* + * Simple allocator for sequential only block group. It only allows + * sequential allocation. No need to play with trees. This function + * also reserve the bytes as in btrfs_add_reserved_bytes. + */ + +static int find_free_extent_zoned(struct btrfs_block_group *cache, + struct find_free_extent_ctl *ffe_ctl) +{ + struct btrfs_space_info *space_info = cache->space_info; + struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; + u64 start = cache->start; + u64 num_bytes = ffe_ctl->num_bytes; + u64 avail; + int ret = 0; + + ASSERT(btrfs_fs_incompat(cache->fs_info, HMZONED)); + + spin_lock(&space_info->lock); + spin_lock(&cache->lock); + + if (cache->ro) { + ret = -EAGAIN; + goto out; + } + + avail = cache->length - cache->alloc_offset; + if (avail < num_bytes) { + ffe_ctl->max_extent_size = avail; + ret = 1; + goto out; + } + + ffe_ctl->found_offset = start + cache->alloc_offset; + cache->alloc_offset += num_bytes; + spin_lock(&ctl->tree_lock); + ctl->free_space -= num_bytes; + spin_unlock(&ctl->tree_lock); + + ASSERT(IS_ALIGNED(ffe_ctl->found_offset, + cache->fs_info->stripesize)); + ffe_ctl->search_start = ffe_ctl->found_offset; + __btrfs_add_reserved_bytes(cache, ffe_ctl->ram_bytes, num_bytes, + ffe_ctl->delalloc); + +out: + spin_unlock(&cache->lock); + spin_unlock(&space_info->lock); + return ret; +} + /* * Return >0 means caller needs to re-search for free extent * Return 0 means we have the needed free extent. @@ -3803,6 +3862,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, struct btrfs_block_group *block_group = NULL; struct find_free_extent_ctl ffe_ctl = {0}; struct btrfs_space_info *space_info; + bool hmzoned = btrfs_fs_incompat(fs_info, HMZONED); bool use_cluster = true; bool full_search = false; @@ -3965,6 +4025,17 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, if (unlikely(block_group->cached == BTRFS_CACHE_ERROR)) goto loop; + if (hmzoned) { + ret = find_free_extent_zoned(block_group, &ffe_ctl); + if (ret) + goto loop; + /* + * find_free_space_seq should ensure that + * everything is OK and reserve the extent. + */ + goto nocheck; + } + /* * Ok we want to try and use the cluster allocator, so * lets look there @@ -4020,6 +4091,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, num_bytes); goto loop; } +nocheck: btrfs_inc_block_group_reservations(block_group); /* we are all good, lets return */ diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 3283da419200..e068325fcfc0 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2336,6 +2336,8 @@ int __btrfs_add_free_space(struct btrfs_fs_info *fs_info, struct btrfs_free_space *info; int ret = 0; + ASSERT(!btrfs_fs_incompat(fs_info, HMZONED)); + info = kmem_cache_zalloc(btrfs_free_space_cachep, GFP_NOFS); if (!info) return -ENOMEM; @@ -2384,9 +2386,36 @@ int __btrfs_add_free_space(struct btrfs_fs_info *fs_info, return ret; } +int __btrfs_add_free_space_seq(struct btrfs_block_group *block_group, + u64 bytenr, u64 size) +{ + struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; + u64 offset = bytenr - block_group->start; + u64 to_free, to_unusable; + + spin_lock(&ctl->tree_lock); + if (block_group->wp_broken) + to_free = 0; + else if (offset >= block_group->alloc_offset) + to_free = size; + else if (offset + size <= block_group->alloc_offset) + to_free = 0; + else + to_free = offset + size - block_group->alloc_offset; + to_unusable = size - to_free; + + ctl->free_space += to_free; + block_group->zone_unusable += to_unusable; + spin_unlock(&ctl->tree_lock); + return 0; +} + int btrfs_add_free_space(struct btrfs_block_group *block_group, u64 bytenr, u64 size) { + if (btrfs_fs_incompat(block_group->fs_info, HMZONED)) + return __btrfs_add_free_space_seq(block_group, bytenr, size); + return __btrfs_add_free_space(block_group->fs_info, block_group->free_space_ctl, bytenr, size); @@ -2400,6 +2429,9 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group, int ret; bool re_search = false; + if (btrfs_fs_incompat(block_group->fs_info, HMZONED)) + return 0; + spin_lock(&ctl->tree_lock); again: @@ -2635,6 +2667,8 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group *block_group, u64 align_gap = 0; u64 align_gap_len = 0; + ASSERT(!btrfs_fs_incompat(block_group->fs_info, HMZONED)); + spin_lock(&ctl->tree_lock); entry = find_free_space(ctl, &offset, &bytes_search, block_group->full_stripe_len, max_extent_size); @@ -2754,6 +2788,8 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group *block_group, struct rb_node *node; u64 ret = 0; + ASSERT(!btrfs_fs_incompat(block_group->fs_info, HMZONED)); + spin_lock(&cluster->lock); if (bytes > cluster->max_size) goto out; @@ -3401,6 +3437,8 @@ int btrfs_trim_block_group(struct btrfs_block_group *block_group, { int ret; + ASSERT(!btrfs_fs_incompat(block_group->fs_info, HMZONED)); + *trimmed = 0; spin_lock(&block_group->lock); diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h index ba9a23241101..0d3812bbb793 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h @@ -84,6 +84,8 @@ void btrfs_init_free_space_ctl(struct btrfs_block_group *block_group); int __btrfs_add_free_space(struct btrfs_fs_info *fs_info, struct btrfs_free_space_ctl *ctl, u64 bytenr, u64 size); +int __btrfs_add_free_space_seq(struct btrfs_block_group *block_group, + u64 bytenr, u64 size); int btrfs_add_free_space(struct btrfs_block_group *block_group, u64 bytenr, u64 size); int btrfs_remove_free_space(struct btrfs_block_group *block_group, diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 9a814ad1b0a5..83dc2dc22323 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -8,14 +8,21 @@ #include #include +#include #include "ctree.h" #include "volumes.h" #include "hmzoned.h" #include "rcu-string.h" #include "disk-io.h" +#include "block-group.h" +#include "locking.h" /* Maximum number of zones to report per blkdev_report_zones() call */ #define BTRFS_REPORT_NR_ZONES 4096 +/* Invalid allocation pointer value for missing devices */ +#define WP_MISSING_DEV ((u64)-1) +/* Pseudo write pointer value for conventional zone */ +#define WP_CONVENTIONAL ((u64)-2) static int sb_write_pointer(struct blk_zone *zone, u64 *wp_ret); @@ -608,3 +615,463 @@ bool btrfs_check_allocatable_zones(struct btrfs_device *device, u64 pos, return find_next_bit(zinfo->seq_zones, end, begin) == end; } + +void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) +{ + u64 unusable, free; + + if (!btrfs_fs_incompat(cache->fs_info, HMZONED)) + return; + + WARN_ON(cache->bytes_super != 0); + if (!cache->wp_broken) { + unusable = cache->alloc_offset - cache->used; + free = cache->length - cache->alloc_offset; + } else { + unusable = cache->length - cache->used; + free = 0; + } + /* we only need ->free_space in ALLOC_SEQ BGs */ + cache->last_byte_to_unpin = (u64)-1; + cache->cached = BTRFS_CACHE_FINISHED; + cache->free_space_ctl->free_space = free; + cache->zone_unusable = unusable; + /* + * Should not have any excluded extents. Just + * in case, though. + */ + btrfs_free_excluded_extents(cache); +} + +static int emulate_write_pointer(struct btrfs_block_group *cache, + u64 *offset_ret) +{ + struct btrfs_fs_info *fs_info = cache->fs_info; + struct btrfs_root *root = fs_info->extent_root; + struct btrfs_path *path; + struct extent_buffer *leaf; + struct btrfs_key search_key; + struct btrfs_key found_key; + int slot; + int ret; + u64 length; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + search_key.objectid = cache->start + cache->length; + search_key.type = 0; + search_key.offset = 0; + + ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); + if (ret < 0) + goto out; + ASSERT(ret != 0); + slot = path->slots[0]; + leaf = path->nodes[0]; + ASSERT(slot != 0); + slot--; + btrfs_item_key_to_cpu(leaf, &found_key, slot); + + if (found_key.objectid < cache->start) { + *offset_ret = 0; + } else if (found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { + struct btrfs_key extent_item_key; + + if (found_key.objectid != cache->start) { + ret = -EUCLEAN; + goto out; + } + + length = 0; + + /* metadata may have METADATA_ITEM_KEY */ + if (slot == 0) { + btrfs_set_path_blocking(path); + ret = btrfs_prev_leaf(root, path); + if (ret < 0) + goto out; + if (ret == 0) { + slot = btrfs_header_nritems(leaf) - 1; + btrfs_item_key_to_cpu(leaf, &extent_item_key, + slot); + } + } else { + btrfs_item_key_to_cpu(leaf, &extent_item_key, slot - 1); + ret = 0; + } + + if (ret == 0 && + extent_item_key.objectid == cache->start) { + if (extent_item_key.type == BTRFS_METADATA_ITEM_KEY) + length = fs_info->nodesize; + else if (extent_item_key.type == BTRFS_EXTENT_ITEM_KEY) + length = extent_item_key.offset; + else { + ret = -EUCLEAN; + goto out; + } + } + + *offset_ret = length; + } else if (found_key.type == BTRFS_EXTENT_ITEM_KEY || + found_key.type == BTRFS_METADATA_ITEM_KEY) { + + if (found_key.type == BTRFS_EXTENT_ITEM_KEY) + length = found_key.offset; + else + length = fs_info->nodesize; + + if (!(found_key.objectid >= cache->start && + found_key.objectid + length <= + cache->start + cache->length)) { + ret = -EUCLEAN; + goto out; + } + *offset_ret = found_key.objectid + length - cache->start; + } else { + ret = -EUCLEAN; + goto out; + } + ret = 0; + +out: + btrfs_free_path(path); + return ret; +} + +static u64 offset_in_dev_extent(struct map_lookup *map, u64 *alloc_offsets, + u64 logical, int idx) +{ + u64 profile = map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK; + u64 stripe_nr = logical / map->stripe_len; + u64 full_stripes_cnt; + u32 rest_stripes_cnt; + u64 stripe_start, offset; + int data_stripes = map->num_stripes / map->sub_stripes; + int stripe_idx; + int i; + + ASSERT(profile == BTRFS_BLOCK_GROUP_RAID0 || + profile == BTRFS_BLOCK_GROUP_RAID10); + + full_stripes_cnt = div_u64_rem(stripe_nr, data_stripes, + &rest_stripes_cnt); + stripe_idx = idx / map->sub_stripes; + + if (stripe_idx < rest_stripes_cnt) + return map->stripe_len * (full_stripes_cnt + 1); + + for (i = idx + map->sub_stripes; i < map->num_stripes; + i += map->sub_stripes) { + if (alloc_offsets[i] != WP_CONVENTIONAL && + alloc_offsets[i] > map->stripe_len * full_stripes_cnt) + return map->stripe_len * (full_stripes_cnt + 1); + } + + stripe_start = (full_stripes_cnt * data_stripes + stripe_idx) * + map->stripe_len; + if (stripe_start >= logical) + return full_stripes_cnt * map->stripe_len; + offset = min_t(u64, logical - stripe_start, map->stripe_len); + + return full_stripes_cnt * map->stripe_len + offset; +} + +int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache) +{ + struct btrfs_fs_info *fs_info = cache->fs_info; + struct extent_map_tree *em_tree = &fs_info->mapping_tree; + struct extent_map *em; + struct map_lookup *map; + struct btrfs_device *device; + u64 logical = cache->start; + u64 length = cache->length; + u64 physical = 0; + int ret; + int i, j; + unsigned int nofs_flag; + u64 *alloc_offsets = NULL; + u64 emulated_offset = 0; + u32 num_sequential = 0, num_conventional = 0; + + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return 0; + + /* Sanity check */ + if (!IS_ALIGNED(length, fs_info->zone_size)) { + btrfs_err(fs_info, "unaligned block group at %llu + %llu", + logical, length); + return -EIO; + } + + /* Get the chunk mapping */ + read_lock(&em_tree->lock); + em = lookup_extent_mapping(em_tree, logical, length); + read_unlock(&em_tree->lock); + + if (!em) + return -EINVAL; + + map = em->map_lookup; + + /* + * Get the zone type: if the group is mapped to a non-sequential zone, + * there is no need for the allocation offset (fit allocation is OK). + */ + alloc_offsets = kcalloc(map->num_stripes, sizeof(*alloc_offsets), + GFP_NOFS); + if (!alloc_offsets) { + free_extent_map(em); + return -ENOMEM; + } + + for (i = 0; i < map->num_stripes; i++) { + bool is_sequential; + struct blk_zone zone; + + device = map->stripes[i].dev; + physical = map->stripes[i].physical; + + if (device->bdev == NULL) { + alloc_offsets[i] = WP_MISSING_DEV; + continue; + } + + is_sequential = btrfs_dev_is_sequential(device, physical); + if (is_sequential) + num_sequential++; + else + num_conventional++; + + if (!is_sequential) { + alloc_offsets[i] = WP_CONVENTIONAL; + continue; + } + + /* + * This zone will be used for allocation, so mark this + * zone non-empty. + */ + btrfs_dev_clear_zone_empty(device, physical); + + /* + * The group is mapped to a sequential zone. Get the zone write + * pointer to determine the allocation offset within the zone. + */ + WARN_ON(!IS_ALIGNED(physical, fs_info->zone_size)); + nofs_flag = memalloc_nofs_save(); + ret = btrfs_get_dev_zone(device, physical, &zone); + memalloc_nofs_restore(nofs_flag); + if (ret == -EIO || ret == -EOPNOTSUPP) { + ret = 0; + alloc_offsets[i] = WP_MISSING_DEV; + continue; + } else if (ret) { + goto out; + } + + switch (zone.cond) { + case BLK_ZONE_COND_OFFLINE: + case BLK_ZONE_COND_READONLY: + btrfs_err( + fs_info, "Offline/readonly zone %llu", + physical >> device->zone_info->zone_size_shift); + alloc_offsets[i] = WP_MISSING_DEV; + break; + case BLK_ZONE_COND_EMPTY: + alloc_offsets[i] = 0; + break; + case BLK_ZONE_COND_FULL: + alloc_offsets[i] = fs_info->zone_size; + break; + default: + /* Partially used zone */ + alloc_offsets[i] = + ((zone.wp - zone.start) << SECTOR_SHIFT); + break; + } + } + + if (num_conventional > 0) { + ret = emulate_write_pointer(cache, &emulated_offset); + if (ret || map->num_stripes == num_conventional) { + if (!ret) + cache->alloc_offset = emulated_offset; + goto out; + } + } + + switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { + case 0: /* single */ + case BTRFS_BLOCK_GROUP_DUP: + case BTRFS_BLOCK_GROUP_RAID1: + cache->alloc_offset = WP_MISSING_DEV; + for (i = 0; i < map->num_stripes; i++) { + if (alloc_offsets[i] == WP_MISSING_DEV || + alloc_offsets[i] == WP_CONVENTIONAL) + continue; + if (cache->alloc_offset == WP_MISSING_DEV) + cache->alloc_offset = alloc_offsets[i]; + if (alloc_offsets[i] == cache->alloc_offset) + continue; + + cache->wp_broken = 1; + } + break; + case BTRFS_BLOCK_GROUP_RAID0: + cache->alloc_offset = 0; + for (i = 0; i < map->num_stripes; i++) { + if (alloc_offsets[i] == WP_MISSING_DEV) { + cache->wp_broken = 1; + continue; + } + + if (alloc_offsets[i] == WP_CONVENTIONAL) + alloc_offsets[i] = + offset_in_dev_extent(map, alloc_offsets, + emulated_offset, + i); + + /* sanity check */ + if (i > 0) { + if ((alloc_offsets[i] % BTRFS_STRIPE_LEN != 0 && + alloc_offsets[i - 1] % + BTRFS_STRIPE_LEN != 0) || + (alloc_offsets[i - 1] < alloc_offsets[i]) || + (alloc_offsets[i - 1] - alloc_offsets[i] > + BTRFS_STRIPE_LEN)) { + cache->wp_broken = 1; + continue; + } + } + + cache->alloc_offset += alloc_offsets[i]; + } + break; + case BTRFS_BLOCK_GROUP_RAID10: + /* + * Pass1: check write pointer of RAID1 level: each pointer + * should be equal. + */ + for (i = 0; i < map->num_stripes / map->sub_stripes; i++) { + int base = i * map->sub_stripes; + u64 offset = WP_MISSING_DEV; + int fill = 0, num_conventional = 0; + + for (j = 0; j < map->sub_stripes; j++) { + if (alloc_offsets[base+j] == WP_MISSING_DEV) { + fill++; + continue; + } + if (alloc_offsets[base+j] == WP_CONVENTIONAL) { + fill++; + num_conventional++; + continue; + } + if (offset == WP_MISSING_DEV) + offset = alloc_offsets[base+j]; + if (alloc_offsets[base + j] == offset) + continue; + + cache->wp_broken = 1; + goto out; + } + if (!fill) + continue; + /* this RAID0 stripe is free on conventional zones */ + if (num_conventional == map->sub_stripes) + offset = WP_CONVENTIONAL; + /* fill WP_MISSING_DEV or WP_CONVENTIONAL */ + for (j = 0; j < map->sub_stripes; j++) + alloc_offsets[base + j] = offset; + } + + /* Pass2: check write pointer of RAID0 level */ + cache->alloc_offset = 0; + for (i = 0; i < map->num_stripes / map->sub_stripes; i++) { + int base = i * map->sub_stripes; + + if (alloc_offsets[base] == WP_MISSING_DEV) { + cache->wp_broken = 1; + continue; + } + + if (alloc_offsets[base] == WP_CONVENTIONAL) + alloc_offsets[base] = + offset_in_dev_extent(map, alloc_offsets, + emulated_offset, + base); + + /* sanity check */ + if (i > 0) { + int prev = base - map->sub_stripes; + + if ((alloc_offsets[base] % + BTRFS_STRIPE_LEN != 0 && + alloc_offsets[prev] % + BTRFS_STRIPE_LEN != 0) || + (alloc_offsets[prev] < + alloc_offsets[base]) || + (alloc_offsets[prev] - alloc_offsets[base] > + BTRFS_STRIPE_LEN)) { + cache->wp_broken = 1; + continue; + } + } + + cache->alloc_offset += alloc_offsets[base]; + } + break; + case BTRFS_BLOCK_GROUP_RAID5: + case BTRFS_BLOCK_GROUP_RAID6: + /* RAID5/6 is not supported yet */ + default: + btrfs_err(fs_info, "Unsupported profile on HMZONED %llu", + map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK); + ret = -EINVAL; + goto out; + } + +out: + /* an extent is allocated after the write pointer */ + if (num_conventional && emulated_offset > cache->alloc_offset) { + btrfs_err(fs_info, + "got wrong write pointer in BG %llu: %llu > %llu", + logical, emulated_offset, cache->alloc_offset); + cache->wp_broken = 1; + ret = -EIO; + } + + if (cache->wp_broken) { + char buf[128] = {'\0'}; + + btrfs_describe_block_groups(cache->flags, buf, sizeof(buf)); + btrfs_err(fs_info, "broken write pointer: block group %llu %s", + logical, buf); + for (i = 0; i < map->num_stripes; i++) { + char *note; + + device = map->stripes[i].dev; + physical = map->stripes[i].physical; + + if (device->bdev == NULL) + note = " (missing)"; + else if (!btrfs_dev_is_sequential(device, physical)) + note = " (conventional)"; + else + note = ""; + + btrfs_err_in_rcu(fs_info, + "stripe %d dev %s physical %llu write_pointer[i] = %llu%s", + i, rcu_str_deref(device->name), + physical, alloc_offsets[i], note); + } + } + + kfree(alloc_offsets); + free_extent_map(em); + + return ret; +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index d54b4ae8cf8b..4ed985d027cc 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -40,6 +40,8 @@ int btrfs_advance_sb_log(struct btrfs_device *device, int mirror); int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror); bool btrfs_check_allocatable_zones(struct btrfs_device *device, u64 pos, u64 num_bytes); +void btrfs_calc_zone_unusable(struct btrfs_block_group *cache); +int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -89,6 +91,12 @@ static inline bool btrfs_check_allocatable_zones(struct btrfs_device *device, { return true; } +static inline void btrfs_calc_zone_unusable(struct btrfs_block_group *cache) { } +static inline int btrfs_load_block_group_zone_info( + struct btrfs_block_group *cache) +{ + return 0; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index f09aa6ee9113..322036e49831 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -16,6 +16,7 @@ u64 __pure btrfs_space_info_used(struct btrfs_space_info *s_info, ASSERT(s_info); return s_info->bytes_used + s_info->bytes_reserved + s_info->bytes_pinned + s_info->bytes_readonly + + s_info->bytes_zone_unusable + (may_use_included ? s_info->bytes_may_use : 0); } @@ -112,7 +113,7 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info) void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, u64 total_bytes, u64 bytes_used, - u64 bytes_readonly, + u64 bytes_readonly, u64 bytes_zone_unusable, struct btrfs_space_info **space_info) { struct btrfs_space_info *found; @@ -128,6 +129,7 @@ void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, found->bytes_used += bytes_used; found->disk_used += bytes_used * factor; found->bytes_readonly += bytes_readonly; + found->bytes_zone_unusable += bytes_zone_unusable; if (total_bytes > 0) found->full = 0; btrfs_try_granting_tickets(info, found); @@ -267,10 +269,10 @@ static void __btrfs_dump_space_info(struct btrfs_fs_info *fs_info, info->total_bytes - btrfs_space_info_used(info, true), info->full ? "" : "not "); btrfs_info(fs_info, - "space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu", + "space_info total=%llu, used=%llu, pinned=%llu, reserved=%llu, may_use=%llu, readonly=%llu zone_unusable=%llu", info->total_bytes, info->bytes_used, info->bytes_pinned, info->bytes_reserved, info->bytes_may_use, - info->bytes_readonly); + info->bytes_readonly, info->bytes_zone_unusable); DUMP_BLOCK_RSV(fs_info, global_block_rsv); DUMP_BLOCK_RSV(fs_info, trans_block_rsv); @@ -299,9 +301,10 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, list_for_each_entry(cache, &info->block_groups[index], list) { spin_lock(&cache->lock); btrfs_info(fs_info, - "block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %s", + "block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %llu zone_unusable %s", cache->start, cache->length, cache->used, cache->pinned, - cache->reserved, cache->ro ? "[readonly]" : ""); + cache->reserved, cache->zone_unusable, + cache->ro ? "[readonly]" : ""); btrfs_dump_free_space(cache, bytes); spin_unlock(&cache->lock); } diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 1a349e3f9cc1..a1a5f6c2611b 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -17,6 +17,8 @@ struct btrfs_space_info { u64 bytes_may_use; /* number of bytes that may be used for delalloc/allocations */ u64 bytes_readonly; /* total bytes that are read only */ + u64 bytes_zone_unusable; /* total bytes that are unusable until + resetting the device zone */ u64 max_extent_size; /* This will hold the maximum extent size of the space info if we had an ENOSPC in the @@ -111,7 +113,7 @@ DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned"); int btrfs_init_space_info(struct btrfs_fs_info *fs_info); void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, u64 total_bytes, u64 bytes_used, - u64 bytes_readonly, + u64 bytes_readonly, u64 bytes_zone_unusable, struct btrfs_space_info **space_info); struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info, u64 flags); diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 230c7ad90e22..c479708537fc 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -458,6 +458,7 @@ SPACE_INFO_ATTR(bytes_pinned); SPACE_INFO_ATTR(bytes_reserved); SPACE_INFO_ATTR(bytes_may_use); SPACE_INFO_ATTR(bytes_readonly); +SPACE_INFO_ATTR(bytes_zone_unusable); SPACE_INFO_ATTR(disk_used); SPACE_INFO_ATTR(disk_total); BTRFS_ATTR(space_info, total_bytes_pinned, @@ -471,6 +472,7 @@ static struct attribute *space_info_attrs[] = { BTRFS_ATTR_PTR(space_info, bytes_reserved), BTRFS_ATTR_PTR(space_info, bytes_may_use), BTRFS_ATTR_PTR(space_info, bytes_readonly), + BTRFS_ATTR_PTR(space_info, bytes_zone_unusable), BTRFS_ATTR_PTR(space_info, disk_used), BTRFS_ATTR_PTR(space_info, disk_total), BTRFS_ATTR_PTR(space_info, total_bytes_pinned), From patchwork Wed Dec 4 08:17:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272309 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35E0A6C1 for ; Wed, 4 Dec 2019 08:19:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 143E82068E for ; Wed, 4 Dec 2019 08:19:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="jEcZB9d4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727403AbfLDITu (ORCPT ); Wed, 4 Dec 2019 03:19:50 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32758 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727388AbfLDITq (ORCPT ); Wed, 4 Dec 2019 03:19:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447587; x=1606983587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wvg0IqZ/70mmiMou4MCSFBUNqZKh0c6d/vjtjdV79yg=; b=jEcZB9d4eaUujFquU5GM9sfSfruhrn8Zz0olvuFHte9Dl3RalQdhW97R kPTUP3Q/RAK7ESuVw+RUWAw/tW3R+pMpNHWdVzMlBoTYIaEKMb6Q/Z5Yf MA4oy1hyfHgnu0X8g8ERIRphXXGMSJJjDRWi7TCd9sBPXbHv9wZ1V5EXt q9CvkR5LOSOOEqsi7SrUXqI2ecqX30Gc5LQBtG14i+8BdpMck9MsXvS3b VU68Y+tmX9EJ3rC0sOFCJ5bxBqxGZfg3qZeUBpUxaqFKc2vR66s3po1Fu jbljXBw+Sgnkuj1zgV+VpIZPsCSvo47KiJRZOUZ3uhKdRmnsLhJ44OCYj A==; IronPort-SDR: cTSByzUN4eQQMK099gRon42SkWSS51bc/c1qbSLswi0bu4ypQuoyAyR69lgCedg4Ne2EO8zuHD wc1KTe/rAOsd+n9bo+oZ49yhPGzSDNa/vHt4Y6IO6to5LDAEjUSza6gst0LVlbYULUzvr3TBP7 EP6QfmTCMUeOqnCBXxUtCpWguDrp86BnZG4E8A6Go8GATJFbNhZTJkqe26jWAo9nnay64WQ+E+ 7eBcqh6flpU7ia1zzHum7Ki1HLhJYE9b9Ibvz4y1bPeqSHGSZIjTuZ0hWCJXCglzHBBa5Jz4Kg DaM= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355064" 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; 04 Dec 2019 16:19:46 +0800 IronPort-SDR: W3oSlbAGmvsP2wuSgjHZAkMUzonOoC3GwCWZnC8yhmF61bBoAVEmOYIHA0fKnTmoaAYmha1/G7 CoF/0iPFqg4epmqN002/hZTTVZFLC0jR21eHiB9HOkyiMdc174uNeSaP72njWqS97YQ9+Itw+n i2v/+M7LTSsUgVsJQvFCowoHhqc1JrR8o/DGKQcszXDF0OT3E/EQvwlDWatg7vvx0RIBU/I6oY wfmGHtjUR6ltCyh9aB6BC5SpMgyZn0iXGK61EjCW4xjRU/5d7pM/HP9LkB66CECQaJmbo3yL1K uL6/bjmOqhG/8fs8fao2joP0 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:11 -0800 IronPort-SDR: /bk3FznSpO+2nolqNKzEdF82r59p9l8zicp4IBiqgssl3Am8YQE4rl0wunHIM7Fuj9CncurEKn pBUH1ydhfz4EF6fZ6VinlxAokDPc67GWOdrt9hBkZwySrefx/lJWVn0KGyg6NyraqRnpfPjLJ+ 9G48j5q6b4Yi5FGWOoZZ1JR8iNgUilplU47gm7MBqZ9DSw25hGR/X0SGDovCBnM0XkGQ4aCxWX bJK65ibetdnrrCeiU3NwVfF7BNJa2CpTwk6d+PcSWdK6j5Jr5cpg/LCtX5Z1p17ksNR1wszr5r IaI= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:44 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 11/28] btrfs: make unmirroed BGs readonly only if we have at least one writable BG Date: Wed, 4 Dec 2019 17:17:18 +0900 Message-Id: <20191204081735.852438-12-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If the btrfs volume has mirrored block groups, it unconditionally makes un-mirrored block groups read only. When we have mirrored block groups, but don't have writable block groups, this will drop all writable block groups. So, check if we have at least one writable mirrored block group before setting un-mirrored block groups read only. This change is necessary to handle e.g. xfstests btrfs/124 case. When we mount degraded RAID1 FS and write to it, and then re-mount with full device, the write pointers of corresponding zones of written block group differ. We mark such block group as "wp_broken" and make it read only. In this situation, we only have read only RAID1 block groups because of "wp_broken" and un-mirrored block groups are also marked read only, because we have RAID1 block groups. As a result, all the block groups are now read only, so that we cannot even start the rebalance to fix the situation. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 5c04422f6f5a..b286359f3876 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1813,6 +1813,27 @@ static int read_one_block_group(struct btrfs_fs_info *info, return ret; } +/* + * have_mirrored_block_group - check if we have at least one writable + * mirrored Block Group + */ +static bool have_mirrored_block_group(struct btrfs_space_info *space_info) +{ + struct btrfs_block_group *block_group; + int i; + + for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) { + if (i == BTRFS_RAID_RAID0 || i == BTRFS_RAID_SINGLE) + continue; + list_for_each_entry(block_group, &space_info->block_groups[i], + list) { + if (!block_group->ro) + return true; + } + } + return false; +} + int btrfs_read_block_groups(struct btrfs_fs_info *info) { struct btrfs_path *path; @@ -1861,6 +1882,10 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info) BTRFS_BLOCK_GROUP_RAID56_MASK | BTRFS_BLOCK_GROUP_DUP))) continue; + + if (!have_mirrored_block_group(space_info)) + continue; + /* * Avoid allocating from un-mirrored block group if there are * mirrored block groups. From patchwork Wed Dec 4 08:17:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272313 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C42A517EF for ; Wed, 4 Dec 2019 08:19:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2167206DF for ; Wed, 4 Dec 2019 08:19:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="WqiZPK7y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727412AbfLDITv (ORCPT ); Wed, 4 Dec 2019 03:19:51 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32774 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727370AbfLDITu (ORCPT ); Wed, 4 Dec 2019 03:19:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447590; x=1606983590; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DnnBFlGOLII8ia0sIKHSj+86HBxr5rZC20HX/a86UVA=; b=WqiZPK7ym357GLoi3zIjg3uEcKFKe7kvZCpE97jSXAiFdzx5AAU7P4L7 KpRyAeZ4YEOaaHAmtcwH70Rxi5NDFG+iCLhkSBQZxz/BGfqchYv/iY6Cr qHHOHT+q3ZippixmmoWCevVoL6vN1fRsrRCFD5KNGC7W9fpCTaSYqP0c8 +SjIyttaulMI+luV+vSJP1nAg9iRD0W1wM1/dVboMogtaKnP0VUdOfqN1 z85Y4AlcRl5BXKtUZtQBS2m+94Yez+FtJqdfVaIZVCJiJ3yDLtyofsBLz 7EUJOP+xSNt+5v1Ki0Y/UBv1f7rcpcDT80cvxMKqscJQF76NFnOtqd5CS w==; IronPort-SDR: II1ZZiJd97Fl672vvAlXzWwVfIeLNCHsCbAoyZg82Ctr3eM5eVptxh9Ux4ma9RWLAuK99zUCHM bZpMsLUvhlykNN4ZJ+HPqleHbOSdkUAiOKcyA2HA92zX0zfolxX02NQAmihzFSoeO9uQxRcrE7 0xgFMQIAVJjlco7bRkWJz/B4GiI4CBaZ0uOAnkxQ203TI5uSQaJvzU7NUTE/EpCH04p2QrMmcX Sr65YOgaOe1eptlXt6XZvQFDI8E8LipbGQ8gUw2BfsTSxfVLOMsBda1i3OlwzDdz5O9rZoHUC9 C2U= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355073" 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; 04 Dec 2019 16:19:49 +0800 IronPort-SDR: 1NEQmhe0V10gVym5CZPaA9e8Zp8zohqH/uwALDICAf1GHvV4eospv42lBdjGh+ocWbbUccv4Lf +lJykOOFw8ijyBryGw7ez8zMLkT5BJONgFipNCDqzOmA8TSSb9zMvPA2hn9+ItQ3VUYe4Pp952 xfdyHKuZhLIir2AJ2KvIL2AoFvzffE+pHrsyuuX8K9F/NwVUUBlzkgsXVBp3M0eOP1snHtu7+6 GljU5wxkfixrbDI6//ImroLERtp73xYaWT9eQy1XJ8S2OohxGpTu48FLsXfaTL7dQKFfR3Qsqa QGH55MKgIR3HcP2Q8cAxk1/9 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:14 -0800 IronPort-SDR: XWBAmn9/zfXHOXJoQpUKPdu9JkRCnQ9rYRHAYM7GWN4HXbfRQCR1cuaf1SvaaD8HENB+sHM+Ey 2OnmajgDNrQdYgD3RefClBlGrjLsUU87dfORZ6xjoJkD9DY605nG2+wsqZumclxn0cjJRIDWgu 49HJZrlI3iwkoSEHhazFsi0juVYQ7ypfycrFmlOhKtpt7JKE48MDznMeDoZiOeVOkIrXdza89m JUsOgyIOkrXCURNTyAPrX09V315nv8F11C5A9PM2hhOCJntkD2udEa9II5NFay1ia2uJAASCOS bxo= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:46 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 12/28] btrfs: ensure metadata space available on/after degraded mount in HMZONED Date: Wed, 4 Dec 2019 17:17:19 +0900 Message-Id: <20191204081735.852438-13-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On/After degraded mount, we might have no writable metadata block group due to broken write pointers. If you e.g. balance the FS before writing any data, alloc_tree_block_no_bg_flush() (called from insert_balance_item()) fails to allocate a tree block for it, due to global reservation failure. We can reproduce this situation with xfstests btrfs/124. While we can workaround the failure if we write some data and, as a result of writing, let a new metadata block group allocated, it's a bad practice to apply. This commit avoids such failures by ensuring that read-write mounted volume has non-zero metadata space. If metadata space is empty, it forces new metadata block group allocation. Signed-off-by: Naohiro Aota --- fs/btrfs/disk-io.c | 9 +++++++++ fs/btrfs/hmzoned.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 6 ++++++ 3 files changed, 60 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index deca9fd70771..7f4c6a92079a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3246,6 +3246,15 @@ int __cold open_ctree(struct super_block *sb, } } + ret = btrfs_hmzoned_check_metadata_space(fs_info); + if (ret) { + btrfs_warn(fs_info, "failed to allocate metadata space: %d", + ret); + btrfs_warn(fs_info, "try remount with readonly"); + close_ctree(fs_info); + return ret; + } + down_read(&fs_info->cleanup_work_sem); if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) || (ret = btrfs_orphan_cleanup(fs_info->tree_root))) { diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 83dc2dc22323..4fd96fd43897 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -16,6 +16,8 @@ #include "disk-io.h" #include "block-group.h" #include "locking.h" +#include "space-info.h" +#include "transaction.h" /* Maximum number of zones to report per blkdev_report_zones() call */ #define BTRFS_REPORT_NR_ZONES 4096 @@ -1075,3 +1077,46 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache) return ret; } + +/* + * On/After degraded mount, we might have no writable metadata block + * group due to broken write pointers. If you e.g. balance the FS + * before writing any data, alloc_tree_block_no_bg_flush() (called + * from insert_balance_item())fails to allocate a tree block for + * it. To avoid such situations, ensure we have some metadata BG here. + */ +int btrfs_hmzoned_check_metadata_space(struct btrfs_fs_info *fs_info) +{ + struct btrfs_root *root = fs_info->extent_root; + struct btrfs_trans_handle *trans; + struct btrfs_space_info *info; + u64 left; + int ret; + + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return 0; + + info = btrfs_find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA); + spin_lock(&info->lock); + left = info->total_bytes - btrfs_space_info_used(info, true); + spin_unlock(&info->lock); + + if (left) + return 0; + + trans = btrfs_start_transaction(root, 0); + if (IS_ERR(trans)) + return PTR_ERR(trans); + + mutex_lock(&fs_info->chunk_mutex); + ret = btrfs_alloc_chunk(trans, btrfs_metadata_alloc_profile(fs_info)); + if (ret) { + mutex_unlock(&fs_info->chunk_mutex); + btrfs_abort_transaction(trans, ret); + btrfs_end_transaction(trans); + return ret; + } + mutex_unlock(&fs_info->chunk_mutex); + + return btrfs_commit_transaction(trans); +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index 4ed985d027cc..8ac758074afd 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -42,6 +42,7 @@ bool btrfs_check_allocatable_zones(struct btrfs_device *device, u64 pos, u64 num_bytes); void btrfs_calc_zone_unusable(struct btrfs_block_group *cache); int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache); +int btrfs_hmzoned_check_metadata_space(struct btrfs_fs_info *fs_info); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -97,6 +98,11 @@ static inline int btrfs_load_block_group_zone_info( { return 0; } +static inline int btrfs_hmzoned_check_metadata_space( + struct btrfs_fs_info *fs_info) +{ + return 0; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) From patchwork Wed Dec 4 08:17:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272317 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA6A76C1 for ; Wed, 4 Dec 2019 08:19:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9041A2068E for ; Wed, 4 Dec 2019 08:19:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Fa5Rsuf8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727420AbfLDITx (ORCPT ); Wed, 4 Dec 2019 03:19:53 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727370AbfLDITw (ORCPT ); Wed, 4 Dec 2019 03:19:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447592; x=1606983592; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZOJWDCO29Lzs1E0Bi4IJaDaHtj6nm3ML/WZWkr7HtVk=; b=Fa5Rsuf8WQOyn/48MjrocOuPxWXLumrQ0iEchUB/0JkE32hFrjWsm+zT eBtbUqIyZcawQ7IuiWDe/FLDd6FuY23A3rUBWhoVLx3QK2wVAfzV3s/Es rnbOrayL3Csp9m9AWuEkZxy7BWBoHcRxqt+Icr83XJpbdCba4jibUy5de OwMzCqJkCXEQrcbCel395976R0Cei4n+jAjiLYyC2N6tHEeY2WNKUl0Pu TTx6b3olu3iTSJFfVXnmIhc7wztGPKU5n89UhlRRXXRghOPDkxHn3+kM0 L3WS63PgRdC+RwdNHbChWAQio48TFVJDud/jc0rOJ7F2VAfDkwubLApSA g==; IronPort-SDR: 35JrSpGblRX9M3RDKAYZ6WSXi7OT5vJrtYdtc8cZBK2aja34O27SpoNyQKLS4PEqQe0mUB73Gt JW8LAeJ+AwrNFFzKuAwpIoKfCF2j7j5DJjFu+0qiTf4UqFEJKJHwbL1Tv+amO8z0F3kgyZpRGR Ot2T8LmxCp6g++OchGbniSEKKERbYoFiH4QB67IWxqDPAPNJe0Gx0pkxFGx243IxYqQ0+EljYV HO07wtPgHvtv7Jwuja7wBWnicS0+2FsNkwWbx6q3p1rWIpZAQD/6kon/dMHx7QNHkn64107lQ/ RCQ= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355078" 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; 04 Dec 2019 16:19:52 +0800 IronPort-SDR: TWwM2B2Uc0xYWgl2o+73CWv7z0j63BThL29Mg2iXHMzHyK4O/tGQrF51a/TTmX3moJp7bf8SHT Jfk5OWp15GR6jZ4T6gQO35pRdrh3apj5Hu6npZiWbvWEzOLz7RTXv2DrGne0OFW1xNkuvY8tLf qpyXzkbyWBb0mueyMQKRg1BbR781Pu7WziC54WjUloBIlzOA6qowLeIWNiFdBrZMDyW2TPGvi1 s2Sdh36wxPtWqOM4gQHPzlkLu/H7hXc/1OIQTxOfOoKkrGuFKfVVmPAVHSXx/OzNdcdaWrRxZ9 mu8aDb9KnQQ2Kc3XUZaV1I0K Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:17 -0800 IronPort-SDR: xQ5Hl5FHDUGJN9LAfs/mtaSfZm7Mz4F63ZflWdzoBHT4W/33Bfo8CVnFRjLdi8LNy6VUm3Ka+2 lZ0M+LG/GTbtubs8pFtb42NJWQTp3rhP24NE5xg1c2ic1Cq8As/ObNMJk7xDRfe8g7GHDGnJaM zg5V6b4oU8NFwZoNSgSD3rbTuR3wcFN9tzE+OX/MO2rCeOAzq3B9SePslwv2OeEi0xhIyYTI/M uXxvdMZeMiqo/Mx9zFV9E6Jc2NRkOwshuAPS/whU6N7e6lJTzWk48LdgBG2EJF2Qe7dYPckxRi ZqE= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:48 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 13/28] btrfs: reset zones of unused block groups Date: Wed, 4 Dec 2019 17:17:20 +0900 Message-Id: <20191204081735.852438-14-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org For an HMZONED volume, a block group maps to a zone of the device. For deleted unused block groups, the zone of the block group can be reset to rewind the zone write pointer at the start of the zone. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 8 ++++++-- fs/btrfs/extent-tree.c | 17 ++++++++++++----- fs/btrfs/hmzoned.c | 18 ++++++++++++++++++ fs/btrfs/hmzoned.h | 23 +++++++++++++++++++++++ 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index b286359f3876..e78d34a4fb56 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1369,8 +1369,12 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) spin_unlock(&block_group->lock); spin_unlock(&space_info->lock); - /* DISCARD can flip during remount */ - trimming = btrfs_test_opt(fs_info, DISCARD); + /* + * DISCARD can flip during remount. In HMZONED mode, + * we need to reset sequential required zones. + */ + trimming = btrfs_test_opt(fs_info, DISCARD) || + btrfs_fs_incompat(fs_info, HMZONED); /* Implicit trim during transaction commit. */ if (trimming) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 3781a3778696..b41a45855bc4 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1338,6 +1338,9 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, stripe = bbio->stripes; for (i = 0; i < bbio->num_stripes; i++, stripe++) { + struct btrfs_device *dev = stripe->dev; + u64 physical = stripe->physical; + u64 length = stripe->length; u64 bytes; struct request_queue *req_q; @@ -1345,14 +1348,18 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, ASSERT(btrfs_test_opt(fs_info, DEGRADED)); continue; } + req_q = bdev_get_queue(stripe->dev->bdev); - if (!blk_queue_discard(req_q)) + /* zone reset in HMZONED mode */ + if (btrfs_can_zone_reset(dev, physical, length)) + ret = btrfs_reset_device_zone(dev, physical, + length, &bytes); + else if (blk_queue_discard(req_q)) + ret = btrfs_issue_discard(dev->bdev, physical, + length, &bytes); + else continue; - ret = btrfs_issue_discard(stripe->dev->bdev, - stripe->physical, - stripe->length, - &bytes); if (!ret) { discarded_bytes += bytes; } else if (ret != -EOPNOTSUPP) { diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 4fd96fd43897..0eb4f578c54a 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -1120,3 +1120,21 @@ int btrfs_hmzoned_check_metadata_space(struct btrfs_fs_info *fs_info) return btrfs_commit_transaction(trans); } + +int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, + u64 length, u64 *bytes) +{ + int ret; + + ret = blkdev_reset_zones(device->bdev, physical >> SECTOR_SHIFT, + length >> SECTOR_SHIFT, GFP_NOFS); + if (!ret) { + *bytes = length; + while (length) { + btrfs_dev_set_zone_empty(device, physical); + length -= device->zone_info->zone_size; + } + } + + return ret; +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index 8ac758074afd..e1fa6a2f2557 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -43,6 +43,8 @@ bool btrfs_check_allocatable_zones(struct btrfs_device *device, u64 pos, void btrfs_calc_zone_unusable(struct btrfs_block_group *cache); int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache); int btrfs_hmzoned_check_metadata_space(struct btrfs_fs_info *fs_info); +int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, + u64 length, u64 *bytes); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -103,6 +105,11 @@ static inline int btrfs_hmzoned_check_metadata_space( { return 0; } +static inline int btrfs_reset_device_zone(struct btrfs_device *device, + u64 physical, u64 length, u64 *bytes) +{ + return 0; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) @@ -189,4 +196,20 @@ static inline u64 btrfs_zone_align(struct btrfs_device *device, u64 pos) return ALIGN(pos, device->zone_info->zone_size); } +static inline bool btrfs_can_zone_reset(struct btrfs_device *device, + u64 physical, u64 length) +{ + u64 zone_size; + + if (!btrfs_dev_is_sequential(device, physical)) + return false; + + zone_size = device->zone_info->zone_size; + if (!IS_ALIGNED(physical, zone_size) || + !IS_ALIGNED(length, zone_size)) + return false; + + return true; +} + #endif From patchwork Wed Dec 4 08:17:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24D526C1 for ; Wed, 4 Dec 2019 08:19:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EC6A620675 for ; Wed, 4 Dec 2019 08:19:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="EaDsvsUE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727283AbfLDIT4 (ORCPT ); Wed, 4 Dec 2019 03:19:56 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727370AbfLDITz (ORCPT ); Wed, 4 Dec 2019 03:19:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447595; x=1606983595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QqEFXmHtK6lkWlPuAAKCfDrEAYUfdSQMaeXLzrs1npQ=; b=EaDsvsUEu1Sf2R6dMtjuKD9U9xpIys2aWQl6s1kxC1TZRdvAR2CgCP2B IkQoOVmqCWcFVeXRiVGykA5o8F58BXcYR5TEYwfyCh5Nw+oj13RPTyHLK yp9nsAgfAOH3n2XvZ/FXpd3jsV1ho8/x7Fv3o/lAV6YzMCkSHsKwmxRdU 65+/sJ+B3c+vOdrN0pwX3AJQbqnZpOxqKCxWUBR5xcl6zR95QBZ8cOeaL bxP86cyoxsElYwarRNWjLapT2VICjadMhwqVKfB5JSCcsc8b+PQUCoAwk SCO3ccVj7FecihlHi0B374zoL2Y3qTcp6nqYLbERGeVwR1WSMLyPiHjqR w==; IronPort-SDR: kb48U6rMmJQoH1g84hu42+BpHJwTuC4HGbFSDoKx1FRhrw5EzMVCmJbo8jNM1aG2i3h+m4c+/Y IGoUujXzwbF7fBRuE8/P0Yq4GcrbeZO7e460gzFERQtRg0QHvG4EHPpnVDbeE0XaWJiQNPlp3M dVDVYu/g4KC1UPMb/5qoVIlmhRFjnUV+1+4JWdBRsNRlPvmsR3jlCsaTtWakYHgKaj0pdRhNnT lRknQ+Zt7RmC2XhTM3TzZrxK5K97NEdnuU96RWSm3mT0/Bj7/c7DDnYhukG+qE7TxKEdil4FIn WFU= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355087" 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; 04 Dec 2019 16:19:55 +0800 IronPort-SDR: CMJEqtYUG5fAMVZeHFeEnLOqwvVdyo+Gb4zLLc4+bBQ+KybY3BJkotU2bIgrwsiBZxV20w+g3L SCbgD/RJwGjhoKzI3hMWfbDqRrSrKCU4kxOwbohB6Ur7xADZ6UwctUY+0giRu6p59M3681fxlP wGDP4MU16IztxcUIqbE+g9gMWwa3S/zP4t3DCsGCoWpZOauhDXsbwQ/iAH34VFTuJDxam381PD G09e/0rvECglUkIaUURn+4CgvrfD0aG8mYPLtDXjdtdJKjtYDlNqJ/WQvuBUFv87XBlO3uZpZQ G3LtaKIbUCcGm3ZQZMAvuWNC Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:20 -0800 IronPort-SDR: Z0cQab+MYNFHMPSGfvgbfDk1iXWx97vevPW+D8FSO9XeZiQrN9kBpgdzMo4dtYZkxAvpOblsyh V8A23SNK5GE4FdKSVtck24Zt3NVezeMmDlpeTNv009x9VLJO7kvRA58A9wTybk7k+0Rho/FD4L 3h3rc6pIQzztcFmrVYvsFi1FruwZL4ydDaGJZ6WCwAeLCtKZYVgwGuUrO6fGfBqVwWHTnbKGhE BiCgaaPmR53yYulEyBZnhPbAGZVg+JLsXyNXqwQ+tmv4NAC3laYDdh5qK9T8fqgsJDIxyYT93b Pqc= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:51 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 14/28] btrfs: redirty released extent buffers in HMZONED mode Date: Wed, 4 Dec 2019 17:17:21 +0900 Message-Id: <20191204081735.852438-15-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Tree manipulating operations like merging nodes often release once-allocated tree nodes. Btrfs cleans such nodes so that pages in the node are not uselessly written out. On HMZONED drives, however, such optimization blocks the following IOs as the cancellation of the write out of the freed blocks breaks the sequential write sequence expected by the device. This patch introduces a list of clean and unwritten extent buffers that have been released in a transaction. Btrfs redirty the buffer so that btree_write_cache_pages() can send proper bios to the devices. Besides it clears the entire content of the extent buffer not to confuse raw block scanners e.g. btrfsck. By clearing the content, csum_dirty_buffer() complains about bytenr mismatch, so avoid the checking and checksum using newly introduced buffer flag EXTENT_BUFFER_NO_CHECK. Signed-off-by: Naohiro Aota --- fs/btrfs/disk-io.c | 8 ++++++++ fs/btrfs/extent-tree.c | 12 +++++++++++- fs/btrfs/extent_io.c | 3 +++ fs/btrfs/extent_io.h | 2 ++ fs/btrfs/hmzoned.c | 36 ++++++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 6 ++++++ fs/btrfs/transaction.c | 10 ++++++++++ fs/btrfs/transaction.h | 3 +++ 8 files changed, 79 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 7f4c6a92079a..fbbc313f9f46 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -525,6 +525,12 @@ static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page) return 0; found_start = btrfs_header_bytenr(eb); + + if (test_bit(EXTENT_BUFFER_NO_CHECK, &eb->bflags)) { + WARN_ON(found_start != 0); + return 0; + } + /* * Please do not consolidate these warnings into a single if. * It is useful to know what went wrong. @@ -4521,6 +4527,8 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans, btrfs_destroy_pinned_extent(fs_info, fs_info->pinned_extents); + btrfs_free_redirty_list(cur_trans); + cur_trans->state =TRANS_STATE_COMPLETED; wake_up(&cur_trans->commit_wait); } diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index b41a45855bc4..e61f69eef4a8 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3301,8 +3301,10 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans, if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { ret = check_ref_cleanup(trans, buf->start); - if (!ret) + if (!ret) { + btrfs_redirty_list_add(trans->transaction, buf); goto out; + } } pin = 0; @@ -3314,6 +3316,13 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans, goto out; } + if (btrfs_fs_incompat(fs_info, HMZONED)) { + btrfs_redirty_list_add(trans->transaction, buf); + pin_down_extent(cache, buf->start, buf->len, 1); + btrfs_put_block_group(cache); + goto out; + } + WARN_ON(test_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)); btrfs_add_free_space(cache, buf->start, buf->len); @@ -4524,6 +4533,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, btrfs_tree_lock(buf); btrfs_clean_tree_block(buf); clear_bit(EXTENT_BUFFER_STALE, &buf->bflags); + clear_bit(EXTENT_BUFFER_NO_CHECK, &buf->bflags); btrfs_set_lock_blocking_write(buf); set_extent_buffer_uptodate(buf); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index eb8bd0258360..6e25c8790ef4 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -24,6 +24,7 @@ #include "rcu-string.h" #include "backref.h" #include "disk-io.h" +#include "hmzoned.h" static struct kmem_cache *extent_state_cache; static struct kmem_cache *extent_buffer_cache; @@ -4889,6 +4890,7 @@ __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start, init_waitqueue_head(&eb->read_lock_wq); btrfs_leak_debug_add(&eb->leak_list, &buffers); + INIT_LIST_HEAD(&eb->release_list); spin_lock_init(&eb->refs_lock); atomic_set(&eb->refs, 1); @@ -5686,6 +5688,7 @@ void write_extent_buffer(struct extent_buffer *eb, const void *srcv, WARN_ON(start > eb->len); WARN_ON(start + len > eb->start + eb->len); + WARN_ON(test_bit(EXTENT_BUFFER_NO_CHECK, &eb->bflags)); offset = offset_in_page(start_offset + start); diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index a8551a1f56e2..51a15e93a5cd 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -29,6 +29,7 @@ enum { EXTENT_BUFFER_IN_TREE, /* write IO error */ EXTENT_BUFFER_WRITE_ERR, + EXTENT_BUFFER_NO_CHECK, }; /* these are flags for __process_pages_contig */ @@ -115,6 +116,7 @@ struct extent_buffer { */ wait_queue_head_t read_lock_wq; struct page *pages[INLINE_EXTENT_BUFFER_PAGES]; + struct list_head release_list; #ifdef CONFIG_BTRFS_DEBUG int spinning_writers; atomic_t spinning_readers; diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 0eb4f578c54a..169ef8a35cba 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -1138,3 +1138,39 @@ int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, return ret; } + +void btrfs_redirty_list_add(struct btrfs_transaction *trans, + struct extent_buffer *eb) +{ + struct btrfs_fs_info *fs_info = eb->fs_info; + + if (!btrfs_fs_incompat(fs_info, HMZONED) || + btrfs_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN) || + !list_empty(&eb->release_list)) + return; + + set_extent_buffer_dirty(eb); + set_extent_bits_nowait(&trans->dirty_pages, eb->start, + eb->start + eb->len - 1, EXTENT_DIRTY); + memzero_extent_buffer(eb, 0, eb->len); + set_bit(EXTENT_BUFFER_NO_CHECK, &eb->bflags); + + spin_lock(&trans->releasing_ebs_lock); + list_add_tail(&eb->release_list, &trans->releasing_ebs); + spin_unlock(&trans->releasing_ebs_lock); + atomic_inc(&eb->refs); +} + +void btrfs_free_redirty_list(struct btrfs_transaction *trans) +{ + spin_lock(&trans->releasing_ebs_lock); + while (!list_empty(&trans->releasing_ebs)) { + struct extent_buffer *eb; + + eb = list_first_entry(&trans->releasing_ebs, + struct extent_buffer, release_list); + list_del_init(&eb->release_list); + free_extent_buffer(eb); + } + spin_unlock(&trans->releasing_ebs_lock); +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index e1fa6a2f2557..ddec6aed7283 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -45,6 +45,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache); int btrfs_hmzoned_check_metadata_space(struct btrfs_fs_info *fs_info); int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, u64 length, u64 *bytes); +void btrfs_redirty_list_add(struct btrfs_transaction *trans, + struct extent_buffer *eb); +void btrfs_free_redirty_list(struct btrfs_transaction *trans); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -110,6 +113,9 @@ static inline int btrfs_reset_device_zone(struct btrfs_device *device, { return 0; } +static inline void btrfs_redirty_list_add(struct btrfs_transaction *trans, + struct extent_buffer *eb) { } +static inline void btrfs_free_redirty_list(struct btrfs_transaction *trans) { } #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 19de6e2041dc..39628c370bdb 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -21,6 +21,7 @@ #include "dev-replace.h" #include "qgroup.h" #include "block-group.h" +#include "hmzoned.h" #define BTRFS_ROOT_TRANS_TAG 0 @@ -329,6 +330,8 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, spin_lock_init(&cur_trans->dirty_bgs_lock); INIT_LIST_HEAD(&cur_trans->deleted_bgs); spin_lock_init(&cur_trans->dropped_roots_lock); + INIT_LIST_HEAD(&cur_trans->releasing_ebs); + spin_lock_init(&cur_trans->releasing_ebs_lock); list_add_tail(&cur_trans->list, &fs_info->trans_list); extent_io_tree_init(fs_info, &cur_trans->dirty_pages, IO_TREE_TRANS_DIRTY_PAGES, fs_info->btree_inode); @@ -2336,6 +2339,13 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) goto scrub_continue; } + /* + * At this point, we should have written the all tree blocks + * allocated in this transaction. So it's now safe to free the + * redirtyied extent buffers. + */ + btrfs_free_redirty_list(cur_trans); + ret = write_all_supers(fs_info, 0); /* * the super is written, we can safely allow the tree-loggers diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 49f7196368f5..3d60d2213c70 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -84,6 +84,9 @@ struct btrfs_transaction { spinlock_t dropped_roots_lock; struct btrfs_delayed_ref_root delayed_refs; struct btrfs_fs_info *fs_info; + + spinlock_t releasing_ebs_lock; + struct list_head releasing_ebs; }; #define __TRANS_FREEZABLE (1U << 0) From patchwork Wed Dec 4 08:17:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272325 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A237930 for ; Wed, 4 Dec 2019 08:20:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F61E2068E for ; Wed, 4 Dec 2019 08:20:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="L9bYPg+0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727436AbfLDIT7 (ORCPT ); Wed, 4 Dec 2019 03:19:59 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727370AbfLDIT5 (ORCPT ); Wed, 4 Dec 2019 03:19:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447598; x=1606983598; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y8QXk6brR3tcRJ1SASk/5og+UoqtTNWx3qVdS+e9vws=; b=L9bYPg+0MCHa4pIgxXP9C64xE83nnkIiW3nXKd8kjalMK+zIHkIDYOgo +4ZGV/ZGqZsL52MG5DI29qkC3oGvaegF0wFHFPwP53zPsQ7iwFp4L8yvU AWx5oMSz9ypy7W4/hylQ4IMwdcmvwb6ShdsphLEOSQRxATAB0CaQz/u4g dp/vCAuvJiF4a1r8kKa4o7oF0g9EhwEl0fCgw5cCin9HLJnY8tYaKRWi/ r2qg3QIIATmGpHzTh7E5fMhu88XITopB/c28l2F9zxdd7HPXvqAdRz5Zy 4fm4BEges8PiJWdvsWFcKVmI7J/oGmqWfh+VkipHjQmDhtiIxGAMMr1sJ Q==; IronPort-SDR: lFNi0pDP/AVlrZ5H/aEVD2eYlv/74PGBYxCEtduQANQ+umuubeFWIW4FpPPXuCuSHDxuvmEUHF UsE/vtcIbDWVC1RkJqkwm4lO54kpLrE0TVY0xMqi5Ph8mS8xtkrYhul1swaaKRZiJjJgaLDHG6 tmSPxHMiFyqqaPG2ySpWqdHOV7q6hBdajOMsThgx+jjxlBCbkv04U6gP5peyTAnch8XGpZ9u3q gGGjNY2divUebEA255TPxCV14C8Lops8pk2yNA+jUhDquroVpnNQG/LUGkQWonDo2WJet+UaIE or4= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355092" 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; 04 Dec 2019 16:19:57 +0800 IronPort-SDR: M10k4O1do4JU6hlKiJNSquMOWm7MuMOY8Ktlj5+B1tH8cQDa0iNETWjB0671fxamGJtlW3klm7 sPJaaHRvvabdePEJ3OMX+dMOZOIvAVo2NqrXrVwevoKKmqxLFEpGK8KbjgKbbe3HSItl2rjJHo d5xmxX1acASeXZQN2n0IYBJTnwiXQzzbHFd7Hrg8aHSit/LIQCm75xYEVrAEtxLhcOxL/M9S/4 a156sO4nyrNwe1BwdtwsSNkwuAbqyOTM72TdlIT6vROxao005mNiK2sf6LnIGJuXfYQzycDFQg cqvisxGkkbIs/j1QDINANmBG Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:22 -0800 IronPort-SDR: RZW/2bvSfn1V40J4b8Q4MSKwHQ6p0YPxwqTXIr4rkqy5CVTRZfpkuq/cC1brxygJS+KdpbfjW4 /sggY+EEpnZARoN7n1KW1kVMKiC2ascwGtYuPxnbaey0If1C5GdcERYdEsvSUA7a5DUtyIzih2 94EegkS7Q1fgfHocoLGLd+lt2RwnLAPP7kFJdW2AcJ4ccXd3pATjX5ntEass95nbSBM2AVCz4t cPTeUATMb+dr1IKXmsShe6E6j40SNdH4Y9YUSkHp9ImvkkT1g9Fy/NnW1pqv4PInQp7kUBpIw8 nXA= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:54 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 15/28] btrfs: serialize data allocation and submit IOs Date: Wed, 4 Dec 2019 17:17:22 +0900 Message-Id: <20191204081735.852438-16-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org To preserve sequential write pattern on the drives, we must serialize allocation and submit_bio. This commit add per-block group mutex "zone_io_lock" and find_free_extent_zoned() hold the lock. The lock is kept even after returning from find_free_extent(). It is released when submiting IOs corresponding to the allocation is completed. Implementing such behavior under __extent_writepage_io() is almost impossible because once pages are unlocked we are not sure when submiting IOs for an allocated region is finished or not. Instead, this commit add run_delalloc_hmzoned() to write out non-compressed data IOs at once using extent_write_locked_rage(). After the write, we can call btrfs_hmzoned_data_io_unlock() to unlock the block group for new allocation. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 1 + fs/btrfs/block-group.h | 1 + fs/btrfs/extent-tree.c | 4 ++++ fs/btrfs/hmzoned.h | 36 +++++++++++++++++++++++++++++++++ fs/btrfs/inode.c | 45 ++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 85 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index e78d34a4fb56..6f7d29171adf 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1642,6 +1642,7 @@ static struct btrfs_block_group *btrfs_create_block_group_cache( btrfs_init_free_space_ctl(cache); atomic_set(&cache->trimming, 0); mutex_init(&cache->free_space_lock); + mutex_init(&cache->zone_io_lock); btrfs_init_full_stripe_locks_tree(&cache->full_stripe_locks_root); return cache; diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 347605654021..57c8d6f4b3d1 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -165,6 +165,7 @@ struct btrfs_block_group { * enabled. */ u64 alloc_offset; + struct mutex zone_io_lock; }; #ifdef CONFIG_BTRFS_DEBUG diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index e61f69eef4a8..d1f326b6c4d4 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3699,6 +3699,7 @@ static int find_free_extent_zoned(struct btrfs_block_group *cache, ASSERT(btrfs_fs_incompat(cache->fs_info, HMZONED)); + btrfs_hmzoned_data_io_lock(cache); spin_lock(&space_info->lock); spin_lock(&cache->lock); @@ -3729,6 +3730,9 @@ static int find_free_extent_zoned(struct btrfs_block_group *cache, out: spin_unlock(&cache->lock); spin_unlock(&space_info->lock); + /* if succeeds, unlock after submit_bio */ + if (ret) + btrfs_hmzoned_data_io_unlock(cache); return ret; } diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index ddec6aed7283..f6682ead575b 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -12,6 +12,7 @@ #include #include "volumes.h" #include "disk-io.h" +#include "block-group.h" struct btrfs_zoned_device_info { /* @@ -48,6 +49,7 @@ int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical, void btrfs_redirty_list_add(struct btrfs_transaction *trans, struct extent_buffer *eb); void btrfs_free_redirty_list(struct btrfs_transaction *trans); +void btrfs_hmzoned_data_io_unlock_at(struct inode *inode, u64 start, u64 len); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -116,6 +118,8 @@ static inline int btrfs_reset_device_zone(struct btrfs_device *device, static inline void btrfs_redirty_list_add(struct btrfs_transaction *trans, struct extent_buffer *eb) { } static inline void btrfs_free_redirty_list(struct btrfs_transaction *trans) { } +static inline void btrfs_hmzoned_data_io_unlock_at(struct inode *inode, + u64 start, u64 len) { } #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) @@ -218,4 +222,36 @@ static inline bool btrfs_can_zone_reset(struct btrfs_device *device, return true; } +static inline void btrfs_hmzoned_data_io_lock( + struct btrfs_block_group *cache) +{ + /* No need to lock metadata BGs or non-sequential BGs */ + if (!btrfs_fs_incompat(cache->fs_info, HMZONED) || + !(cache->flags & BTRFS_BLOCK_GROUP_DATA)) + return; + mutex_lock(&cache->zone_io_lock); +} + +static inline void btrfs_hmzoned_data_io_unlock( + struct btrfs_block_group *cache) +{ + if (!btrfs_fs_incompat(cache->fs_info, HMZONED) || + !(cache->flags & BTRFS_BLOCK_GROUP_DATA)) + return; + mutex_unlock(&cache->zone_io_lock); +} + +static inline void btrfs_hmzoned_data_io_unlock_logical( + struct btrfs_fs_info *fs_info, u64 logical) +{ + struct btrfs_block_group *cache; + + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return; + + cache = btrfs_lookup_block_group(fs_info, logical); + btrfs_hmzoned_data_io_unlock(cache); + btrfs_put_block_group(cache); +} + #endif diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 56032c518b26..3677c36999d8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -49,6 +49,7 @@ #include "qgroup.h" #include "delalloc-space.h" #include "block-group.h" +#include "hmzoned.h" struct btrfs_iget_args { struct btrfs_key *location; @@ -1325,6 +1326,39 @@ static int cow_file_range_async(struct inode *inode, return 0; } +static noinline int run_delalloc_hmzoned(struct inode *inode, + struct page *locked_page, u64 start, + u64 end, int *page_started, + unsigned long *nr_written) +{ + struct extent_map *em; + u64 logical; + int ret; + + ret = cow_file_range(inode, locked_page, start, end, + page_started, nr_written, 0); + if (ret) + return ret; + + if (*page_started) + return 0; + + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, end - start + 1, + 0); + ASSERT(em != NULL && em->block_start < EXTENT_MAP_LAST_BYTE); + logical = em->block_start; + free_extent_map(em); + + __set_page_dirty_nobuffers(locked_page); + account_page_redirty(locked_page); + extent_write_locked_range(inode, start, end, WB_SYNC_ALL); + *page_started = 1; + + btrfs_hmzoned_data_io_unlock_logical(btrfs_sb(inode->i_sb), logical); + + return 0; +} + static noinline int csum_exist_in_range(struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes) { @@ -1737,17 +1771,24 @@ int btrfs_run_delalloc_range(struct inode *inode, struct page *locked_page, { int ret; int force_cow = need_force_cow(inode, start, end); + int do_compress = inode_can_compress(inode) && + inode_need_compress(inode, start, end); + int hmzoned = btrfs_fs_incompat(btrfs_sb(inode->i_sb), HMZONED); if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW && !force_cow) { + ASSERT(!hmzoned); ret = run_delalloc_nocow(inode, locked_page, start, end, page_started, 1, nr_written); } else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC && !force_cow) { + ASSERT(!hmzoned); ret = run_delalloc_nocow(inode, locked_page, start, end, page_started, 0, nr_written); - } else if (!inode_can_compress(inode) || - !inode_need_compress(inode, start, end)) { + } else if (!do_compress && !hmzoned) { ret = cow_file_range(inode, locked_page, start, end, page_started, nr_written, 1); + } else if (!do_compress && hmzoned) { + ret = run_delalloc_hmzoned(inode, locked_page, start, end, + page_started, nr_written); } else { set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, &BTRFS_I(inode)->runtime_flags); From patchwork Wed Dec 4 08:17:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272327 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA299930 for ; Wed, 4 Dec 2019 08:20:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98CAD2068E for ; Wed, 4 Dec 2019 08:20:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="fAiRl2Hm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbfLDIUA (ORCPT ); Wed, 4 Dec 2019 03:20:00 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727437AbfLDIUA (ORCPT ); Wed, 4 Dec 2019 03:20:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447600; x=1606983600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=48fi9iWuTJ5hUDEI3q4s9C6bEGLUNolZCKfPx156Xxk=; b=fAiRl2HmEkPvPSsfjTg6UkzdTX4YfGWRHfPuQIZfbr2d/ZqYFZxk6155 P6uttvGkQPOg5o01ns2k4qPFeVOlYudD+Wct34bCh5cIQqMCzwXLfuX0B E0/t1tucRtr8Vjoka+QOoUSQSUVnr6wn5kBPCkK32d6/YHhSJpV04TshP 7m/EQeXiNrwA0bdSCpLBpZ9SPvAmJgtkMk0Xu/63Mxe/NXzRbeeJLUQ7t cU/zi863vVsmuBpj3zMXPMgDHZEZK0sZGOghm5aH/TALoz6WKAA5eFcpR Zqr/gajSEZRDG6VHFYcPUddqhVVctStkJY/706tsGdhjLr+HKDaWTSm6L w==; IronPort-SDR: jH1M2EBLhom67WXalvqt4IirPIdLdX+Oc8/I5vewPdR9keRoNFvzcZnrt8oTtl97im3/medZvi VWiwYRyVfh9sjbHSsA28OrjktEf1Ij+wpKehtUUf68xbxqf7kYN0ag+lFBl86inWj0vp9JPGQ9 53Rd2YpVvEPhhB0NtaYu5DcVYJjHHzRs/SImQprc+Inka5zmM+/Dm4WODu/DlrrHgYnanBnM+U K4+rfVN74b7csxuyecXmOQHKQ6BxPa2yj0ThCr3AQ4GOw+REVlwNx2FrU75h/JRKD3zTan9GLY 83g= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355094" 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; 04 Dec 2019 16:20:00 +0800 IronPort-SDR: 8gxPzSkdqNGV2P+V4szZ6DSeexTt/ncjBitIXeYa/soz/XEVdfzCte+uQpXD/JtliUXpToVRPI ixqVyAoJba0JzPZ8BPx4gTqdVWEtjubJQXgIFJedvJ3R1g6oQaG5SpGDdQjBvQm7valM2i08yP 49LCgslPlAliNLfJRRMPdKuvKuyzlwvOgepP84NztcGOdv6gtLhw7oWcBqOMg+FF0rXWrcTj5B aK/49gZgm8IDalLud47JFG4RWzDZSJ+uIYqTlSO+Nb3oIzaHuTXd2AXgftkXKYS0C8c/3bu5sK pGPNgPjtfAx9bRIEQo/RaS/F Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:25 -0800 IronPort-SDR: lymiCoHnw4iO4+Qe6jL7PiSRV1yyjZ4WMz6XlHiJfl3jX2TdDxc8+/LT0i8Jxv8k5nzc+pzJG0 c/HDGojBG5VrhHbXYz+MGrdoWL6aoyRPtFO5TUNDesnJAHRbea49Ao777RNrpYGqFv1lmJiMTB CEnAQ2SXV6iYQmxAJYDaJQZCVXD35euzi7GtMyQrv9hJk4ND8IvrK2y+Azp0sDm8QFDusHESGg CX+9U5usuwfBTXm55pDAbVliI1KfpItITy6PmQLSNCwCmFOKlIs1jhbaD/3DO+JssAlFV1hJt5 MEw= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:57 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 16/28] btrfs: implement atomic compressed IO submission Date: Wed, 4 Dec 2019 17:17:23 +0900 Message-Id: <20191204081735.852438-17-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As same as with non-compressed IO submission, we must unlock a block group for the next allocation. Signed-off-by: Naohiro Aota --- fs/btrfs/inode.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3677c36999d8..e09089e24a8f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -793,13 +793,25 @@ static noinline void submit_compressed_extents(struct async_chunk *async_chunk) * and IO for us. Otherwise, we need to submit * all those pages down to the drive. */ - if (!page_started && !ret) + if (!page_started && !ret) { + struct extent_map *em; + u64 logical; + + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, + async_extent->start, + async_extent->ram_size, + 0); + logical = em->block_start; + free_extent_map(em); + extent_write_locked_range(inode, async_extent->start, async_extent->start + async_extent->ram_size - 1, WB_SYNC_ALL); - else if (ret && async_chunk->locked_page) + btrfs_hmzoned_data_io_unlock_logical(fs_info, + logical); + } else if (ret && async_chunk->locked_page) unlock_page(async_chunk->locked_page); kfree(async_extent); cond_resched(); @@ -899,6 +911,7 @@ static noinline void submit_compressed_extents(struct async_chunk *async_chunk) free_async_extent_pages(async_extent); } alloc_hint = ins.objectid + ins.offset; + btrfs_hmzoned_data_io_unlock_logical(fs_info, ins.objectid); kfree(async_extent); cond_resched(); } @@ -906,6 +919,7 @@ static noinline void submit_compressed_extents(struct async_chunk *async_chunk) out_free_reserve: btrfs_dec_block_group_reservations(fs_info, ins.objectid); btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset, 1); + btrfs_hmzoned_data_io_unlock_logical(fs_info, ins.objectid); out_free: extent_clear_unlock_delalloc(inode, async_extent->start, async_extent->start + From patchwork Wed Dec 4 08:17:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272333 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 535526C1 for ; Wed, 4 Dec 2019 08:20:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32A012068E for ; Wed, 4 Dec 2019 08:20:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ApLqcywE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727453AbfLDIUD (ORCPT ); Wed, 4 Dec 2019 03:20:03 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727435AbfLDIUC (ORCPT ); Wed, 4 Dec 2019 03:20:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447602; x=1606983602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fQova5fCa+QqHXMFjuyqIKWvJWmoO6qkos/hzGf3o5o=; b=ApLqcywEDS9U6KVTmu9khC7jBaBbrvcqc92Ox3O+izABcGv2LLAfQLHW TRbk2om/kpMUYTUADcuXOPfw8FTWnHVM62UkydifBKw0d/kkoiUpSIFl4 ufeGk9lYJGErEx43MM4hztplum8pBYKdkLIQWPD34rxLX2ZenPjhklodx oHNAaTT9xjuOzCnzT31ZZ38ycgu2blSPeomjS32yDcWxZqDjBvWrmmxTW 7tBabot/6XuDWzwlLwmrrE8HzVJdWlUuQfcRKrfa4gypiI5apbmgf5J78 moyovRXekvG4d7zkRJpRp4kzj4vsZ2trMpzXP5bgq0zd8F8lsuO1ethFM g==; IronPort-SDR: SGagtC+HhGAQz6Dajnczk3XWpM1yt2cvMHiivQuBJeFCnfLEL3OZHPQkBh3xlEGO39Wf+ChFOJ QulOqV6sNEg27zBjivQOGA1SfDct9/ZDgltGHKRkU0603cWec3EpWyPAei90lpcuza/PyMiKo2 bPdOoK/wMpMwbhLnlIXavQwh4A0ly8Usd2VAlZHH88SN7j4Mbu9K5QR7LMWn52V9S3TBE2B2Af sK+zWbM49P8z4vgRD0YqEKVtkMGDgmjDVOcMXb7LrN1/aSumWasKww0DUi3UV+2MnbTcFWaLkX OuQ= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355095" 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; 04 Dec 2019 16:20:02 +0800 IronPort-SDR: 8vGOsrbZbrkzpIuHXp67OxFdgCXwbWHmkn2gc0a8qxP2diiAi8CwTVgRYIN7R2YxfiTwNKezw5 kTB7utmJdgmE2Hqpo6LjwSowazB8ogcc+X5CfIyGS5hccKpjJgrpiAgVepJ1HzGEfDfI7DMjNV GjOI0WWhUlgDcaxHNuexz43P294YENWxSUUyhEV7PyDEXQz4HLf5xGbHjg36fD9/Y9jvusC4m1 4HuJIilrR9xXb8F7jzqU0WQHHvYi+WDn+mQZGQIQtmVbq1EXfFjqeyVQtHmg/3yOTLTOCV23RQ DdYf4wRT0MryZpiB5AJVuZAE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:27 -0800 IronPort-SDR: 4J396UrE7jBEbzgc5Gr8/NsLrROGqFVn2R10gVdvWHd4KRu8eqGdl2P9vGh0wHGREohIGDN6Ah 8JcAoDKqzqELIM9iBOa6cmjI5f9cKwQAtfXMJc4EDQ2eC4StTESQpaINcx0jMiLwSpGuoiESaZ 9WjxQRXarBR84xAN8CrBtvl0MisRtC0zDR0F4iop5/zsIDKYwL/Lm6c+kls+fbO3ozXB6JsCL/ 0GmAcQzH6z+QH2D/kmRRP/tFGLKR6UEphbTm/PJxDQQPn5seWVe7qppiyFbxMjtXJwToaEXBht 6pc= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:19:59 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 17/28] btrfs: support direct write IO in HMZONED Date: Wed, 4 Dec 2019 17:17:24 +0900 Message-Id: <20191204081735.852438-18-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As same as with other IO submission, we must unlock a block group for the next allocation. Signed-off-by: Naohiro Aota --- fs/btrfs/inode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e09089e24a8f..44658590c6e8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -60,6 +60,7 @@ struct btrfs_dio_data { u64 reserve; u64 unsubmitted_oe_range_start; u64 unsubmitted_oe_range_end; + u64 alloc_end; int overwrite; }; @@ -7787,6 +7788,12 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map, } } + if (dio_data->alloc_end) { + btrfs_hmzoned_data_io_unlock_logical(fs_info, + dio_data->alloc_end - 1); + dio_data->alloc_end = 0; + } + /* this will cow the extent */ len = bh_result->b_size; free_extent_map(em); @@ -7818,6 +7825,7 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map, WARN_ON(dio_data->reserve < len); dio_data->reserve -= len; dio_data->unsubmitted_oe_range_end = start + len; + dio_data->alloc_end = em->block_start + (start - em->start) + len; current->journal_info = dio_data; out: return ret; @@ -8585,6 +8593,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, struct btrfs_io_bio *io_bio; bool write = (bio_op(dio_bio) == REQ_OP_WRITE); int ret = 0; + u64 disk_bytenr, len; bio = btrfs_bio_clone(dio_bio); @@ -8628,7 +8637,18 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, dio_data->unsubmitted_oe_range_end; } + disk_bytenr = dip->disk_bytenr; + len = dip->bytes; ret = btrfs_submit_direct_hook(dip); + if (write) { + struct btrfs_dio_data *dio_data = current->journal_info; + + if (disk_bytenr + len == dio_data->alloc_end) { + btrfs_hmzoned_data_io_unlock_logical( + btrfs_sb(inode->i_sb), disk_bytenr); + dio_data->alloc_end = 0; + } + } if (!ret) return; @@ -8804,6 +8824,11 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) btrfs_delalloc_release_space(inode, data_reserved, offset, count - (size_t)ret, true); btrfs_delalloc_release_extents(BTRFS_I(inode), count); + if (dio_data.alloc_end) { + pr_info("unlock final direct %llu", dio_data.alloc_end); + btrfs_hmzoned_data_io_unlock_logical( + fs_info, dio_data.alloc_end - 1); + } } out: if (wakeup) From patchwork Wed Dec 4 08:17:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272339 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB8106C1 for ; Wed, 4 Dec 2019 08:20:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEFD12068E for ; Wed, 4 Dec 2019 08:20:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="bTMNA4F3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727460AbfLDIUG (ORCPT ); Wed, 4 Dec 2019 03:20:06 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727435AbfLDIUF (ORCPT ); Wed, 4 Dec 2019 03:20:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447605; x=1606983605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ciqj1oCL5KqUdvZbziaPfAt/t1dmYyxBglSVY3FHISw=; b=bTMNA4F333JjaZUx3u/m/3x1I9RWZ8mTXFo4pb+WgSEM1G2VukBFmTQ+ vgd9P4HGQzyoigDZrLuCF8iumm15Eca6U3xtisTfP5Kh+/2wm9mDdkMVG ap/JkqycJs9yqzVpDAZVAHpifIiGamhEo3NQvQysrfjSKh17WQWnNOl8A PEj6X/hobDWDZp1i3IvO8n8XSRq8bfABl64DFedI5rqksqakL++tLHl8t h2IkBEWtOR5jVdUIRG2k3CjhxR6TPqtEau5eRmgQoCOa7eOi/tEGDmB2i igIrtTg1F8Qeou2g1DrnHFX9BsapHD8jFlN5Z9Lo/v/3QnoDYx6PterJj A==; IronPort-SDR: VeOBzkPrJID8sKHAs7pV5GgNq9WVEn+n4OgFIVDRhJyDQ1iH55CY2lt/56IzmtGFOkZvLVLCFY JYA5gVnnfJwS2D3BKBt2jMoXTzY6Z/HRm/GjM62Of9KKKFHdTa/D12OKr2YRXoWwemZA31ByiV 8dycCatnqxrx4eGnfbV5I5AEDHd+5Zn5nsEVBaV5sSOrVaQn8BM+k6T0xmGiUq+M/jtO8uapW3 b6E5EfDuTPEPW33sx9RJDB+mr2Cy7Fy6usyf1LkGKJZoWDDrcS9TrYAevzF5wwzi67sWwL7wlV g8I= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355097" 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; 04 Dec 2019 16:20:04 +0800 IronPort-SDR: 5R9YSsfSRClpkraFTKDXojOYEkXahHALa743vnKYnI6Zg+skGdsQsdBKEfmKgFW4Keczj7hXil FRRj+An8R/BtqKfDPu3UZ9YxxWj4NTB+9squYUXNYtmThxK964CtEILZk6ldGVmHQHOqi+x1Ie SwnAR05jO/VNxLqOKTXgmnRK9v6Tu4llW5h/8v39LQiJBaf0btTnR8VbAU819OCpfFkqKTrVqG YJc8UKobwlsp09yuwaIi59ctiKLojED3hgUdPHxWvWCYtZN8r+o0v5mLobUTUMPXtWGuaE6C2R l2NCX534CmfuGeofH0xhgwrF Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:29 -0800 IronPort-SDR: 4C48g2bSGT8qcFhyX4sG4jy2UOPWseEyn3rdjmwDvxqAkpp/Alg96Z0D2IwcY/WgOqsBZlTTxs 7kigIe0VRmIKGFxpZaRcaxwHAD7nGFT9CI1Gtp4t5YeIG17rfxatFNMT7QiMaHUS02nMc8PJZH Hj9fvx0XpUm7ko5RUPkIuCCKOG7oEQiMMsnSbpON3gRLYzo+Ej1EjFew/WDMtsbcDb0xPvKcyd rp2jbj0o3R3JbkvbAhUfzufH2vyumuQndGT7LGUGhlzDBrpGZ+xPwY4D500QIr6nsudbrsIJPx IVo= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:02 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 18/28] btrfs: serialize meta IOs on HMZONED mode Date: Wed, 4 Dec 2019 17:17:25 +0900 Message-Id: <20191204081735.852438-19-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As same as in data IO path, we must serialize write IOs for metadata. We cannot add mutex around allocation and submit because metadata blocks are allocated in an earlier stage to build up B-trees. Thus, this commit add hmzoned_meta_io_lock and hold it during metadata IO submission in btree_write_cache_pages() to serialize IOs. Furthermore, this commit add per-block group metadata IO submission pointer "meta_write_pointer" to ensure sequential writing, which can be caused when writing back blocks in a not finished transaction. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.h | 1 + fs/btrfs/ctree.h | 2 ++ fs/btrfs/disk-io.c | 1 + fs/btrfs/extent_io.c | 27 +++++++++++++++++++++- fs/btrfs/hmzoned.c | 52 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/hmzoned.h | 27 ++++++++++++++++++++++ 6 files changed, 109 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 57c8d6f4b3d1..8827869f1744 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -166,6 +166,7 @@ struct btrfs_block_group { */ u64 alloc_offset; struct mutex zone_io_lock; + u64 meta_write_pointer; }; #ifdef CONFIG_BTRFS_DEBUG diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 44517802b9e5..18d2d0581e68 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -905,6 +905,8 @@ struct btrfs_fs_info { spinlock_t ref_verify_lock; struct rb_root block_tree; #endif + + struct mutex hmzoned_meta_io_lock; }; static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index fbbc313f9f46..4abadd9317d1 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2707,6 +2707,7 @@ int __cold open_ctree(struct super_block *sb, mutex_init(&fs_info->delete_unused_bgs_mutex); mutex_init(&fs_info->reloc_mutex); mutex_init(&fs_info->delalloc_root_mutex); + mutex_init(&fs_info->hmzoned_meta_io_lock); seqlock_init(&fs_info->profiles_lock); INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 6e25c8790ef4..24f7b05e1f4c 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3921,7 +3921,9 @@ int btree_write_cache_pages(struct address_space *mapping, struct writeback_control *wbc) { struct extent_io_tree *tree = &BTRFS_I(mapping->host)->io_tree; + struct btrfs_fs_info *fs_info = tree->fs_info; struct extent_buffer *eb, *prev_eb = NULL; + struct btrfs_block_group *cache = NULL; struct extent_page_data epd = { .bio = NULL, .tree = tree, @@ -3951,6 +3953,7 @@ int btree_write_cache_pages(struct address_space *mapping, tag = PAGECACHE_TAG_TOWRITE; else tag = PAGECACHE_TAG_DIRTY; + btrfs_hmzoned_meta_io_lock(fs_info); retry: if (wbc->sync_mode == WB_SYNC_ALL) tag_pages_for_writeback(mapping, index, end); @@ -3994,12 +3997,30 @@ int btree_write_cache_pages(struct address_space *mapping, if (!ret) continue; + if (!btrfs_check_meta_write_pointer(fs_info, eb, + &cache)) { + /* + * If for_sync, this hole will be + * filled with trasnsaction commit. + */ + if (wbc->sync_mode == WB_SYNC_ALL && + !wbc->for_sync) + ret = -EAGAIN; + else + ret = 0; + done = 1; + free_extent_buffer(eb); + break; + } + prev_eb = eb; ret = lock_extent_buffer_for_io(eb, &epd); if (!ret) { + btrfs_revert_meta_write_pointer(cache, eb); free_extent_buffer(eb); continue; } else if (ret < 0) { + btrfs_revert_meta_write_pointer(cache, eb); done = 1; free_extent_buffer(eb); break; @@ -4032,12 +4053,16 @@ int btree_write_cache_pages(struct address_space *mapping, index = 0; goto retry; } + if (cache) + btrfs_put_block_group(cache); ASSERT(ret <= 0); if (ret < 0) { end_write_bio(&epd, ret); - return ret; + goto out; } ret = flush_write_bio(&epd); +out: + btrfs_hmzoned_meta_io_unlock(fs_info); return ret; } diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 169ef8a35cba..ee9d9cd54664 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -1072,6 +1072,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache) } } + if (!ret) + cache->meta_write_pointer = cache->alloc_offset + cache->start; + kfree(alloc_offsets); free_extent_map(em); @@ -1174,3 +1177,52 @@ void btrfs_free_redirty_list(struct btrfs_transaction *trans) } spin_unlock(&trans->releasing_ebs_lock); } + +bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, + struct extent_buffer *eb, + struct btrfs_block_group **cache_ret) +{ + struct btrfs_block_group *cache; + + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return true; + + cache = *cache_ret; + + if (cache && + (eb->start < cache->start || + cache->start + cache->length <= eb->start)) { + btrfs_put_block_group(cache); + cache = NULL; + *cache_ret = NULL; + } + + if (!cache) + cache = btrfs_lookup_block_group(fs_info, + eb->start); + + if (cache) { + *cache_ret = cache; + + if (cache->meta_write_pointer != eb->start) { + btrfs_put_block_group(cache); + cache = NULL; + *cache_ret = NULL; + return false; + } + + cache->meta_write_pointer = eb->start + eb->len; + } + + return true; +} + +void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, + struct extent_buffer *eb) +{ + if (!btrfs_fs_incompat(eb->fs_info, HMZONED) || !cache) + return; + + ASSERT(cache->meta_write_pointer == eb->start + eb->len); + cache->meta_write_pointer = eb->start; +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index f6682ead575b..54f1affa6919 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -50,6 +50,11 @@ void btrfs_redirty_list_add(struct btrfs_transaction *trans, struct extent_buffer *eb); void btrfs_free_redirty_list(struct btrfs_transaction *trans); void btrfs_hmzoned_data_io_unlock_at(struct inode *inode, u64 start, u64 len); +bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, + struct extent_buffer *eb, + struct btrfs_block_group **cache_ret); +void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, + struct extent_buffer *eb); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -120,6 +125,14 @@ static inline void btrfs_redirty_list_add(struct btrfs_transaction *trans, static inline void btrfs_free_redirty_list(struct btrfs_transaction *trans) { } static inline void btrfs_hmzoned_data_io_unlock_at(struct inode *inode, u64 start, u64 len) { } +static inline bool btrfs_check_meta_write_pointer( + struct btrfs_fs_info *fs_info, struct extent_buffer *eb, + struct btrfs_block_group **cache_ret) +{ + return true; +} +static inline void btrfs_revert_meta_write_pointer( + struct btrfs_block_group *cache, struct extent_buffer *eb) { } #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) @@ -254,4 +267,18 @@ static inline void btrfs_hmzoned_data_io_unlock_logical( btrfs_put_block_group(cache); } +static inline void btrfs_hmzoned_meta_io_lock(struct btrfs_fs_info *fs_info) +{ + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return; + mutex_lock(&fs_info->hmzoned_meta_io_lock); +} + +static inline void btrfs_hmzoned_meta_io_unlock(struct btrfs_fs_info *fs_info) +{ + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return; + mutex_unlock(&fs_info->hmzoned_meta_io_lock); +} + #endif From patchwork Wed Dec 4 08:17:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B57D26C1 for ; Wed, 4 Dec 2019 08:20:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9424D2068E for ; Wed, 4 Dec 2019 08:20:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="L/UWg0pN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727467AbfLDIUH (ORCPT ); Wed, 4 Dec 2019 03:20:07 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727435AbfLDIUG (ORCPT ); Wed, 4 Dec 2019 03:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447607; x=1606983607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wD/L2N6Pr/GUhfnWh9kOAQLWKs9x/iWk54ItmaVu6NM=; b=L/UWg0pN9/uzeL4ToLZGPzMUDttMh3wFmFoR5lp4mlw7945HaeRvQ55I IRViboWqGRiGvijw2ewGjpbis67Hfpeb+RGOwhmcXTQ2gX8SwtI95Oypu VQwKDvaEGANSGEzXVrD2ABrb8RUGN2nk8uv2Kr9khdxfPqwTkhdofYqRR ksdvAfErfRuR4Ixz3Fuo8RHUP+DS+B89AL2tDrtcWVxVnbWNDdhef9+xS 1c7htEGQrQVzILloNL/i88zvNvNsEyw/7LmJPMvP/j4+kQYtMm5Yfs0Sj A543KbRwtpyFQRH4oWYydqt3w/WxkThPF/XzUI8P6WoXwtd7ggnrzonvJ Q==; IronPort-SDR: RQeP76jJPURHoea3UXt3CLLmXDxfNyaCT1bEZZyjtNO+vOPXYPBJNU1rDK3yfv0GQv6qIjyaf0 0ELlzkBMhnv2Jb9LjzJm8NpNtOfn/EHsw7plCBsUIf462q/UDbKhPsfcZ1bcXkLSB1Z+HFWPYA PC2vJAmak+Yru5lFkTT0ThdpBbB4ZzN45g80cwHqvBdz2yHBr6V4ea8/odxFiijVO5xdol6wG/ Qd/W4oGLoHTAO4eiT41b1Jl+Th/ntW82uPiy9JIeRA2jpj89/Nf2AaGTrJDmtfbnnNWxFhy/Rb F2c= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355101" 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; 04 Dec 2019 16:20:07 +0800 IronPort-SDR: 8pi8bLtELeEA0kyAuN+GsoAQNFiae+WzEpvMAy/rEHBljt2Op65Mip0cdZPr1qlZZuaA5V/CgM q2SyKNTGgZg4l4edlkwjvsDQT3Gp5fiMdpBfY16Uchwah0Q1gesj70IwEKUajX0N611Or9bfM/ YM1jg9HR70VI4BsOjZAKvOzngLBwYO2RJk4F3FOQmF1kZDHcmSP5GQPW7CqpDOWWhnWOPQA9V9 IY8kPqfVnlRssIf9YAhjhF02SODnkCj4XOO/LIP/8Awr6bodcUeHFY3B81i0gGQyCyBpnsEnOP GDRFgdXGS4fIYSc/uUhwQxXB Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:31 -0800 IronPort-SDR: +Y4a7R0qFZnE6UyOAlpKIcCUqzBllyMi3UU2Mhcc84hCZoA3ky+WqaKXLFlTUHMYoJ6CmoFWnM 6S+QXa6jbI4axHXoWyIYVw12be/xOPphvMkxs2VhmL6jeOaWHtUA+ry28N2/6q4s5hHZlJCodi kdTnIw8nXoR/s3fsYts7H1MS2H34sfUEa9wyHVIOvTVTZbqZl1bBiAPsVCq4HkiAcDFA+USKHH SgLckHT6o7FDf17HRIzkvkwxrffXDmTrZC4Xvl3MDn8wJQHeh/tPk+5hrTWhqjxLdRseXz4NFk uuM= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:04 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 19/28] btrfs: wait existing extents before truncating Date: Wed, 4 Dec 2019 17:17:26 +0900 Message-Id: <20191204081735.852438-20-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When truncating a file, file buffers which have already been allocated but not yet written may be truncated. Truncating these buffers could cause breakage of a sequential write pattern in a block group if the truncated blocks are for example followed by blocks allocated to another file. To avoid this problem, always wait for write out of all unwritten buffers before proceeding with the truncate execution. Signed-off-by: Naohiro Aota --- fs/btrfs/inode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 44658590c6e8..e7fc217be095 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5323,6 +5323,16 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) btrfs_end_write_no_snapshotting(root); btrfs_end_transaction(trans); } else { + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + + if (btrfs_fs_incompat(fs_info, HMZONED)) { + ret = btrfs_wait_ordered_range( + inode, + ALIGN(newsize, fs_info->sectorsize), + (u64)-1); + if (ret) + return ret; + } /* * We're truncating a file that used to have good data down to From patchwork Wed Dec 4 08:17:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5056F17EF for ; Wed, 4 Dec 2019 08:20:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E27520675 for ; Wed, 4 Dec 2019 08:20:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Tpf884GX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727477AbfLDIUL (ORCPT ); Wed, 4 Dec 2019 03:20:11 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727435AbfLDIUJ (ORCPT ); Wed, 4 Dec 2019 03:20:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447609; x=1606983609; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gv9q0DDDj86eEUSslQJev/ik3Quaqy64bmbJlpcYfcY=; b=Tpf884GXdIh3ncZQ1PY/thhFyx7Lw1YdAUeDt+zNm4ywGjjV4wZ4K/Bj 0a4Kdp8xJcCtVfM1PQKEbsf9O04zkoyrd+EdWWJgm4JmZC0TqzK9zQix3 gEPkFYzyCQL//TrLuqWhv3YbsrGFpCVReTqELomiWmGb4SPq0WBgYbqcb QnZOIKJVjI0UlDJ+0R3chtpWO2M0Ey9zAztjR0ek9HW7BeuRdAsEqPeP1 wgebhsvxEStVAN5hVp0XVKC1xSMOGPjrpXNJ0d0fxYgL3QPpJRmkhB541 cndGbR6D8lgLuu4KVeVfIURLqguHOvjxv24YB5wK01BMwdWz5EYN7GeMb w==; IronPort-SDR: xVQrUn/3icwv1zCIjgJkhafzza5StsCy1gEUX9Y8cCp3wqKnrur/sVq0tdwWT7h8JCIQgdsjKH rQONtpqda5iIqZ6R+iXcgWiUfEo8/ITHRcSremhb0L0CHRrFfWEL1KSCNN/WfFPtraTWZkUj26 HYM+QrjGNNCGe8qiklI0+fipuIePiwGvn9UIvUUX0PjnNPFK+TPL8ctDKTdbwn13hv+2DDrIZg T5YIkjXhu8uCapH0p7R/izWuXce8aw3kkB1D9TbS5M2VXWD2napza+kUR3tYlHHW/XXJ1AOpCF XJ4= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355105" 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; 04 Dec 2019 16:20:09 +0800 IronPort-SDR: bFgcRCFJoh6ooYnyEurHJdHf68ZvToX8rIPf8U9DSQciTlvlpti7KPnBi+uDG73mecHRiB9X/J ARa0DQgTEjQ4Xc94hDKueqV6YQHquKdGEsK8FUDFqmzw6CfnbsNqVwGCTWUp0+46+mDfKf4ajz +GzYwIxEIEbDQWRobmuVmtuyEfBwIncnFQtUQV+fCmnfc6/TX3oM+TKPq6wVjWRXM4uxKw10ul 2llC2asojWqxnuhRx4ixdNhg641Gsrrj1kcbv0DzLPrKYcZfdZS6txz2blPhqkhgCBreOAGrf2 I6na0G+9fu0I1Khrg9dFpQag Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:34 -0800 IronPort-SDR: AcczeqZZEo03vX9756H6qTsbPoG3QSUh2nWNfMfqZ8kKzybnc+Zwp2BApQFTRADGRhruBFBM0r AIEljy1oE1JviZp98m/I4N7DnjJ3ugvFe84AZvIoijLVnIO/fhoOFGptZ5su7hnw2/HO4OGZYk ME81HakcpF+ZDmD/hQrLTvh9CHPvkoHnY/o3PWWxtyID0RDFCsXsnc7xtvDKJQMw4j6ocpWDeV nPGjoIydZ2yXDMI0CilLpbEya17fGvgLwMe4Av0DBioG0QGF6akaR3neVpa5LifDZ/lYtX4tVT WnQ= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:06 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 20/28] btrfs: avoid async checksum on HMZONED mode Date: Wed, 4 Dec 2019 17:17:27 +0900 Message-Id: <20191204081735.852438-21-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In HMZONED, btrfs use per-Block Group zone_io_lock to serialize the data write IOs or use per-FS hmzoned_meta_io_lock to serialize the metadata write IOs. Even with these serialization, write bios sent from {btree,btrfs}_write_cache_pages can be reordered by async checksum workers as these workers are per CPU and not per zone. To preserve write BIO ordering, we can disable async checksum on HMZONED. This does not result in lower performance with HDDs as a single CPU core is fast enough to do checksum for a single zone write stream with the maximum possible bandwidth of the device. If multiple zones are being written simultaneously, HDD seek overhead lowers the achievable maximum bandwidth, resulting again in a per zone checksum serialization not affecting performance. Signed-off-by: Naohiro Aota --- fs/btrfs/disk-io.c | 2 ++ fs/btrfs/inode.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4abadd9317d1..c3d8fc10d11d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -882,6 +882,8 @@ static blk_status_t btree_submit_bio_start(void *private_data, struct bio *bio, static int check_async_write(struct btrfs_fs_info *fs_info, struct btrfs_inode *bi) { + if (btrfs_fs_incompat(fs_info, HMZONED)) + return 0; if (atomic_read(&bi->sync_writers)) return 0; if (test_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags)) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e7fc217be095..bd3384200fc9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2166,7 +2166,8 @@ static blk_status_t btrfs_submit_bio_hook(struct inode *inode, struct bio *bio, enum btrfs_wq_endio_type metadata = BTRFS_WQ_ENDIO_DATA; blk_status_t ret = 0; int skip_sum; - int async = !atomic_read(&BTRFS_I(inode)->sync_writers); + int async = !atomic_read(&BTRFS_I(inode)->sync_writers) && + !btrfs_fs_incompat(fs_info, HMZONED); skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; @@ -8457,7 +8458,8 @@ static inline blk_status_t btrfs_submit_dio_bio(struct bio *bio, /* Check btrfs_submit_bio_hook() for rules about async submit. */ if (async_submit) - async_submit = !atomic_read(&BTRFS_I(inode)->sync_writers); + async_submit = !atomic_read(&BTRFS_I(inode)->sync_writers) && + !btrfs_fs_incompat(fs_info, HMZONED); if (!write) { ret = btrfs_bio_wq_end_io(fs_info, bio, BTRFS_WQ_ENDIO_DATA); @@ -8522,7 +8524,8 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip) } /* async crcs make it difficult to collect full stripe writes. */ - if (btrfs_data_alloc_profile(fs_info) & BTRFS_BLOCK_GROUP_RAID56_MASK) + if (btrfs_data_alloc_profile(fs_info) & BTRFS_BLOCK_GROUP_RAID56_MASK || + btrfs_fs_incompat(fs_info, HMZONED)) async_submit = 0; else async_submit = 1; From patchwork Wed Dec 4 08:17:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272349 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E45B26C1 for ; Wed, 4 Dec 2019 08:20:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3A892068E for ; Wed, 4 Dec 2019 08:20:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="qTfIzgOJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727485AbfLDIUM (ORCPT ); Wed, 4 Dec 2019 03:20:12 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727468AbfLDIUL (ORCPT ); Wed, 4 Dec 2019 03:20:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447611; x=1606983611; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wM+B0/NBtyNeSYyvcUDDv5lBZhJIyM6EuqhnCymFNz0=; b=qTfIzgOJycYF412m5Bj7I+bcezpNF7JnuhkpRII0IiZjteSTcHkvefnz eh6AuaQkjxnv2HG+iKSQ9/8hMHMxsN123RXpbBDhcb7bxZTTxV6FcpIX5 rIhKWV8jP2cQJ4hJI9FbIfScUAg80J9G10qd1xd/Ienr7ErRT7XYQjnlw FE1hiVX34L98G5fdj+Dvik0ZcWMvmCaWeNEDqlBe7Iemi5kOafkwHFCLh 4AR+MMHoAGEXNbhZ1i7ukBPwywE9hKaJ1TNitBrVPGbWOZ/7o2WLYcLbn xMOB3h8/3I2GaMvG/SuLqOWuvmTzt/islfdHqmt8hLoh5jdrlQA+h7YSg A==; IronPort-SDR: vtJA/w1y61P6Okiu82SPlXf8uyRzZ6JZG8MqHVft4Sa1os781CVjBUPpHK0VoNOb/WSreQ3KP4 n1pCYIw7gCHcGyczsa2C/gVFzEitHLAqlvWTTMG+Hc5QiLl2cJ8CagZJZd1HSM7K15BsEG4teK 7hub+u4Y3tt1WPV3WXhY63p//TkMgRybKNzcCODT8tHi2Nl0gYuOn6Y8sMWE9cI2dyrMqBm7aK SaBakj8L8ItSXFIIdLvXRFbh+YctPU3TeCV+wPLwj/H68bbrWi89wYRy1Zc3NKb6Z65dfo2qIn Ues= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355106" 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; 04 Dec 2019 16:20:11 +0800 IronPort-SDR: IpDogbzwwAyKWAZMxcqnRI3WN+ks5hs7yyryhdKNu/weClGSMG7XyCQA9X4+rbtJH0DMnEQ7dB 2YjLMerYw46eFaf5p0V2C/Q2HhNeNRxdC5uSn8h9K0LQQowjGirv+6IbKGA/8ldWUMDjaMjU7Y kQE4JopzAC+AaMm7swrRAo+Q0SNWMsJZNO+wipmIVOQAyNs1xYdUtcmXZk4YYBvKK7eIgg/YpR wu6BG2P7pHYhU6uHD8zX4B8MAQsPVmh4qsk5+sB12ZPKlwTHRdMZnpTzKUCWPSYNhdEdsGiRu3 +/KjzbuGF6A0qo4gUYaR5mjZ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:36 -0800 IronPort-SDR: 7l5s7htt58Vmo8tVXvKjG+T6+hNLlLCZmv0Ppavy70bI2Cqc6HcCXzIhw9OO6HITjaEPFlysll T1cdCPc7pjrGKyJFsX2O/chncZP5xKB9wg5boyi65su9n3p2sJbJn6eHBbDbk+LqNEyCvUubjS BCz3GHZbHaqSziiCnUi2s81G5Bbpl8p12g2Kvy+J8WtAXElmPXFiRfREnwqA1EPtqRd02fF1s+ ICg67AVpcsLf/RuuSLdFY8otRTghMNB1JRiSiikusHdd64iIvRX//Qzu/kiz7Ymq+wSkdL0UHm iy0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:08 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 21/28] btrfs: disallow mixed-bg in HMZONED mode Date: Wed, 4 Dec 2019 17:17:28 +0900 Message-Id: <20191204081735.852438-22-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Placing both data and metadata in a block group is impossible in HMZONED mode. For data, we can allocate a space for it and write it immediately after the allocation. For metadata, however, we cannot do so, because the logical addresses are recorded in other metadata buffers to build up the trees. As a result, a data buffer can be placed after a metadata buffer, which is not written yet. Writing out the data buffer will break the sequential write rule. This commit check and disallow MIXED_BG with HMZONED mode. Signed-off-by: Naohiro Aota --- fs/btrfs/hmzoned.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index ee9d9cd54664..1fdc5946715a 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -311,6 +311,13 @@ int btrfs_check_hmzoned_mode(struct btrfs_fs_info *fs_info) goto out; } + if (btrfs_fs_incompat(fs_info, MIXED_GROUPS)) { + btrfs_err(fs_info, + "HMZONED mode is not allowed for mixed block groups"); + ret = -EINVAL; + goto out; + } + btrfs_info(fs_info, "HMZONED mode enabled, zone size %llu B", fs_info->zone_size); out: From patchwork Wed Dec 4 08:17:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AECF6C1 for ; Wed, 4 Dec 2019 08:20:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A1CF2068E for ; Wed, 4 Dec 2019 08:20:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NIiKh+GL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727489AbfLDIUP (ORCPT ); Wed, 4 Dec 2019 03:20:15 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727272AbfLDIUN (ORCPT ); Wed, 4 Dec 2019 03:20:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447613; x=1606983613; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/19Q0PhgS90q+im5kYYWHaU2pK5prWUE7U1i/KWl9dI=; b=NIiKh+GLaETpioFg6E7HS34a9Wo6ee2njBfiU0MSwxJU8Y0J1NaPcrwi Bwlbp2JtI6Oq8ITvZMiC09jsn6UNSHiZvgj4ldsW0wG2Z+ZzFUH5vucBM fUNhSWVCbwPIUePNb2U9gJGYcTEpTFp07CYwkxr8xuVJJQWMMGyZqhpKN EH9tMObcqTDA/FiC1xCqF+OyZfwwDr+reBjlv5cm8IChsQxvlxKRyH9nU ssyK06ax89/Xoe15y3QDKSAiB9SljEyi3ohLbc9FPBas1g12p3klsDrMS vD/E++gIgLANuL/fhS7PRZ4uEpxpD/xmzefKClQ9fb7rZ5TZwyRtigXBv A==; IronPort-SDR: 1Vr81wcylnfVJqvVfg8VcjQfeyfxn2PEh9n87Zh9B2bPWfg13E3gZnaq2PmvI2Fmmkztb1ttq+ J3K1hVczrlRZHUBHTFeOtNPciNiuTVE/uRyXD15tyQUD4F4hXuSGJYUXJwFWRoqGNxTMCB3xBB 52PElA5sBmAt6+5bIFjYVBidWa3FjsS0Cw1qOicB2j1ARPDSpxucMb3Gdn6f03DkFgpftNHIAv NjHJh4InEnNxHlZA1cN+cuycl5feQsMO7IF43+cHv0IjirCqLqV4CM/aLgHSJx2O+cnTasQdhw Oro= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355111" 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; 04 Dec 2019 16:20:13 +0800 IronPort-SDR: 1idgBIE+tIBdaBuY11IryJrcBxB4BBa/atPB/yyiRUKZF1G0WndYMv8Boif45mogOuIUc7w5Rm vaZrhaIVUOXe8DWkwoI1gJoSohbUTBrheqitsjNiLYDD49+fzetbo+JXfnu0Rzp+BD8o7m4JZg 5XBxr1H2DYLPcukL0gphvBEel9vXyOl7qMw2XWIT9wC1ifRdnUTN6Mmer28+tGMB7F1r95NcMX HOJzlwmks1DSaqQuNy3oKeAOZrDu4lSQQkEjGwEZkHRr6hDqfVicEppB4xLtBivh+zlygsbDpT gybtnP4AzfV7+x6aOS5H2e6d Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:38 -0800 IronPort-SDR: i2syMJO2RLKQqx/IeVJMCVgiTuyVVdNSHWYR2/noR+QxYVE8mxG6OY2Gzr6S1vvsbdrzVASke9 CTtxZuXq/+c18lI5LmuAStoZon0jXF7+E8bNWdzv5l9RCA3Q+11Nuke7U6aY2UPaDUwVvXYuSt 2PuqiNZE800d8BLqpWG5uPrsyY6Q3J8TRe+JDQhhlySgw2w909HZVDk1RogeoFRQ0LU5DHuEmp pV7JIVEqnGrWkWmfn9eVcbHsdErd3r8P0Fc12d39y1i8ll1vFTuUD5fkb8a6+k9L/+lUtFwxTU Cbk= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:10 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 22/28] btrfs: disallow inode_cache in HMZONED mode Date: Wed, 4 Dec 2019 17:17:29 +0900 Message-Id: <20191204081735.852438-23-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org inode_cache use pre-allocation to write its cache data. However, pre-allocation is completely disabled in HMZONED mode. We can technically enable inode_cache in the same way as relocation. However, inode_cache is rarely used and the man page discourage using it. So, let's just disable it for now. Signed-off-by: Naohiro Aota --- fs/btrfs/hmzoned.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 1fdc5946715a..55530782c1b1 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -345,6 +345,12 @@ int btrfs_check_mountopts_hmzoned(struct btrfs_fs_info *info) return -EINVAL; } + if (btrfs_test_pending(info, SET_INODE_MAP_CACHE)) { + btrfs_err(info, + "cannot enable inode map caching with HMZONED mode"); + return -EINVAL; + } + return 0; } From patchwork Wed Dec 4 08:17:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7B1D17EF for ; Wed, 4 Dec 2019 08:20:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ABCF220675 for ; Wed, 4 Dec 2019 08:20:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Kp6jCMSZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727494AbfLDIUR (ORCPT ); Wed, 4 Dec 2019 03:20:17 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32779 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726217AbfLDIUQ (ORCPT ); Wed, 4 Dec 2019 03:20:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447616; x=1606983616; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qzq6R7eigVoSGVvXFRm66Itm4o4QQDnnFA53lW64zh0=; b=Kp6jCMSZUlDA6ZFW7A5Cx1zJNWetKvtLT01SBuNHfQgVUTylGxGelcGT W/ev6h3E9Rcms6rxHtT2f6PFLamzT4/mmE/SeSmPnymdK41VDlU6X+z0I 96dy9Fuxofc/qTasXaCc69hDmcJqsKE4rvQUSa+7W9HDLov8ocDiMR+tM ydhU5L6D3kT2yykXCXnkT29MHFHcuXm01J2jZdPBNb4JOgYsf2//aHDL6 deQGX2etxWHYTfhqhV4D6NzI+4jjMzocpzVkPlvUZek211WrW2HqNZiaf DWUWOhcMDhGQPtVWGDyYitIyXNr2Auuxp3q9b/zEzkqIqyqWtN7E75nZZ Q==; IronPort-SDR: Tp/3pCeYOdu8zWDuvUEDh0EBHUXWq0PNpOD2p+WbdsmmT+/Bm7uUyemMGagUx23tKzLEG+vAhO fnJrxRYA2n1nMbKHcaWtQLFj6x5DQ9l4354QDAYCCtTiJOJrk/Cj/uLii9xZmQxY1OlmAeiIA7 2x1Rrq2F30+7bLmHrOy7VGyAir/qDooKDIL76hoBgcB8ZT8UdildYxig6UKGFTTDScZI9Ovt4X WDqQoSl6naJhztt2QnyvU5PdmiWz1aorEZOdIfDtdSVFZOawqjmpyRan74s7HoGeYkxAK9c96y SSI= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355115" 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; 04 Dec 2019 16:20:16 +0800 IronPort-SDR: 40Kd1SGzRSminTpSL0mH+hEtFdsTc3Plt9t/UTm9n7R0Yd30CbR96rTEjPhhtp6jYlhBADjXL2 BUaowjJ459JIbUaHpade94g9yi2D4lUebCkUYL0IU9ah0mzSJguxxKoJ7/ijFqYNl+K6+jHm4Q mkERj+aJwnZrs9FuBzj3gyLG725YclYQjjW+WH3oEEacbdmrPjGDMIjzBi6gyGJQVB/6sb6qZi +JJwskqkjz83gqB2whuaQkxOAcc0RddAJFtaxqnMGmazIFC7UfucXy+eIZyjiHSstF3wcjVKtw AkKe47qA9htC1h1ba3EBfQBu Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:40 -0800 IronPort-SDR: nP1RrEcAB42F3/wVp5F+eYWVlvZNZc4WFgBXwwh2id9iH5EekfB7Jqn8gOdNj1wwfnDP+5vbfh B2L4iPHLnpdzUNoTKaFLwOMXjvKJoOdBIcH1f9vqOCpCHJgSFzB0kJbRy+7RuqcqQWGHI+AuDp Pvh2zrwjfWJrztj+8TmRuL8znse5hv9NhKcJN+mKfNJDq+b/HPS75o64KbNtatozxBh7UjnWf0 IMBsGLP8EIm8EViowlMPieCWiKoZ57OcjX7saf6+3ODIbzf5bzownCktuh+GpOWThLyhyaOHQK hxM= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:13 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 23/28] btrfs: support dev-replace in HMZONED mode Date: Wed, 4 Dec 2019 17:17:30 +0900 Message-Id: <20191204081735.852438-24-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have two type of I/Os during the device-replace process. One is a I/O to "copy" (by the scrub functions) all the device extents on the source device to the destination device. The other one is a I/O to "clone" (by handle_ops_on_dev_replace()) new incoming write I/Os from users to the source device into the target device. Cloning incoming I/Os can break the sequential write rule in the target device. When write is mapped in the middle of a block group, that I/O is directed in the middle of a zone of target device, which breaks the sequential write rule. However, the cloning function cannot be simply disabled since incoming I/Os targeting already copied device extents must be cloned so that the I/O is executed on the target device. We cannot use dev_replace->cursor_{left,right} to determine whether bio is going to not yet copied region. Since we have time gap between finishing btrfs_scrub_dev() and rewriting the mapping tree in btrfs_dev_replace_finishing(), we can have newly allocated device extent which is never cloned nor copied. So the point is to copy only already existing device extents. This patch introduces mark_block_group_to_copy() to mark existing block group as a target of copying. Then, handle_ops_on_dev_replace() and dev-replace can check the flag to do their job. Device-replace process in HMZONED mode must copy or clone all the extents in the source device exctly once. So, we need to use to ensure allocations started just before the dev-replace process to have their corresponding extent information in the B-trees. finish_extent_writes_for_hmzoned() implements that functionality, which basically is the removed code in the commit 042528f8d840 ("Btrfs: fix block group remaining RO forever after error during device replace"). This patch also handles empty region between used extents. Since dev-replace is smart to copy only used extents on source device, we have to fill the gap to honor the sequential write rule in the target device. Signed-off-by: Naohiro Aota --- This patch must be reworked once "btrfs: use btrfs_can_overcommit in inc_block_group_ro" is applied. fs/btrfs/block-group.h | 1 + fs/btrfs/dev-replace.c | 178 +++++++++++++++++++++++++++++++++++++++++ fs/btrfs/dev-replace.h | 3 + fs/btrfs/extent-tree.c | 20 ++++- fs/btrfs/hmzoned.c | 91 +++++++++++++++++++++ fs/btrfs/hmzoned.h | 16 ++++ fs/btrfs/scrub.c | 142 +++++++++++++++++++++++++++++++- fs/btrfs/volumes.c | 36 ++++++++- 8 files changed, 481 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 8827869f1744..323ba01ad8a9 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -83,6 +83,7 @@ struct btrfs_block_group { unsigned int has_caching_ctl:1; unsigned int removed:1; unsigned int wp_broken:1; + unsigned int to_copy:1; int disk_cache_state; diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 9286c6e0b636..6ac6aa0eb0b6 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -265,6 +265,10 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE); device->fs_devices = fs_info->fs_devices; + ret = btrfs_get_dev_zone_info(device); + if (ret) + goto error; + mutex_lock(&fs_info->fs_devices->device_list_mutex); list_add(&device->dev_list, &fs_info->fs_devices->devices); fs_info->fs_devices->num_devices++; @@ -399,6 +403,176 @@ static char* btrfs_dev_name(struct btrfs_device *device) return rcu_str_deref(device->name); } +static int mark_block_group_to_copy(struct btrfs_fs_info *fs_info, + struct btrfs_device *src_dev) +{ + struct btrfs_path *path; + struct btrfs_key key; + struct btrfs_key found_key; + struct btrfs_root *root = fs_info->dev_root; + struct btrfs_dev_extent *dev_extent = NULL; + struct btrfs_block_group *cache; + struct extent_buffer *l; + struct btrfs_trans_handle *trans; + int slot; + int ret = 0; + u64 chunk_offset, length; + + /* Do not use "to_copy" on non-HMZONED for now */ + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return 0; + + mutex_lock(&fs_info->chunk_mutex); + + /* ensulre we don't have pending new block group */ + while (fs_info->running_transaction && + !list_empty(&fs_info->running_transaction->dev_update_list)) { + mutex_unlock(&fs_info->chunk_mutex); + trans = btrfs_attach_transaction(root); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + mutex_lock(&fs_info->chunk_mutex); + if (ret == -ENOENT) + continue; + else + goto out; + } + + ret = btrfs_commit_transaction(trans); + mutex_lock(&fs_info->chunk_mutex); + if (ret) + goto out; + } + + path = btrfs_alloc_path(); + if (!path) { + ret = -ENOMEM; + goto out; + } + + path->reada = READA_FORWARD; + path->search_commit_root = 1; + path->skip_locking = 1; + + key.objectid = src_dev->devid; + key.offset = 0ull; + key.type = BTRFS_DEV_EXTENT_KEY; + + while (1) { + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + if (ret < 0) + break; + if (ret > 0) { + if (path->slots[0] >= + btrfs_header_nritems(path->nodes[0])) { + ret = btrfs_next_leaf(root, path); + if (ret < 0) + break; + if (ret > 0) { + ret = 0; + break; + } + } else { + ret = 0; + } + } + + l = path->nodes[0]; + slot = path->slots[0]; + + btrfs_item_key_to_cpu(l, &found_key, slot); + + if (found_key.objectid != src_dev->devid) + break; + + if (found_key.type != BTRFS_DEV_EXTENT_KEY) + break; + + if (found_key.offset < key.offset) + break; + + dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent); + length = btrfs_dev_extent_length(l, dev_extent); + + chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); + + cache = btrfs_lookup_block_group(fs_info, chunk_offset); + if (!cache) + goto skip; + + spin_lock(&cache->lock); + cache->to_copy = 1; + spin_unlock(&cache->lock); + + btrfs_put_block_group(cache); + +skip: + key.offset = found_key.offset + length; + btrfs_release_path(path); + } + + btrfs_free_path(path); +out: + mutex_unlock(&fs_info->chunk_mutex); + + return ret; +} + +bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev, + struct btrfs_block_group *cache, + u64 physical) +{ + struct btrfs_fs_info *fs_info = cache->fs_info; + struct extent_map *em; + struct map_lookup *map; + u64 chunk_offset = cache->start; + int num_extents, cur_extent; + int i; + + /* Do not use "to_copy" on non-HMZONED for now */ + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return true; + + spin_lock(&cache->lock); + if (cache->removed) { + spin_unlock(&cache->lock); + return true; + } + spin_unlock(&cache->lock); + + em = btrfs_get_chunk_map(fs_info, chunk_offset, 1); + BUG_ON(IS_ERR(em)); + map = em->map_lookup; + + num_extents = cur_extent = 0; + for (i = 0; i < map->num_stripes; i++) { + /* we have more device extent to copy */ + if (srcdev != map->stripes[i].dev) + continue; + + num_extents++; + if (physical == map->stripes[i].physical) + cur_extent = i; + } + + free_extent_map(em); + + if (num_extents > 1 && cur_extent < num_extents - 1) { + /* + * Has more stripes on this device. Keep this BG + * readonly until we finish all the stripes. + */ + return false; + } + + /* last stripe on this device */ + spin_lock(&cache->lock); + cache->to_copy = 0; + spin_unlock(&cache->lock); + + return true; +} + static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, const char *tgtdev_name, u64 srcdevid, const char *srcdev_name, int read_src) @@ -440,6 +614,10 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, if (ret) return ret; + ret = mark_block_group_to_copy(fs_info, src_device); + if (ret) + return ret; + down_write(&dev_replace->rwsem); switch (dev_replace->replace_state) { case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED: diff --git a/fs/btrfs/dev-replace.h b/fs/btrfs/dev-replace.h index 60b70dacc299..3911049a5f23 100644 --- a/fs/btrfs/dev-replace.h +++ b/fs/btrfs/dev-replace.h @@ -18,5 +18,8 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info); void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info); int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info); int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace); +bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev, + struct btrfs_block_group *cache, + u64 physical); #endif diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d1f326b6c4d4..69c4ce8ec83e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -34,6 +34,7 @@ #include "block-group.h" #include "rcu-string.h" #include "hmzoned.h" +#include "dev-replace.h" #undef SCRAMBLE_DELAYED_REFS @@ -1343,6 +1344,8 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, u64 length = stripe->length; u64 bytes; struct request_queue *req_q; + struct btrfs_dev_replace *dev_replace = + &fs_info->dev_replace; if (!stripe->dev->bdev) { ASSERT(btrfs_test_opt(fs_info, DEGRADED)); @@ -1351,15 +1354,28 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, req_q = bdev_get_queue(stripe->dev->bdev); /* zone reset in HMZONED mode */ - if (btrfs_can_zone_reset(dev, physical, length)) + if (btrfs_can_zone_reset(dev, physical, length)) { ret = btrfs_reset_device_zone(dev, physical, length, &bytes); - else if (blk_queue_discard(req_q)) + if (ret) + goto next; + if (!btrfs_dev_replace_is_ongoing( + dev_replace) || + dev != dev_replace->srcdev) + goto next; + + discarded_bytes += bytes; + /* send to replace target as well */ + ret = btrfs_reset_device_zone( + dev_replace->tgtdev, + physical, length, &bytes); + } else if (blk_queue_discard(req_q)) ret = btrfs_issue_discard(dev->bdev, physical, length, &bytes); else continue; +next: if (!ret) { discarded_bytes += bytes; } else if (ret != -EOPNOTSUPP) { diff --git a/fs/btrfs/hmzoned.c b/fs/btrfs/hmzoned.c index 55530782c1b1..08ba72a2c973 100644 --- a/fs/btrfs/hmzoned.c +++ b/fs/btrfs/hmzoned.c @@ -18,6 +18,7 @@ #include "locking.h" #include "space-info.h" #include "transaction.h" +#include "dev-replace.h" /* Maximum number of zones to report per blkdev_report_zones() call */ #define BTRFS_REPORT_NR_ZONES 4096 @@ -845,6 +846,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache) for (i = 0; i < map->num_stripes; i++) { bool is_sequential; struct blk_zone zone; + struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; + int dev_replace_is_ongoing = 0; device = map->stripes[i].dev; physical = map->stripes[i].physical; @@ -871,6 +874,14 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache) */ btrfs_dev_clear_zone_empty(device, physical); + down_read(&dev_replace->rwsem); + dev_replace_is_ongoing = + btrfs_dev_replace_is_ongoing(dev_replace); + if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL) + btrfs_dev_clear_zone_empty(dev_replace->tgtdev, + physical); + up_read(&dev_replace->rwsem); + /* * The group is mapped to a sequential zone. Get the zone write * pointer to determine the allocation offset within the zone. @@ -1239,3 +1250,83 @@ void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, ASSERT(cache->meta_write_pointer == eb->start + eb->len); cache->meta_write_pointer = eb->start; } + +int btrfs_hmzoned_issue_zeroout(struct btrfs_device *device, u64 physical, + u64 length) +{ + if (!btrfs_dev_is_sequential(device, physical)) + return -EOPNOTSUPP; + + return blkdev_issue_zeroout(device->bdev, + physical >> SECTOR_SHIFT, + length >> SECTOR_SHIFT, + GFP_NOFS, 0); +} + +static int read_zone_info(struct btrfs_fs_info *fs_info, u64 logical, + struct blk_zone *zone) +{ + struct btrfs_bio *bbio = NULL; + u64 mapped_length = PAGE_SIZE; + unsigned int nofs_flag; + int nmirrors; + int i, ret; + + ret = btrfs_map_sblock(fs_info, BTRFS_MAP_GET_READ_MIRRORS, logical, + &mapped_length, &bbio); + if (ret || !bbio || mapped_length < PAGE_SIZE) { + btrfs_put_bbio(bbio); + return -EIO; + } + + if (bbio->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) + return -EINVAL; + + nofs_flag = memalloc_nofs_save(); + nmirrors = (int)bbio->num_stripes; + for (i = 0; i < nmirrors; i++) { + u64 physical = bbio->stripes[i].physical; + struct btrfs_device *dev = bbio->stripes[i].dev; + + /* missing device */ + if (!dev->bdev) + continue; + + ret = btrfs_get_dev_zone(dev, physical, zone); + /* failing device */ + if (ret == -EIO || ret == -EOPNOTSUPP) + continue; + break; + } + memalloc_nofs_restore(nofs_flag); + + return ret; +} + +int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical, + u64 physical_start, u64 physical_pos) +{ + struct btrfs_fs_info *fs_info = tgt_dev->fs_info; + struct blk_zone zone; + u64 length; + u64 wp; + int ret; + + if (!btrfs_dev_is_sequential(tgt_dev, physical_pos)) + return 0; + + ret = read_zone_info(fs_info, logical, &zone); + if (ret) + return ret; + + wp = physical_start + ((zone.wp - zone.start) << SECTOR_SHIFT); + + if (physical_pos == wp) + return 0; + + if (physical_pos > wp) + return -EUCLEAN; + + length = wp - physical_pos; + return btrfs_hmzoned_issue_zeroout(tgt_dev, physical_pos, length); +} diff --git a/fs/btrfs/hmzoned.h b/fs/btrfs/hmzoned.h index 54f1affa6919..8558dd692b08 100644 --- a/fs/btrfs/hmzoned.h +++ b/fs/btrfs/hmzoned.h @@ -55,6 +55,10 @@ bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, struct btrfs_block_group **cache_ret); void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache, struct extent_buffer *eb); +int btrfs_hmzoned_issue_zeroout(struct btrfs_device *device, u64 physical, + u64 length); +int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical, + u64 physical_start, u64 physical_pos); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -133,6 +137,18 @@ static inline bool btrfs_check_meta_write_pointer( } static inline void btrfs_revert_meta_write_pointer( struct btrfs_block_group *cache, struct extent_buffer *eb) { } +static inline int btrfs_hmzoned_issue_zeroout(struct btrfs_device *device, + u64 physical, u64 length) +{ + return -EOPNOTSUPP; +} +static inline int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, + u64 logical, + u64 physical_start, + u64 physical_pos) +{ + return -EOPNOTSUPP; +} #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index af7cec962619..e88f32256ccc 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -168,6 +168,7 @@ struct scrub_ctx { int pages_per_rd_bio; int is_dev_replace; + u64 write_pointer; struct scrub_bio *wr_curr_bio; struct mutex wr_lock; @@ -1627,6 +1628,25 @@ static int scrub_write_page_to_dev_replace(struct scrub_block *sblock, return scrub_add_page_to_wr_bio(sblock->sctx, spage); } +static int fill_writer_pointer_gap(struct scrub_ctx *sctx, u64 physical) +{ + int ret = 0; + u64 length; + + if (!btrfs_fs_incompat(sctx->fs_info, HMZONED)) + return 0; + + if (sctx->write_pointer < physical) { + length = physical - sctx->write_pointer; + + ret = btrfs_hmzoned_issue_zeroout(sctx->wr_tgtdev, + sctx->write_pointer, length); + if (!ret) + sctx->write_pointer = physical; + } + return ret; +} + static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, struct scrub_page *spage) { @@ -1649,6 +1669,13 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, if (sbio->page_count == 0) { struct bio *bio; + ret = fill_writer_pointer_gap(sctx, + spage->physical_for_dev_replace); + if (ret) { + mutex_unlock(&sctx->wr_lock); + return ret; + } + sbio->physical = spage->physical_for_dev_replace; sbio->logical = spage->logical; sbio->dev = sctx->wr_tgtdev; @@ -1710,6 +1737,10 @@ static void scrub_wr_submit(struct scrub_ctx *sctx) * doubled the write performance on spinning disks when measured * with Linux 3.5 */ btrfsic_submit_bio(sbio->bio); + + if (btrfs_fs_incompat(sctx->fs_info, HMZONED)) + sctx->write_pointer = sbio->physical + + sbio->page_count * PAGE_SIZE; } static void scrub_wr_bio_end_io(struct bio *bio) @@ -3040,6 +3071,46 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx, return ret < 0 ? ret : 0; } +static void sync_replace_for_hmzoned(struct scrub_ctx *sctx) +{ + if (!btrfs_fs_incompat(sctx->fs_info, HMZONED)) + return; + + sctx->flush_all_writes = true; + scrub_submit(sctx); + mutex_lock(&sctx->wr_lock); + scrub_wr_submit(sctx); + mutex_unlock(&sctx->wr_lock); + + wait_event(sctx->list_wait, + atomic_read(&sctx->bios_in_flight) == 0); +} + +static int sync_write_pointer_for_hmzoned(struct scrub_ctx *sctx, u64 logical, + u64 physical, u64 physical_end) +{ + struct btrfs_fs_info *fs_info = sctx->fs_info; + int ret = 0; + + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return 0; + + wait_event(sctx->list_wait, atomic_read(&sctx->bios_in_flight) == 0); + + mutex_lock(&sctx->wr_lock); + if (sctx->write_pointer < physical_end) { + ret = btrfs_sync_zone_write_pointer(sctx->wr_tgtdev, logical, + physical, + sctx->write_pointer); + if (ret) + btrfs_err(fs_info, "failed to recover write pointer"); + } + mutex_unlock(&sctx->wr_lock); + btrfs_dev_clear_zone_empty(sctx->wr_tgtdev, physical); + + return ret; +} + static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, struct map_lookup *map, struct btrfs_device *scrub_dev, @@ -3052,7 +3123,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, struct btrfs_extent_item *extent; struct blk_plug plug; u64 flags; - int ret; + int ret, ret2; int slot; u64 nstripes; struct extent_buffer *l; @@ -3171,6 +3242,14 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, */ blk_start_plug(&plug); + if (sctx->is_dev_replace && + btrfs_dev_is_sequential(sctx->wr_tgtdev, physical)) { + mutex_lock(&sctx->wr_lock); + sctx->write_pointer = physical; + mutex_unlock(&sctx->wr_lock); + sctx->flush_all_writes = true; + } + /* * now find all extents for each stripe and scrub them */ @@ -3343,6 +3422,9 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, if (ret) goto out; + if (sctx->is_dev_replace) + sync_replace_for_hmzoned(sctx); + if (extent_logical + extent_len < key.objectid + bytes) { if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { @@ -3410,6 +3492,15 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, blk_finish_plug(&plug); btrfs_free_path(path); btrfs_free_path(ppath); + + if (sctx->is_dev_replace && ret >= 0) { + ret2 = sync_write_pointer_for_hmzoned( + sctx, base + offset, + map->stripes[num].physical, physical_end); + if (ret2) + ret = ret2; + } + return ret < 0 ? ret : 0; } @@ -3465,6 +3556,25 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx, return ret; } +static int finish_extent_writes_for_hmzoned(struct btrfs_root *root, + struct btrfs_block_group *cache) +{ + struct btrfs_fs_info *fs_info = cache->fs_info; + struct btrfs_trans_handle *trans; + + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return 0; + + btrfs_wait_block_group_reservations(cache); + btrfs_wait_nocow_writers(cache); + btrfs_wait_ordered_roots(fs_info, U64_MAX, cache->start, cache->length); + + trans = btrfs_join_transaction(root); + if (IS_ERR(trans)) + return PTR_ERR(trans); + return btrfs_commit_transaction(trans); +} + static noinline_for_stack int scrub_enumerate_chunks(struct scrub_ctx *sctx, struct btrfs_device *scrub_dev, u64 start, u64 end) @@ -3483,6 +3593,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, struct btrfs_key found_key; struct btrfs_block_group *cache; struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; + bool do_chunk_alloc = btrfs_fs_incompat(fs_info, HMZONED); path = btrfs_alloc_path(); if (!path) @@ -3551,6 +3662,18 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, if (!cache) goto skip; + + if (sctx->is_dev_replace && + btrfs_fs_incompat(fs_info, HMZONED)) { + spin_lock(&cache->lock); + if (!cache->to_copy) { + spin_unlock(&cache->lock); + ro_set = 0; + goto done; + } + spin_unlock(&cache->lock); + } + /* * we need call btrfs_inc_block_group_ro() with scrubs_paused, * to avoid deadlock caused by: @@ -3579,7 +3702,16 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, * thread can't be triggered fast enough, and use up all space * of btrfs_super_block::sys_chunk_array */ - ret = btrfs_inc_block_group_ro(cache, false); + ret = btrfs_inc_block_group_ro(cache, do_chunk_alloc); + if (!ret && sctx->is_dev_replace) { + ret = finish_extent_writes_for_hmzoned(root, cache); + if (ret) { + btrfs_dec_block_group_ro(cache); + scrub_pause_off(fs_info); + btrfs_put_block_group(cache); + break; + } + } scrub_pause_off(fs_info); if (ret == 0) { @@ -3641,6 +3773,12 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx, scrub_pause_off(fs_info); + if (sctx->is_dev_replace && + !btrfs_finish_block_group_to_copy(dev_replace->srcdev, + cache, found_key.offset)) + ro_set = 0; + +done: down_write(&dev_replace->rwsem); dev_replace->cursor_left = dev_replace->cursor_right; dev_replace->item_needs_writeback = 1; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d058ea613627..c4061b65a38b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1413,6 +1413,9 @@ static int find_free_dev_extent_start(struct btrfs_device *device, search_start = max_t(u64, search_start, zone_size); search_start = btrfs_zone_align(device, search_start); + WARN_ON(device->zone_info && + !IS_ALIGNED(num_bytes, device->zone_info->zone_size)); + path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -5720,9 +5723,29 @@ static int get_extra_mirror_from_replace(struct btrfs_fs_info *fs_info, return ret; } +static bool is_block_group_to_copy(struct btrfs_fs_info *fs_info, u64 logical) +{ + struct btrfs_block_group *cache; + bool ret; + + /* non-HMZONED mode does not use "to_copy" flag */ + if (!btrfs_fs_incompat(fs_info, HMZONED)) + return false; + + cache = btrfs_lookup_block_group(fs_info, logical); + + spin_lock(&cache->lock); + ret = cache->to_copy; + spin_unlock(&cache->lock); + + btrfs_put_block_group(cache); + return ret; +} + static void handle_ops_on_dev_replace(enum btrfs_map_op op, struct btrfs_bio **bbio_ret, struct btrfs_dev_replace *dev_replace, + u64 logical, int *num_stripes_ret, int *max_errors_ret) { struct btrfs_bio *bbio = *bbio_ret; @@ -5735,6 +5758,15 @@ static void handle_ops_on_dev_replace(enum btrfs_map_op op, if (op == BTRFS_MAP_WRITE) { int index_where_to_add; + /* + * a block group which have "to_copy" set will + * eventually copied by dev-replace process. We can + * avoid cloning IO here. + */ + if (is_block_group_to_copy(dev_replace->srcdev->fs_info, + logical)) + return; + /* * duplicate the write operations while the dev replace * procedure is running. Since the copying of the old disk to @@ -6145,8 +6177,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL && need_full_stripe(op)) { - handle_ops_on_dev_replace(op, &bbio, dev_replace, &num_stripes, - &max_errors); + handle_ops_on_dev_replace(op, &bbio, dev_replace, logical, + &num_stripes, &max_errors); } *bbio_ret = bbio; From patchwork Wed Dec 4 08:17:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D26917EF for ; Wed, 4 Dec 2019 08:20:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF7C3206DF for ; Wed, 4 Dec 2019 08:20:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="JIohd1Yg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727499AbfLDIUT (ORCPT ); Wed, 4 Dec 2019 03:20:19 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32819 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726217AbfLDIUS (ORCPT ); Wed, 4 Dec 2019 03:20:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447619; x=1606983619; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Xc6PNKHNLMT6cFXODCW5lJKtVCDGPT+JT7Ud3tXcFaQ=; b=JIohd1YgL0p1Cz+6wbYEa8hpZghI+6UbSIdizHe6pgByl04JAcF3eU7K EO3eiAmDAxtNhRO08czgv7/hiacwEkg9s4vIwxSTJDU+6T+to8l7p9VoQ 2Wu8eSqOlE7IgqnIOT0tCBoNTwNwJwj4ugrw5hCc1JoCfeba/6s03x0lU ke+o9pMpc31pf1C0WENVRzuBEVmV3uwMY/SpkxlCRpgnUSA7foKb3FQI6 krmc1GmU/mGJVq/gK7bDY6ttNUTF5MP8GgfUkEwM5OQC6jd/bY4oH+3ZZ jRPonkMWhxAxxJVqaZ4Rz6uZkPYIVI75KzvffiToIJDcpxJhk1z7AzxA7 A==; IronPort-SDR: Rvqr1H5AQh8hOB7AsX/xT8BeZmmJpfCvUiHHh4VEdCMGV0KGFVCrUZLghbPazuXxBon/ZbiDiL RsVHeYAoJcZb3KLEKgYqJ3kMLwr+/y945wWoY1zhiurl/6vnroW4FkSqeVDoOLUsQDkn4HPYgc OVlS+EhaNBAU9selhTYHxvds4CvZjA1oBYsHguEOh+24DVKtw7/2SbxAF8xxxxeOK8ju1QVvpb Ja2rYhIfI6EjuWp45X9bmSFm810XdkBPt9nJ08/n19gOon4qqlFhVPMtkF/PXhpe18qKHZL57a ymk= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355118" 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; 04 Dec 2019 16:20:18 +0800 IronPort-SDR: UyILqiuiOyK0aDvb1ySDIgQ5Pi+6pNj4o3WVdP7LHehII0NZsKyKfPYRNtnVQPCe8BjzgX+TYN HoHuIJ2ogVHhTYRhE6hlV1PPWHfReuzJsK+3XfUzAx2wYYhr1huTySufm8Wcs3MEeB0VROyboj FgWRpXID2UTUD/1nM4bSoW9tdGgtiYI9NGi1E+KiDy2bYZBweGt1QKOn2B0KxE9sfLWNemtr1E aB6GaC6pfh5+Owt5tJ0jKjnhnZGT6CDztm7wSRdOHmXh3hz6HiqRi9rtiwdZe/BfWL3+7/nN9K 5XhLOAqQTVtZAPqPQKlazCsf Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:43 -0800 IronPort-SDR: aUg11jJ6vl3zroLC7+mYWqen82Kj/Q86rVCNmnK1ltzEDDWYsvHbOrJDsUwVF/jOno6P7I9tsv nNvR/YQXWWmlHqfy9UApKTAcLj/wFeQQK9H6zrZ9x8VIisguGUmPiZvhVBf01JASW5PV43ZhV/ Hovt+c1kGBgBBaU9m59OeoS93uCHTnO41A5xfl+kSLoTyFg8q35QuQAMA+ETx6Y1c4q6T/sxe8 zSXqJABMtKcXn768SmLIsAqKjyQJSTu3TCbtvXJxkWxy3eOlJU3iypZPjHZ7tHwK8VmAAofZ/d +oU= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:15 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 24/28] btrfs: enable relocation in HMZONED mode Date: Wed, 4 Dec 2019 17:17:31 +0900 Message-Id: <20191204081735.852438-25-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org To serialize allocation and submit_bio, we introduced mutex around them. As a result, preallocation must be completely disabled to avoid a deadlock. Since current relocation process relies on preallocation to move file data extents, it must be handled in another way. In HMZONED mode, we just truncate the inode to the size that we wanted to pre-allocate. Then, we flush dirty pages on the file before finishing relocation process. run_delalloc_hmzoned() will handle all the allocation and submit IOs to the underlying layers. Signed-off-by: Naohiro Aota --- fs/btrfs/relocation.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index d897a8e5e430..2d17b7566df4 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3159,6 +3159,34 @@ int prealloc_file_extent_cluster(struct inode *inode, if (ret) goto out; + /* + * In HMZONED, we cannot preallocate the file region. Instead, + * we dirty and fiemap_write the region. + */ + + if (btrfs_fs_incompat(btrfs_sb(inode->i_sb), HMZONED)) { + struct btrfs_root *root = BTRFS_I(inode)->root; + struct btrfs_trans_handle *trans; + + end = cluster->end - offset + 1; + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) + return PTR_ERR(trans); + + inode->i_ctime = current_time(inode); + i_size_write(inode, end); + btrfs_ordered_update_i_size(inode, end, NULL); + ret = btrfs_update_inode(trans, root, inode); + if (ret) { + btrfs_abort_transaction(trans, ret); + btrfs_end_transaction(trans); + return ret; + } + ret = btrfs_end_transaction(trans); + + goto out; + } + cur_offset = prealloc_start; while (nr < cluster->nr) { start = cluster->boundary[nr] - offset; @@ -3346,6 +3374,10 @@ static int relocate_file_extent_cluster(struct inode *inode, btrfs_throttle(fs_info); } WARN_ON(nr != cluster->nr); + if (btrfs_fs_incompat(fs_info, HMZONED) && !ret) { + ret = btrfs_wait_ordered_range(inode, 0, (u64)-1); + WARN_ON(ret); + } out: kfree(ra); return ret; @@ -4186,8 +4218,12 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, struct btrfs_path *path; struct btrfs_inode_item *item; struct extent_buffer *leaf; + u64 flags = BTRFS_INODE_NOCOMPRESS | BTRFS_INODE_PREALLOC; int ret; + if (btrfs_fs_incompat(trans->fs_info, HMZONED)) + flags &= ~BTRFS_INODE_PREALLOC; + path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -4202,8 +4238,7 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, btrfs_set_inode_generation(leaf, item, 1); btrfs_set_inode_size(leaf, item, 0); btrfs_set_inode_mode(leaf, item, S_IFREG | 0600); - btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS | - BTRFS_INODE_PREALLOC); + btrfs_set_inode_flags(leaf, item, flags); btrfs_mark_buffer_dirty(leaf); out: btrfs_free_path(path); From patchwork Wed Dec 4 08:17:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D6D016C1 for ; Wed, 4 Dec 2019 08:20:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB1822068E for ; Wed, 4 Dec 2019 08:20:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rv22i6kv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727508AbfLDIUW (ORCPT ); Wed, 4 Dec 2019 03:20:22 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32819 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727501AbfLDIUU (ORCPT ); Wed, 4 Dec 2019 03:20:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447621; x=1606983621; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7YDA5C6hW2cNPHhVKgDju1HaRknXX7UTMxkQL5jLeSg=; b=rv22i6kvHgr28yaLowkqj4U0m+00WwzyYk8kVfI0vA5bJ2CKe7GoXqkK g/zTSVuYBo6iGqvc0CLkbhJOuMvLChai1vUNLVf76n93RDC3j6C4+nRyl jPfw3PAYLESMAuHJubn0tTd/oLUErShXKVJSzEKbydx58NmgFe0lb4pfK dgI1BO2+KAQyz23RVY8dKLOEn7Bh53dKKDXNaBqpqrY3fUvXHPxEaWwnR oBisZZjQqTEACakQahBL6kPf7FbR1eBVCUm0UoRmTd4M79V6tih939YOj Nb8fQrpt9yDa/el9H/NZIbrPODG0O0M0IoJdgtCwEqMOxhRHE1YOQMSGA w==; IronPort-SDR: wTTlt6anIRNwldZry4RDNq6pngbYxE5cdDZ/39cAvgxZSiidoHOTWzniGebz5l4vHXLzdFQQ/7 y0oAurrUYm4k4Py9BE+raAB0dZpZ7vlPeRP5+IBdswJ7Ozj3wM7KJaXk5UzeCCzbz3TZB/9FV0 7zkuMFh/Cc1FHdTtN5MYBJxEdUQeeDXcmvPrzbWhhM7llYiCwLaZbrj0ydjndFLqttFB9Jcs8W 8RsOvyeYKJKOczJu7MliXlAw7gisoPNLGxiVTpbN50B2ZNuddQsfjk0JZpXqyqqUyBhcewfP9p 6nk= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355123" 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; 04 Dec 2019 16:20:20 +0800 IronPort-SDR: 3+/9/xHHk8xBPEQHW/1vMBvAwYMdxJ0bEh5hsz+42QHzAwpWi69y+sb1oGYoCB71XlmvwU82BP JJnvYKZEcx5gmwFdssaY+gZ5uA/Xw1tJmdiBnxvHtBZuKVntCjbJrAVa1C1gdaHpBbhmOt1bwK TUp0gJmBSp0EWGNCSU6JqiGR2DakWnIQGbYzz6dGSm4WrqTiPyEs8KN1QJo4KBrC4fuBjvaUgo v2gv+r4AchbW4OoLSgRCEsOCedCb4jUKUPRvmVkCUSGyHzmqNXZh9UhJyIVE9uwPoZDIU5h/sl uQ77xvnPJY+GBRPTULbhH1/v Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:45 -0800 IronPort-SDR: 6NhCKxt5syV7geitOtlukXLPHUHC4spSPt1XgDCbEphnvQ4b3GgPQKg93GopoCG0b7cmu5lkHB 7LKdSfmGyZ3DgvOQ4+/PvbkcVQcHuY9K7d35IT+AWIUvQn4V2Ney/awKDafOAnBmN+RRLSGrQW kS2lPljbg4y36gmXcy+iNnhJo5fZzdkeBMegmlGq3p3lQxKyXc9HRrBSTN4xIn2jtTJwE0SuAa Lf1MdWC0YnibcSANZxfj43ZjI6VOTMhZnjzO7Kbe7VGe1VBOXC1GqNIyxPFozn7JcGYQB/Qk5A 6Hc= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:17 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 25/28] btrfs: relocate block group to repair IO failure in HMZONED Date: Wed, 4 Dec 2019 17:17:32 +0900 Message-Id: <20191204081735.852438-26-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When btrfs find a checksum error and if the file system has a mirror of the damaged data, btrfs read the correct data from the mirror and write the data to damaged blocks. This repairing, however, is against the sequential write required rule. We can consider three methods to repair an IO failure in HMZONED mode: (1) Reset and rewrite the damaged zone (2) Allocate new device extent and replace the damaged device extent to the new extent (3) Relocate the corresponding block group Method (1) is most similar to a behavior done with regular devices. However, it also wipes non-damaged data in the same device extent, and so it unnecessary degrades non-damaged data. Method (2) is much like device replacing but done in the same device. It is safe because it keeps the device extent until the replacing finish. However, extending device replacing is non-trivial. It assumes "src_dev>physical == dst_dev->physical". Also, the extent mapping replacing function should be extended to support replacing device extent position in one device. Method (3) invokes relocation of the damaged block group, so it is straightforward to implement. It relocates all the mirrored device extents, so it is, potentially, a more costly operation than method (1) or (2). But it relocates only using extents which reduce the total IO size. Let's apply method (3) for now. In the future, we can extend device-replace and apply method (2). For protecting a block group gets relocated multiple time with multiple IO errors, this commit introduces "relocating_repair" bit to show it's now relocating to repair IO failures. Also it uses a new kthread "btrfs-relocating-repair", not to block IO path with relocating process. This commit also supports repairing in the scrub process. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.h | 1 + fs/btrfs/extent_io.c | 3 ++ fs/btrfs/scrub.c | 3 ++ fs/btrfs/volumes.c | 71 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 1 + 5 files changed, 79 insertions(+) diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 323ba01ad8a9..4a5bd87345a1 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -84,6 +84,7 @@ struct btrfs_block_group { unsigned int removed:1; unsigned int wp_broken:1; unsigned int to_copy:1; + unsigned int relocating_repair:1; int disk_cache_state; diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 24f7b05e1f4c..83f5e5883723 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2197,6 +2197,9 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, ASSERT(!(fs_info->sb->s_flags & SB_RDONLY)); BUG_ON(!mirror_num); + if (btrfs_fs_incompat(fs_info, HMZONED)) + return btrfs_repair_one_hmzone(fs_info, logical); + bio = btrfs_io_bio_alloc(1); bio->bi_iter.bi_size = 0; map_length = length; diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index e88f32256ccc..5ed54523f036 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -861,6 +861,9 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check) have_csum = sblock_to_check->pagev[0]->have_csum; dev = sblock_to_check->pagev[0]->dev; + if (btrfs_fs_incompat(fs_info, HMZONED) && !sctx->is_dev_replace) + return btrfs_repair_one_hmzone(fs_info, logical); + /* * We must use GFP_NOFS because the scrub task might be waiting for a * worker task executing this function and in turn a transaction commit diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c4061b65a38b..f023eb559b89 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7793,3 +7793,74 @@ bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr) spin_unlock(&fs_info->swapfile_pins_lock); return node != NULL; } + +static int relocating_repair_kthread(void *data) +{ + struct btrfs_block_group *cache = (struct btrfs_block_group *) data; + struct btrfs_fs_info *fs_info = cache->fs_info; + u64 target; + int ret = 0; + + target = cache->start; + btrfs_put_block_group(cache); + + if (test_and_set_bit(BTRFS_FS_EXCL_OP, &fs_info->flags)) { + btrfs_info(fs_info, + "skip relocating block group %llu to repair: EBUSY", + target); + return -EBUSY; + } + + mutex_lock(&fs_info->delete_unused_bgs_mutex); + + /* ensure Block Group still exists */ + cache = btrfs_lookup_block_group(fs_info, target); + if (!cache) + goto out; + + if (!cache->relocating_repair) + goto out; + + ret = btrfs_may_alloc_data_chunk(fs_info, target); + if (ret < 0) + goto out; + + btrfs_info(fs_info, "relocating block group %llu to repair IO failure", + target); + ret = btrfs_relocate_chunk(fs_info, target); + +out: + if (cache) + btrfs_put_block_group(cache); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); + clear_bit(BTRFS_FS_EXCL_OP, &fs_info->flags); + + return ret; +} + +int btrfs_repair_one_hmzone(struct btrfs_fs_info *fs_info, u64 logical) +{ + struct btrfs_block_group *cache; + + /* do not attempt to repair in degraded state */ + if (btrfs_test_opt(fs_info, DEGRADED)) + return 0; + + cache = btrfs_lookup_block_group(fs_info, logical); + if (!cache) + return 0; + + spin_lock(&cache->lock); + if (cache->relocating_repair) { + spin_unlock(&cache->lock); + btrfs_put_block_group(cache); + return 0; + } + cache->relocating_repair = 1; + spin_unlock(&cache->lock); + + kthread_run(relocating_repair_kthread, cache, + "btrfs-relocating-repair"); + + return 0; +} diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 70cabe65f72a..e5a2e7fc3a08 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -576,5 +576,6 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, int btrfs_bg_type_to_factor(u64 flags); const char *btrfs_bg_type_to_raid_name(u64 flags); int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info); +int btrfs_repair_one_hmzone(struct btrfs_fs_info *fs_info, u64 logical); #endif From patchwork Wed Dec 4 08:17:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FD48930 for ; Wed, 4 Dec 2019 08:20:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E4EA2068E for ; Wed, 4 Dec 2019 08:20:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="XBRWEoZu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727516AbfLDIUY (ORCPT ); Wed, 4 Dec 2019 03:20:24 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32819 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727501AbfLDIUX (ORCPT ); Wed, 4 Dec 2019 03:20:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447623; x=1606983623; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lnC8yzmKb8UpJR++C4z0jIqstzFWE9sHCk1QgPwlnlE=; b=XBRWEoZunR/O4S0bCZUC1NkK6c0lMcFPtqOJiJI+fKiEjX8F1zT491BC AEfp6N+9frDrEcx+mPcwdAd32bAjeaCoJxz4WuoZcY5XueibSKA/NS4Bq 8ZDvFeaNefPNMb7WwuntKgEh3d2gCE0eWqNfO/I4thXEEK69Rx2cmQuMN ss8ubf4UxAnclesyyaFdCWd0i7bJAj19l4FErgh++TZt7k41SegY88CeY Gz573zcPdKX4msI/BiibLM86pjGIBNIOWHoI5gAf9ThsQmXVvWoyOEjGD QqqJNDQ9WuZyBCWtG44u+a1SDMClsvhX8aurHT2eeRzIe9Lbfu2Z9J2Ou A==; IronPort-SDR: 2bvY+D97ly1YH3vyF8VQ9JDAIxuY//IJchSCYArCGVD/b0JdHT8/vFLmv9dnNBzPVgIsXpTBg6 8DUHbDlMkC6ltXeO2aMC/UBZtM6X1y5yrQBQO3n3U7p8Q1OpbnZjvuW4C5AKowSy0Q/DevJSIv kQj+mmWNGOvN/j1NbGEVz2MZwHnqPBSqGwxSDEgGFEeRC0yvYn8NfyH9dgpb2P3Gs9U+N87lu+ UoUysj1ByH80nE0Sgy/5NxlgvTyL+Hnvl0eB9+WxwkHbTiROqkjwhOAuS3Y4JfP236GvSSljbP M0I= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355126" 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; 04 Dec 2019 16:20:23 +0800 IronPort-SDR: PkfhPht3ONvTrrmiHrGsvW9ImAAMwMUpeTrchQoijR5CGQqbWfgT9heLxoQ2bwonlnM2Sa6r6C ZQw3px/q2hFiyqtBQ/6ZfldLHAmzGC4jrITYRY7cE2UWueAd3qc24kdrORwh7/ocJ53R1hNbTI C0xRqfGL4sTFjpePSchTeLXyuXFqRCkmvnRE0U827NcKEYal4N294b27jXif2BvYGDEUmUXI0Z 54927AadE/RHTfyLerlsmlSOk/Ca9FR3rZG6AJVLxyGwoNo/rHTv++VlwJYg2TSNA/fQ2r/kDK aVGbMQBTqtUvaNE+iR2DHRxh Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:48 -0800 IronPort-SDR: 6HoN3pF6kKlpbPJNffhtuS2XBtZrsMhhdGq5tkjCVQSjuBVhsg1taUf7n3PCR80bF0IrlPICgZ G6iRJze+4SNzKWc1qA3giSxbbN6vOyAyWA2kFeJXOmyxgEeW6pL3twdFR0jE7ZbWQjxrU82WFA 6y4L/X/JZXvf/Mxi0cAfuWDPqkogw9Xxw/Z9r0MY9xd1Q1Gdc12pFThpov7oU2K8KtRdWXJem0 fvueB4l7r6BK+81+TQMC0EzLrX6vSu5Au3nPNXEA8D3aBZsYPb4UBUgG7tjYTy7sMpU/8G7/iE /80= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:20 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 26/28] btrfs: split alloc_log_tree() Date: Wed, 4 Dec 2019 17:17:33 +0900 Message-Id: <20191204081735.852438-27-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is a preparation for the next patch. This commit split alloc_log_tree() to allocating tree structure part (remains in alloc_log_tree()) and allocating tree node part (moved in btrfs_alloc_log_tree_node()). The latter part is also exported to be used in the next patch. Signed-off-by: Naohiro Aota --- fs/btrfs/disk-io.c | 31 +++++++++++++++++++++++++------ fs/btrfs/disk-io.h | 2 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index c3d8fc10d11d..914c517d26b0 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1315,7 +1315,6 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info) { struct btrfs_root *root; - struct extent_buffer *leaf; root = btrfs_alloc_root(fs_info, GFP_NOFS); if (!root) @@ -1327,6 +1326,14 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, root->root_key.type = BTRFS_ROOT_ITEM_KEY; root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; + return root; +} + +int btrfs_alloc_log_tree_node(struct btrfs_trans_handle *trans, + struct btrfs_root *root) +{ + struct extent_buffer *leaf; + /* * DON'T set REF_COWS for log trees * @@ -1338,26 +1345,31 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID, NULL, 0, 0, 0); - if (IS_ERR(leaf)) { - kfree(root); - return ERR_CAST(leaf); - } + if (IS_ERR(leaf)) + return PTR_ERR(leaf); root->node = leaf; btrfs_mark_buffer_dirty(root->node); btrfs_tree_unlock(root->node); - return root; + + return 0; } int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info) { struct btrfs_root *log_root; + int ret; log_root = alloc_log_tree(trans, fs_info); if (IS_ERR(log_root)) return PTR_ERR(log_root); + ret = btrfs_alloc_log_tree_node(trans, log_root); + if (ret) { + kfree(log_root); + return ret; + } WARN_ON(fs_info->log_root_tree); fs_info->log_root_tree = log_root; return 0; @@ -1369,11 +1381,18 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_root *log_root; struct btrfs_inode_item *inode_item; + int ret; log_root = alloc_log_tree(trans, fs_info); if (IS_ERR(log_root)) return PTR_ERR(log_root); + ret = btrfs_alloc_log_tree_node(trans, log_root); + if (ret) { + kfree(log_root); + return ret; + } + log_root->last_trans = trans->transid; log_root->root_key.offset = root->root_key.objectid; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 76f123ebb292..21e8d936c705 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -121,6 +121,8 @@ blk_status_t btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, extent_submit_bio_start_t *submit_bio_start); blk_status_t btrfs_submit_bio_done(void *private_data, struct bio *bio, int mirror_num); +int btrfs_alloc_log_tree_node(struct btrfs_trans_handle *trans, + struct btrfs_root *root); int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info); int btrfs_add_log_tree(struct btrfs_trans_handle *trans, From patchwork Wed Dec 4 08:17:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34BE017EF for ; Wed, 4 Dec 2019 08:20:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0078D2068E for ; Wed, 4 Dec 2019 08:20:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="AN5FfVVT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727525AbfLDIU1 (ORCPT ); Wed, 4 Dec 2019 03:20:27 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32819 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727501AbfLDIUZ (ORCPT ); Wed, 4 Dec 2019 03:20:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447626; x=1606983626; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aTDT/TuW1C009nCSV5xqCnFu5EeDZEvFd1SEUSwdmj4=; b=AN5FfVVTtCMORwsMhQn6vRW7hBkkoMcLlMqJqPaVGqS2SkMFQxkQQR6q hfyiYadOQUjGPQ818InY89wte3199p9VdFRTbb6/SukCRetCI7BIHWYl8 Sa5pOhQoCixR39V4AcjwJERBmPReUPOS87rvO6RIjzmFscpMB1xODpVUD x47hHnqRxCgkJqc+qQnZn9cxdlM1b3McpnFD2+W7AHBsXO6uaG9SlPCe9 0PB03sUO6UFSB/RzDYmXjdhmXEZXPGQtIWtgFtYMRX6rbfsGcCE9GVf6B REIPvlorss5ffu+erOqAjk4DHPwc3BJQFAkp1cfI6kHDlmKvdjQ1X/dr5 w==; IronPort-SDR: jHlLqCZJb6Nz54Gkk//vjH1Xa0R8n3j87HHaKqG7kWMvavRsphdKGgZRXEafA3iIFCyT3nxl6G IfW67wFHqwFxefyLDtjjvXsXFC18dEi4PidQU4TN8QdnD4DvMF4zcateCMn9xelA7nvLIDyXXd 5nikNAMepBUYUqXs+LK78yHJ2p3cRQBBWb6jmtHn04rajino/wjiVxujq0NbwG+H9aWDHwS8Ey htkNFdaPVP58aeX3OyLFH0m4L1hJAYeUzHn55+eBVBYA36hRvtF3qv7T04I99wUdY1ZCDKR5IJ vhI= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355129" 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; 04 Dec 2019 16:20:25 +0800 IronPort-SDR: MwuDIQGVjIEyv3PliLJ/ig2O5JoKoCWemgn9eosIgdXvOA5mliKEBEAkBoWAt5gPWvIJqz/PJS nix6O92UStKbOfJQJEuTiQE09c152Wn1vdV3G9Dnqry1jH2yGzRraHGOjGkvxzEvlnIG4B8YQ1 JuNw/izVLaHbMgjWSetKLNyFRhYaQJBPjLfw9PpTx8qOBrShCIlN5CXA8iwowTARncQ9rOxoFt g7riiBS0F4BuZs9z71LTVPhDds6l+eH5UdSDGV50SR6NIuuleY7FjqXRasfB/mCNsmU/OjiqbK oHGDPVhGYitZBwL07IdNrdF4 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:50 -0800 IronPort-SDR: +097Cr6xmLASFAwdhNviHkNNzzNiEWxVKR62Hjg+HRsYNOfUEO4V/xRqQb3fE7y/pUqsvKRG8J AXnNO5dqnmJiFT9GM9WMs7Sh7YwuzLSeQ6V0rg72hLu1S9K4o5iXCtN9Yzx+hAub1hKI8HMxA3 FFBapW77u/JK21Udt/tSKK24IfLD3y4IXlHI/UflrIdssjsw8aHtbAB14TzaE19+P8/qfPVe9Y pRlLQPyDFgVToOWuupxwVFPqJCreV8s6zoqUvnTNxHpUWJKOQxcd6t0m6WE1yRn+2QhNaUr2VH GUw= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:22 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 27/28] btrfs: enable tree-log on HMZONED mode Date: Wed, 4 Dec 2019 17:17:34 +0900 Message-Id: <20191204081735.852438-28-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The tree-log feature does not work on HMZONED mode as is. Blocks for a tree-log tree are allocated mixed with other metadata blocks, and btrfs writes and syncs the tree-log blocks to devices at the time of fsync(), which is different timing than a global transaction commit. As a result, both writing tree-log blocks and writing other metadata blocks become non-sequential writes which HMZONED mode must avoid. Also, since we can start more than one log transactions per subvolume at the same time, nodes from multiple transactions can be allocated interleaved. Such mixed allocation results in non-sequential writes at the time of log transaction commit. The nodes of the global log root tree (fs_info->log_root_tree), also have the same mixed allocation problem. This patch assigns a dedicated block group for tree-log blocks to separate two metadata writing streams (for tree-log blocks and other metadata blocks). As a result, each write stream can now be written to devices separately. "fs_info->treelog_bg" tracks the dedicated block group and btrfs assign "treelog_bg" on-demand on tree-log block allocation time. Then, this patch serializes log transactions by waiting for a committing transaction when someone tries to start a new transaction, to avoid the mixed allocation problem. We must also wait for running log transactions from another subvolume, but there is no easy way to detect which subvolume root is running a log transaction. So, this patch forbids starting a new log transaction when the global log root tree is already allocated by other subvolumes. Furthermore, this patch aligns the allocation order of nodes of "fs_info->log_root_tree" and nodes of "root->log_root" with the writing order of the nodes, by delaying allocation of the root node of "fs_info->log_root_tree," so that, the node buffers can go out sequentially to devices. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 7 +++++ fs/btrfs/ctree.h | 2 ++ fs/btrfs/disk-io.c | 8 ++--- fs/btrfs/extent-tree.c | 71 +++++++++++++++++++++++++++++++++++++----- fs/btrfs/tree-log.c | 49 ++++++++++++++++++++++++----- 5 files changed, 116 insertions(+), 21 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 6f7d29171adf..93e6c617d68e 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -910,6 +910,13 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, btrfs_return_cluster_to_free_space(block_group, cluster); spin_unlock(&cluster->refill_lock); + if (btrfs_fs_incompat(fs_info, HMZONED)) { + spin_lock(&fs_info->treelog_bg_lock); + if (fs_info->treelog_bg == block_group->start) + fs_info->treelog_bg = 0; + spin_unlock(&fs_info->treelog_bg_lock); + } + path = btrfs_alloc_path(); if (!path) { ret = -ENOMEM; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 18d2d0581e68..cba8a169002c 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -907,6 +907,8 @@ struct btrfs_fs_info { #endif struct mutex hmzoned_meta_io_lock; + spinlock_t treelog_bg_lock; + u64 treelog_bg; }; static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 914c517d26b0..9c2b2fbf0cdb 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1360,16 +1360,10 @@ int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info) { struct btrfs_root *log_root; - int ret; log_root = alloc_log_tree(trans, fs_info); if (IS_ERR(log_root)) return PTR_ERR(log_root); - ret = btrfs_alloc_log_tree_node(trans, log_root); - if (ret) { - kfree(log_root); - return ret; - } WARN_ON(fs_info->log_root_tree); fs_info->log_root_tree = log_root; return 0; @@ -2841,6 +2835,8 @@ int __cold open_ctree(struct super_block *sb, fs_info->send_in_progress = 0; + spin_lock_init(&fs_info->treelog_bg_lock); + ret = btrfs_alloc_stripe_hash_table(fs_info); if (ret) { err = ret; diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 69c4ce8ec83e..9b9608097f7f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3704,8 +3704,10 @@ static int find_free_extent_unclustered(struct btrfs_block_group *bg, */ static int find_free_extent_zoned(struct btrfs_block_group *cache, - struct find_free_extent_ctl *ffe_ctl) + struct find_free_extent_ctl *ffe_ctl, + bool for_treelog) { + struct btrfs_fs_info *fs_info = cache->fs_info; struct btrfs_space_info *space_info = cache->space_info; struct btrfs_free_space_ctl *ctl = cache->free_space_ctl; u64 start = cache->start; @@ -3718,12 +3720,26 @@ static int find_free_extent_zoned(struct btrfs_block_group *cache, btrfs_hmzoned_data_io_lock(cache); spin_lock(&space_info->lock); spin_lock(&cache->lock); + spin_lock(&fs_info->treelog_bg_lock); + + ASSERT(!for_treelog || cache->start == fs_info->treelog_bg || + fs_info->treelog_bg == 0); if (cache->ro) { ret = -EAGAIN; goto out; } + /* + * Do not allow currently using block group to be tree-log + * dedicated block group. + */ + if (for_treelog && !fs_info->treelog_bg && + (cache->used || cache->reserved)) { + ret = 1; + goto out; + } + avail = cache->length - cache->alloc_offset; if (avail < num_bytes) { ffe_ctl->max_extent_size = avail; @@ -3731,6 +3747,9 @@ static int find_free_extent_zoned(struct btrfs_block_group *cache, goto out; } + if (for_treelog && !fs_info->treelog_bg) + fs_info->treelog_bg = cache->start; + ffe_ctl->found_offset = start + cache->alloc_offset; cache->alloc_offset += num_bytes; spin_lock(&ctl->tree_lock); @@ -3738,12 +3757,15 @@ static int find_free_extent_zoned(struct btrfs_block_group *cache, spin_unlock(&ctl->tree_lock); ASSERT(IS_ALIGNED(ffe_ctl->found_offset, - cache->fs_info->stripesize)); + fs_info->stripesize)); ffe_ctl->search_start = ffe_ctl->found_offset; __btrfs_add_reserved_bytes(cache, ffe_ctl->ram_bytes, num_bytes, ffe_ctl->delalloc); out: + if (ret && for_treelog) + fs_info->treelog_bg = 0; + spin_unlock(&fs_info->treelog_bg_lock); spin_unlock(&cache->lock); spin_unlock(&space_info->lock); /* if succeeds, unlock after submit_bio */ @@ -3891,7 +3913,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, static noinline int find_free_extent(struct btrfs_fs_info *fs_info, u64 ram_bytes, u64 num_bytes, u64 empty_size, u64 hint_byte, struct btrfs_key *ins, - u64 flags, int delalloc) + u64 flags, int delalloc, bool for_treelog) { int ret = 0; struct btrfs_free_cluster *last_ptr = NULL; @@ -3970,6 +3992,13 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, spin_unlock(&last_ptr->lock); } + if (hmzoned && for_treelog) { + spin_lock(&fs_info->treelog_bg_lock); + if (fs_info->treelog_bg) + hint_byte = fs_info->treelog_bg; + spin_unlock(&fs_info->treelog_bg_lock); + } + ffe_ctl.search_start = max(ffe_ctl.search_start, first_logical_byte(fs_info, 0)); ffe_ctl.search_start = max(ffe_ctl.search_start, hint_byte); @@ -4015,8 +4044,15 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, list_for_each_entry(block_group, &space_info->block_groups[ffe_ctl.index], list) { /* If the block group is read-only, we can skip it entirely. */ - if (unlikely(block_group->ro)) + if (unlikely(block_group->ro)) { + if (hmzoned && for_treelog) { + spin_lock(&fs_info->treelog_bg_lock); + if (block_group->start == fs_info->treelog_bg) + fs_info->treelog_bg = 0; + spin_unlock(&fs_info->treelog_bg_lock); + } continue; + } btrfs_grab_block_group(block_group, delalloc); ffe_ctl.search_start = block_group->start; @@ -4062,7 +4098,25 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, goto loop; if (hmzoned) { - ret = find_free_extent_zoned(block_group, &ffe_ctl); + u64 bytenr = block_group->start; + u64 log_bytenr; + bool skip; + + /* + * Do not allow non-tree-log blocks in the + * dedicated tree-log block group, and vice versa. + */ + spin_lock(&fs_info->treelog_bg_lock); + log_bytenr = fs_info->treelog_bg; + skip = log_bytenr && + ((for_treelog && bytenr != log_bytenr) || + (!for_treelog && bytenr == log_bytenr)); + spin_unlock(&fs_info->treelog_bg_lock); + if (skip) + goto loop; + + ret = find_free_extent_zoned(block_group, &ffe_ctl, + for_treelog); if (ret) goto loop; /* @@ -4222,12 +4276,13 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, bool final_tried = num_bytes == min_alloc_size; u64 flags; int ret; + bool for_treelog = root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID; flags = get_alloc_profile_by_root(root, is_data); again: WARN_ON(num_bytes < fs_info->sectorsize); ret = find_free_extent(fs_info, ram_bytes, num_bytes, empty_size, - hint_byte, ins, flags, delalloc); + hint_byte, ins, flags, delalloc, for_treelog); if (!ret && !is_data) { btrfs_dec_block_group_reservations(fs_info, ins->objectid); } else if (ret == -ENOSPC) { @@ -4245,8 +4300,8 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes, sinfo = btrfs_find_space_info(fs_info, flags); btrfs_err(fs_info, - "allocation failed flags %llu, wanted %llu", - flags, num_bytes); + "allocation failed flags %llu, wanted %llu treelog %d", + flags, num_bytes, for_treelog); if (sinfo) btrfs_dump_space_info(fs_info, sinfo, num_bytes, 1); diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 6f757361db53..e155418f24ba 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -18,6 +18,7 @@ #include "compression.h" #include "qgroup.h" #include "inode-map.h" +#include "hmzoned.h" /* magic values for the inode_only field in btrfs_log_inode: * @@ -105,6 +106,7 @@ static noinline int replay_dir_deletes(struct btrfs_trans_handle *trans, struct btrfs_root *log, struct btrfs_path *path, u64 dirid, int del_all); +static void wait_log_commit(struct btrfs_root *root, int transid); /* * tree logging is a special write ahead log used to make sure that @@ -139,16 +141,25 @@ static int start_log_trans(struct btrfs_trans_handle *trans, struct btrfs_log_ctx *ctx) { struct btrfs_fs_info *fs_info = root->fs_info; + bool hmzoned = btrfs_fs_incompat(fs_info, HMZONED); int ret = 0; mutex_lock(&root->log_mutex); +again: if (root->log_root) { + int index = (root->log_transid + 1) % 2; + if (btrfs_need_log_full_commit(trans)) { ret = -EAGAIN; goto out; } + if (hmzoned && atomic_read(&root->log_commit[index])) { + wait_log_commit(root, root->log_transid - 1); + goto again; + } + if (!root->log_start_pid) { clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); root->log_start_pid = current->pid; @@ -157,8 +168,13 @@ static int start_log_trans(struct btrfs_trans_handle *trans, } } else { mutex_lock(&fs_info->tree_log_mutex); - if (!fs_info->log_root_tree) + if (hmzoned && fs_info->log_root_tree) { + ret = -EAGAIN; + mutex_unlock(&fs_info->tree_log_mutex); + goto out; + } else if (!fs_info->log_root_tree) { ret = btrfs_init_log_root_tree(trans, fs_info); + } mutex_unlock(&fs_info->tree_log_mutex); if (ret) goto out; @@ -191,11 +207,19 @@ static int start_log_trans(struct btrfs_trans_handle *trans, */ static int join_running_log_trans(struct btrfs_root *root) { + bool hmzoned = btrfs_fs_incompat(root->fs_info, HMZONED); int ret = -ENOENT; mutex_lock(&root->log_mutex); +again: if (root->log_root) { + int index = (root->log_transid + 1) % 2; + ret = 0; + if (hmzoned && atomic_read(&root->log_commit[index])) { + wait_log_commit(root, root->log_transid - 1); + goto again; + } atomic_inc(&root->log_writers); } mutex_unlock(&root->log_mutex); @@ -2724,6 +2748,8 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, btrfs_clean_tree_block(next); btrfs_wait_tree_block_writeback(next); btrfs_tree_unlock(next); + btrfs_redirty_list_add( + trans->transaction, next); } else { if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags)) clear_extent_buffer_dirty(next); @@ -3128,6 +3154,11 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, mutex_lock(&log_root_tree->log_mutex); + mutex_lock(&fs_info->tree_log_mutex); + if (!log_root_tree->node) + btrfs_alloc_log_tree_node(trans, log_root_tree); + mutex_unlock(&fs_info->tree_log_mutex); + /* * Now we are safe to update the log_root_tree because we're under the * log_mutex, and we're a current writer so we're holding the commit @@ -3285,16 +3316,20 @@ static void free_log_tree(struct btrfs_trans_handle *trans, .process_func = process_one_buffer }; - ret = walk_log_tree(trans, log, &wc); - if (ret) { - if (trans) - btrfs_abort_transaction(trans, ret); - else - btrfs_handle_fs_error(log->fs_info, ret, NULL); + if (log->node) { + ret = walk_log_tree(trans, log, &wc); + if (ret) { + if (trans) + btrfs_abort_transaction(trans, ret); + else + btrfs_handle_fs_error(log->fs_info, ret, NULL); + } } clear_extent_bits(&log->dirty_log_pages, 0, (u64)-1, EXTENT_DIRTY | EXTENT_NEW | EXTENT_NEED_WAIT); + if (trans && log->node) + btrfs_redirty_list_add(trans->transaction, log->node); free_extent_buffer(log->node); kfree(log); } From patchwork Wed Dec 4 08:17:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11272377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B3E817EF for ; Wed, 4 Dec 2019 08:20:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5A0192068E for ; Wed, 4 Dec 2019 08:20:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="P8QxwLND" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727535AbfLDIU2 (ORCPT ); Wed, 4 Dec 2019 03:20:28 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:32819 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727526AbfLDIU1 (ORCPT ); Wed, 4 Dec 2019 03:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575447628; x=1606983628; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=13Xj/2Q3e/31YLvSZL3B4rqcPrjvoVC0rWnzkBnhSLo=; b=P8QxwLNDI+bJjRcmJp1JFZnFS1+T7HWAELUdwFR2FtfwYa6DtPEX/dV6 h4+njsGvrzoE3+hJGG7JPxAnI/WHFEUIS1d0+X2er4NoiENM944hi54E8 r8H+o/TRgJxdfHzT4DgnuAkVmMX8kbVp3OyhlIqaIZ1wNsaKPDpREAVtg r5xHIaE45GoMjVQbPCjyAU20swFO/zJQRYAES4WzvFd6dvZJvXGThiOtY ma/leiBmMW6YVUiETPuMhMh9FzwbGpRTb+29YABN+sX6svbmqdcInDB7h wmlAhEn+LdW0Q7jWsreAZ4ex/i9CqK1KS4S3RXYk0FWBcRrOrZA96EIR9 A==; IronPort-SDR: GvXXMJ8PFpudt7x8tZvYjQY4SSWsEtKtnOye3cTERuE8CzRXkMcifLieu3p9RWFV2ebr+hc9K/ 4O30XzQnMVm+9MyZ+gLEOhXZmzjEszPE4N0mE7ZfwkUrdI4RcRTc+F9Um2ekaQpAYBxZRyvtey 4irhBo/ReExfgaZi/vna3NJV+Dpnf70Fbls4lhaeMrLBs9G+pTPnQ2isLWaNtsFVIxgMmClA5F WO7dlMhy9nmZUFu3mDMKmOLgh0xH6vbTgOMAeWyIcMzTKZzGpaeQCeisc6U3kqFxOei2g82nmF fFo= X-IronPort-AV: E=Sophos;i="5.69,276,1571673600"; d="scan'208";a="125355133" 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; 04 Dec 2019 16:20:27 +0800 IronPort-SDR: 3Dpfe6Ilx6l7yGCVCqIckNqoz5nDdnoJmHe6syjIWmSVfpilN+kuog2xX0cWD0wfc3MmGjAL+O ACorQ7vrO/gkbTQ5zEjub9qa4fMKaGQ1uw0GNCPBNTu/vXohYhdGCMUBnIcuA+5Qq7ZXX5AJIV 3ml+fWJXdEuXeJpGLiCgnK7SZ/yVvbRKGiimAO3JGRDxcrT06SgyPKoHNZPRniLZFxcL/LBnZt sTkyaoqDOpXm1osz1p+QSHLUT+YusJrpXDrtdbmpaGckkx7pWqTV/sMG76ZXYGRrqqcEEuhGUt KZZjoWvgDHU0DwE4DctW8ycY Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 00:14:52 -0800 IronPort-SDR: NvZG6aFfXhkQl4+OfEo0KxqnzfcGolAes1NmOIyJ1/FMzhixOds6RAvXOv//7TjTkmCWE6BzBg Aq0XtToJzxG45ExLJJyZ+lJ9EYqQDyDUEGFS9sshIY/1eUEzoUGzzZqSyNDMiOvdAgYoRYnDbe LZPttHCQFzCjHAnyD+Obe2Zs1CK0KSg/KtiMCt9UWVVHG8GVvIJlLGQgETgHCAixIWWc881JQk oSwQWG2+aaHEZN+9wjre6p7dY3iS72PdbC3FEaHle7FysWe1N7PwHnpDy2tO3wyncO8ftu7N/3 xPw= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com (HELO naota.fujisawa.hgst.com) ([10.149.53.115]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2019 00:20:24 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v5 28/28] btrfs: enable to mount HMZONED incompat flag Date: Wed, 4 Dec 2019 17:17:35 +0900 Message-Id: <20191204081735.852438-29-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204081735.852438-1-naohiro.aota@wdc.com> References: <20191204081735.852438-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This final patch adds the HMZONED incompat flag to BTRFS_FEATURE_INCOMPAT_SUPP and enables btrfs to mount HMZONED flagged file system. Signed-off-by: Naohiro Aota --- fs/btrfs/ctree.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index cba8a169002c..79c8695ba4b4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -293,7 +293,8 @@ struct btrfs_super_block { BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \ BTRFS_FEATURE_INCOMPAT_NO_HOLES | \ BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \ - BTRFS_FEATURE_INCOMPAT_RAID1C34) + BTRFS_FEATURE_INCOMPAT_RAID1C34 | \ + BTRFS_FEATURE_INCOMPAT_HMZONED) #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \ (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)