From patchwork Fri Sep 2 07:46:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 9310511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1136F60865 for ; Fri, 2 Sep 2016 07:50:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05A2A296CD for ; Fri, 2 Sep 2016 07:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE6B1296D5; Fri, 2 Sep 2016 07:50:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D99F5296D3 for ; Fri, 2 Sep 2016 07:50:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752128AbcIBHs2 (ORCPT ); Fri, 2 Sep 2016 03:48:28 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:24170 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751708AbcIBHsH (ORCPT ); Fri, 2 Sep 2016 03:48:07 -0400 X-IronPort-AV: E=Sophos;i="5.30,270,1470672000"; d="scan'";a="13372571" Received: from mail-by2nam03lp0048.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([216.32.180.48]) by ob1.hgst.iphmx.com with ESMTP; 02 Sep 2016 15:47:49 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-hgst-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CaCGnMAZ88VoUDUCakWunob85mOOhHlyYl9BRo4Jgrw=; b=riqrso3XbEa8xefD6kKPfOmRS9NmxLcNKzcx8N4NjCFZNV5MLhdhEnIq8ijqAXoK307h05MA7FBPorSKmzzQ0rrZ8SC8vurGfCo03O8VMaVHC9TjudSjXCswvA+ovj+Owk9MSODzIiAAEcGcjnXbctvhWjgrrEcqiZo2FfJh/kY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Naohiro.Aota@hgst.com; Received: from naota-devel.dhcp.fujisawa.hgst.com (199.255.44.5) by MWHPR04MB0752.namprd04.prod.outlook.com (10.172.168.10) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9; Fri, 2 Sep 2016 07:47:46 +0000 From: Naohiro Aota To: CC: Chris Mason , Josef Bacik , David Sterba , , Naohiro Aota Subject: [PATCH] btrfs: let btrfs_delete_unused_bgs() to clean relocated bgs Date: Fri, 2 Sep 2016 16:46:32 +0900 Message-ID: <1472802392-10851-1-git-send-email-naohiro.aota@hgst.com> X-Mailer: git-send-email 2.7.3 MIME-Version: 1.0 X-Originating-IP: [199.255.44.5] X-ClientProxiedBy: MWHPR18CA0009.namprd18.prod.outlook.com (10.173.238.147) To MWHPR04MB0752.namprd04.prod.outlook.com (10.172.168.10) X-MS-Office365-Filtering-Correlation-Id: a2a7b4fa-5e40-4fab-dd6c-08d3d3056ed0 X-Microsoft-Exchange-Diagnostics: 1; MWHPR04MB0752; 2:n+KroTIWn1x6I3gYLNSCy5HruhcVzlYOuhWC4zQvoguJXownOBU+RRPvpjJxBXveCPdeEuNqcYhrePrkpi1FTakG7ELWv2eGds1sygNiPBCxzVblklMuKTGvoOFitYlmz2Tgybr8rFXXGTtZfL+GAF2QNd405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LgiuUuLihYv/p2jZSuzdAmC7PugmpRE0WL98/+JQcj4/MZYcrHXJWU5XDQyZP9jFQhS89OsxZGyZbqrsP2qJ5SDHzMw2oFnNBVDyAe6pe59a4O8D7086d9vx+km/vbiaBTQHHH6W9c5noRAlS+P4XcUcW4m8r64lwFg7FPMxTeHiJXehvW521JNnBHdaMPWCnfEM7NELR4I+7j7CFwoD0xS2polDYUugY1yZjcNANQTFfdOMw5Xu9qTOKkKGAKwEHpLYh8FRG9K9JbVTHYUQxazb+41yeffiRcGaX5svNbrnNyC5lGIcA/zn+zr5/dYu09pp9teWleM9F9+GFWNG/FMMIDwvS2V X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(79135771888625); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:MWHPR04MB0752; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB0752; X-Microsoft-Exchange-Diagnostics: 1; MWHPR04MB0752; 4:23L8E9MyuvBCywobVWAEfA9jb6Xzprz5hE5zAx48btJV1Y9nMPJrGUnMa6aRqfAIIO61FslYUimcD4mtwKFuV3oooVIhcxTJgd+qMovLCAHevDOjS/67yHuVJ3CHx6U7c6YzD2GR7hwCNNssOmYRFpVwq7H0fie/o1J+5lR9G+mQRRGH+Zglkfa0VnBjzZwTrEsBYuD0nkEF4gAELcZtDKVzGw0WpThjDuZyR/D9TjGGrwnTtjb1m/qAnQmibE1JCU/xozuDnsUGa9QjC8WX6005vWs1HoCMT6JtdXhjggia08smoR4DqGY+4iO23cLiFaF65XMxZJEaHOJxWyI8hGUKU0TXKAZz+gJhKn2muJbKJNeDb8VDVMU0pfx+FLXBIWmo/EXPrncQ/gw6+WOBpZvG9LFBqchrOSYw5w4C7VioH1vrIzww+ykP/weCdn8G9+BGvGvfWwz9iuRiZCwkxQ== X-Forefront-PRVS: 00531FAC2C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(2906002)(50986999)(50226002)(77096005)(305945005)(4001430100002)(92566002)(68736007)(106356001)(229853001)(2351001)(81156014)(81166006)(101416001)(97736004)(7736002)(8676002)(586003)(7846002)(86362001)(3846002)(42186005)(4326007)(189998001)(5660300001)(36756003)(47776003)(105586002)(19580395003)(19580405001)(110136002)(33646002)(6116002)(551934003)(107886002)(5003940100001)(50466002)(66066001)(48376002)(7099028)(5005270100013); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0752; H:naota-devel.dhcp.fujisawa.hgst.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: hgst.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR04MB0752; 23:NCOeBUJc9twS08WA6aGsu+oduCjBWKfYJmaA2k42t?= =?us-ascii?Q?7M5NWbKy8l2aQInHi1JwqsTHlTDCrGuVW6Ye2L2bYqC9d90+xjouvjHf+aX6?= =?us-ascii?Q?Szc4ApBShVTskqTGYDsA2nralUu5QuZK2RcA5psmb9Jc+XKeqNHIiMJ507bQ?= =?us-ascii?Q?HUuKYmfmoU1z1frCkFrE2ZXFjeNj4DNsoHvv3Bd7nMCTBbEXCyNMPv7as+Rx?= =?us-ascii?Q?2Qwbx6MBu+9E3G9wX10ZDIXvZrmmF9VRE30JvifGOawo4e3mx2qN+JHawEQZ?= =?us-ascii?Q?ysHSTv5gpcrZM+bEPSMqsj5RC8NGe0DSKCpGqGirkNzwoJl7tamAIIDce3kR?= =?us-ascii?Q?+mTyhvuI0GOLraQkcrdsPh/FYhkfMsXUfA5EXOJeczmCJlAmDzwkXy0w4/4I?= =?us-ascii?Q?lT1eyQk9FiUL1czFytpYb7MtuYP91uYKk3yj4JurwBCErkVkjb0sBpVM3/nl?= =?us-ascii?Q?u/aMNR3VdHuDFl4Dx+IaJXWH8KzTBv1wBKOIh1zHqY4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51krXVE7EIZ/1FF+Rv9IKIczJRK6Wi1Iu6dugbeB7Sm3s9+h8gyxpq93PuQHRFIMdlAYjpwufGpSwQ2X/IZVxZUxOSGoqA6l2choOt9jKH2CT87DdVpw==; 5:wNNQ0abXSzQzkIdui3Oghzm1ckMnBIOdpioEcODu7w7uRbe94AgqnZD8WEBSy4VsgBM2fT2h7ohrWzaEwB46gVSKIB8jX6qL8BCex/0c/wUBd1xyHbJTY/vrZ/AU3A4od8f/SAbLWEU6GOvb7lOVWA==; 24:RjngdrX8rhVMiWLPUXPFlyq2B+ffLYcOQ/w6kEKaWB1MjELPU8Lg6R7J8B6P7F7t8fF4asV2plOnwQY2/xUKJ0V+2wNARgqns7BZVowQSoM=; 7:s3ppNCJ9kOnmxP+xntaOU6PZdx//o7GdvJ2KEfKS8Do5nh5frOWXTC4PLrD/pWbwKUKeBYYF+cFI0XN/s9zl97kwnmp7eToZ9p5fMoxJ/CG9KejlMgAum80vuA2S59mkBPgPq0EHtjWtkklz2HF8ZTNC5enK8i2bwyfHGM71/JRA1vTU0fUWTbPLaf1zrdSj9GtNBTiRbQyW5tEd0pkMIb9F6oKANAEh448oaXFTC5LQZgUr8JdWbi3rNNNFVFYX SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR04MB0752; 20:MF52G0Xkkrhl/X3YMj1y4D4/zanNSGa+I0s267jZlQhyWyiIlY/hYnNvbw+6gPb4I2QpqOQMNFiZazuhV+fhUaVicGQoNLAQnWsS4Sk7EPWaVTh6tAiijqQgFBtrO3/2xWj94TkYcWKcj1ZyLr3bwImuo1ZPmn2jz9vx7vIahrqnFrm7pw0WHXFaYaYk7a+lyogvm0Kx4O+DJI3WexIRjCAFHouFtxHH1quB/82sNSNWe20whgcq9rpWoKu0f3OU X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2016 07:47:46.4310 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0752 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, btrfs_relocate_chunk() is removing relocated BG by itself. But the work can be done by btrfs_delete_unused_bgs() (and it's better since it trim the BG). Let's dedupe the code. While btrfs_delete_unused_bgs() is already hitting the relocated BG, it skip the BG since the BG has "ro" flag set (to keep balancing BG intact). On the other hand, btrfs cannot drop "ro" flag here to prevent additional writes. So this patch make use of "removed" flag. btrfs_delete_unused_bgs() now detect the flag to distinguish whether a read-only BG is relocating or not. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 2 +- fs/btrfs/volumes.c | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 843ed27..d382735 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -10971,7 +10971,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) spin_lock(&block_group->lock); if (block_group->reserved || btrfs_block_group_used(&block_group->item) || - block_group->ro || + (block_group->ro && !block_group->removed) || list_is_singular(&block_group->list)) { /* * We want to bail if we made new allocations or have diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7e6399f..1a6789d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2931,8 +2931,8 @@ out: static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) { struct btrfs_root *extent_root; - struct btrfs_trans_handle *trans; int ret; + struct btrfs_block_group_cache *block_group; root = root->fs_info->chunk_root; extent_root = root->fs_info->extent_root; @@ -2962,21 +2962,17 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) if (ret) return ret; - trans = btrfs_start_trans_remove_block_group(root->fs_info, - chunk_offset); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - btrfs_handle_fs_error(root->fs_info, ret, NULL); - return ret; - } - /* - * step two, delete the device extents and the - * chunk tree entries + * step two, flag the chunk as removed and let + * btrfs_delete_unused_bgs() remove it. */ - ret = btrfs_remove_chunk(trans, root, chunk_offset); - btrfs_end_transaction(trans, extent_root); - return ret; + block_group = btrfs_lookup_block_group(root->fs_info, chunk_offset); + spin_lock(&block_group->lock); + block_group->removed = 1; + spin_unlock(&block_group->lock); + btrfs_put_block_group(block_group); + + return 0; } static int btrfs_relocate_sys_chunks(struct btrfs_root *root)