Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2338884imm; Thu, 9 Aug 2018 11:07:42 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyPfTrTs6YbiI/73M4HrYtEbqP4tXP1/H0ghqQqSp6dokrLQoThQBL8lbYEhFP3MLHOA+iW X-Received: by 2002:a17:902:6bc5:: with SMTP id m5-v6mr2974356plt.274.1533838062142; Thu, 09 Aug 2018 11:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533838062; cv=none; d=google.com; s=arc-20160816; b=W09QVr+CKLCIx8e6l/nh5EjkKWbYEa2E+WIBZIbdTUtkM3kIJMkqn1hOAhufhFOZ4X FgBMxpAXWUdGIXJcGQwrf5zI64uOkyRJBUarT2sbR+xuqw8JFC/5Bj/wtB4Qed6t5buq VuxqEHq9vtOY5Nfhf2ejLV0GYq6M/IIggFgRazNexAHAHSKKZ52II72ZrIL2+Mxrelhk X9nTSMDzX41+iAsnvGBRpoxQABp7j6scjNeqk6b/4RachoGtDap9I+ylj/1XqPO856FE KTR6IJQCyhD7TLdyFsGh2krFFI1+Lm9hSipOLOS/wOh3oBjR83Q1B22eCnd6mvkYcmub f5Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=nIuHCF9683iMYU2rHMsdILJuGo9/J5CkhRVd0dD+FUY=; b=f2g/D+5dJiep2pS2CulEUciRWsrMxUmSA8LUM4bf3EqtTT6oLjMqL3XCUBW1vX5EUb ym+oBcMKAQK1HcoJsAvgXA/D7QqAKQL19HzESGgh5njBWcq0nvHCL82xDmdmr7rdUQtf 1yxqHEwp5RgaaLbJTyNcsM298ObIWtOCjbc3T8DGiHOFdKiHoULpnMvDSC5Q2qcRGho6 o4gsfGGRYlVrIvaVeLYAj2NPqoWOLgHFfjaX3Nxjnhhson+iKSAifnwqx6cg7Atr5jR1 4qZssAcqHSwooU0rFCQtuP2boBlMa0sK8hDawP6bBs2uby9BL7OLTEU5qxf23Zwl2AXD xUvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RDNCO6DA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z127-v6si7919929pgb.455.2018.08.09.11.07.28; Thu, 09 Aug 2018 11:07:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RDNCO6DA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727568AbeHIUcZ (ORCPT + 99 others); Thu, 9 Aug 2018 16:32:25 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:46215 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727407AbeHIUcY (ORCPT ); Thu, 9 Aug 2018 16:32:24 -0400 Received: by mail-pf1-f195.google.com with SMTP id u24-v6so3192953pfn.13; Thu, 09 Aug 2018 11:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nIuHCF9683iMYU2rHMsdILJuGo9/J5CkhRVd0dD+FUY=; b=RDNCO6DAKkOyJV0udkYO90nl7ou3VLUqZt5cpOaugzrYSVVLB1ZKWOIi31/PRWbDJl ygqgo4QMZYokvyCMHgDAM3q5OTB8Lz0bn0Q2pWgUKe1X+c3Xqs8/bmFlHBFpoMngHnHu 4yVyGaoaducePqhIRQrz5vofy9whcy9SPuF6wmGRF3AkyzG1mEKI5bR7JwqCAqkibWRP 5+sMssFpNsAmsO+tRP71oBm4LAZz7Py6kIdz18n/Y6vyUT4g3eKkVLt0+tJmeLCkRB5g xnz28N8WVyC0iP9JQqXhLOcUmZaStL6aNwiGC2zaRPaumUK9W1dH4RD+RLeDcoo9aUUq NgaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=nIuHCF9683iMYU2rHMsdILJuGo9/J5CkhRVd0dD+FUY=; b=KWQ6FiBeA1Hrz4qbKMWQFqSjgx2FyYN04jPPxy13WTBhielf179z+Kfnh/hNOH4Vzc h3I6FE12yLoINFX2BIbcr861H9d18/pBLXy/EwZCPsMVQR0uCC1TC6aVh9tZ12v/L36n Y4ORH+qdyLgAm9spAu3VEVQwl6k1iQ9KCMdoyXPSTLXyljP9f8mBIL7CBPlC1/rNINUV BbsNlsC7CY8LDi97HKSnEgkNsHfGfT+pSj8yIEriS86gDd35i1oM/m2Gniect7aw82tW u30hAs45zR0ekb+L6sOWtPh5om59LZejwJEAoR2GxPymFs8D1cGWEXJaSg3QWer35GhG agiQ== X-Gm-Message-State: AOUpUlHL7/564ZGlgDdBTn4Z08cyFOJv+sT4IxfgRk0rr2Rup+g6dsEK CTksNkzqLBO0to+amAJ0kVQ= X-Received: by 2002:a63:2dc1:: with SMTP id t184-v6mr3153420pgt.62.1533837985008; Thu, 09 Aug 2018 11:06:25 -0700 (PDT) Received: from localhost (h101-111-148-072.catv02.itscom.jp. [101.111.148.72]) by smtp.gmail.com with ESMTPSA id l85-v6sm12880248pfk.34.2018.08.09.11.06.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 11:06:24 -0700 (PDT) From: Naohiro Aota To: David Sterba , linux-btrfs@vger.kernel.org Cc: Chris Mason , Josef Bacik , linux-kernel@vger.kernel.org, Hannes Reinecke , Damien Le Moal , Bart Van Assche , Matias Bjorling , Naohiro Aota Subject: [RFC PATCH 15/17] btrfs: reset zones of unused block groups Date: Fri, 10 Aug 2018 03:04:48 +0900 Message-Id: <20180809180450.5091-16-naota@elisp.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180809180450.5091-1-naota@elisp.net> References: <20180809180450.5091-1-naota@elisp.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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/extent-tree.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a5f5935315c8..26989f6fe591 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2025,6 +2025,25 @@ int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr, ASSERT(btrfs_test_opt(fs_info, DEGRADED)); continue; } + + if (clear == BTRFS_CLEAR_OP_DISCARD && + btrfs_dev_is_sequential(stripe->dev, + stripe->physical) && + stripe->length == stripe->dev->zone_size) { + ret = blkdev_reset_zones(stripe->dev->bdev, + stripe->physical >> 9, + stripe->length >> 9, + GFP_NOFS); + if (ret) + discarded_bytes += stripe->length; + else + break; + set_bit(stripe->physical >> + stripe->dev->zone_size_shift, + stripe->dev->empty_zones); + continue; + } + req_q = bdev_get_queue(stripe->dev->bdev); if (clear == BTRFS_CLEAR_OP_DISCARD && !blk_queue_discard(req_q)) @@ -10958,7 +10977,8 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) spin_unlock(&space_info->lock); /* DISCARD can flip during remount */ - trimming = btrfs_test_opt(fs_info, DISCARD); + trimming = btrfs_test_opt(fs_info, DISCARD) || + btrfs_fs_incompat(fs_info, HMZONED); /* Implicit trim during transaction commit. */ if (trimming) -- 2.18.0