From patchwork Wed May 30 13:35:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 10439007 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 7F06C603D7 for ; Wed, 30 May 2018 13:35:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C82428520 for ; Wed, 30 May 2018 13:35:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 618E628E08; Wed, 30 May 2018 13:35:44 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E31EF28520 for ; Wed, 30 May 2018 13:35:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9FA06B000C; Wed, 30 May 2018 09:35:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B740D6B000D; Wed, 30 May 2018 09:35:42 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A634B6B000E; Wed, 30 May 2018 09:35:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot0-f198.google.com (mail-ot0-f198.google.com [74.125.82.198]) by kanga.kvack.org (Postfix) with ESMTP id 89C9E6B000C for ; Wed, 30 May 2018 09:35:42 -0400 (EDT) Received: by mail-ot0-f198.google.com with SMTP id b5-v6so11674817otf.8 for ; Wed, 30 May 2018 06:35:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=TuEjmxchaDo9pzkdrffNaTO9HCR/0YsrhmcbSQpbkwU=; b=UHm9R98XAiRC97CsEdUTceRSgIkFeiDeVTtuN89kqUbrjcxcM+FCiOBN8wPo0pM1+K 2WIb4geZfW4K/wwxAhx9aKtelgz/0JGDzpTpJEErslwWL+cHgdXPPCjCvtZrNHHqSbZ3 OL2W5keayMl0eceYx2ACCUO62rFZTCKA4LAKQyP/BH8koxeqPoCTrpurVrKJuiy3rM7P 2Zn0aflF0V76OxsyCdAUQyVgmeDXsvhjssughV9YkFR5AU3CfQVrQXrxLYlu2XA8gBtJ P2kJIuogmgiZ4r/9Yf8RJR0NHgWZje0E0AKIPepvv4lgkKKp/rF53XGZR8RAcJhMJE6M THYQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of bfoster@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=bfoster@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ALKqPwcuQVPmKIC3kMxrKtJBRC81uk/BhRZolQC4ibKeoCncQ5l2Z123 GhTLj7cGG/WkdP63f1JQGcUkD2tkjSdJHiLOcJEtk+vp12ae4Oo80OEjVxcY16pqpWYRiwyn8XN 2cnfWIIP+iFTpMjLMRZPp4XbegVyySJ9fAWxrqFa+e9DeJ/x+ISCcsSJXUmPGlsRk+g== X-Received: by 2002:a9d:42dd:: with SMTP id c29-v6mr1843400otj.351.1527687342313; Wed, 30 May 2018 06:35:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJfi6ANzl13Lnep5wl0pkvwBF+hrl/l0pXI6T8yYHDx3gIWx9qqDaozuZUYZg5UjZKXk0/2 X-Received: by 2002:a9d:42dd:: with SMTP id c29-v6mr1843367otj.351.1527687341716; Wed, 30 May 2018 06:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527687341; cv=none; d=google.com; s=arc-20160816; b=c1c98LzNRLTaGzIEtXiML3oZeaQiT5TonY41e576ajRB4ul0DyReYi8KfV4O9Th1Xr EMnBQFggsZPfKtS1z/t+7dHkvQJrohltTy5qVJcwNQYA5Qqv1jaGkItG4w+Q9VyMLp6C exNe8s75JYnHsbiWNCKHyJ52CtgcymJ8j23D7np0u8W8xHtlZPaMVqOmLK7KvK8jBwtB x10o2wH3fHTc2eBL8RtEOqllSkzoW8mRZ7Jjr4kPY37j96mB9Qk6vnDm3tB+Cw8AOnMv e7w6M6C5rEqfmn3s81OLI7xPFqQEz0bKldHSjFlSZdC9wnEzfkHiCW5EFSGtvMgpNJdm d29w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:arc-authentication-results; bh=TuEjmxchaDo9pzkdrffNaTO9HCR/0YsrhmcbSQpbkwU=; b=QcLYa0EEuiGpu+bvJ4UfP2zv7P8T1NuFD6hfHli3bqG5uz41HJxCcZNxq3/x6//Lnc hFnTWgp4EZFZsXs6yjBKuEYuSSOoZKTsd5565eTqjRS+YuLbqlL+jrkg2I2FmS4vnDvK dIniXl7YZEID+1iSJoUIE9I8uHHrF0I/ffOLsxBYFQJkdbT7G4Dhcw8RkcwSv9Q1yDKg BnWwPIuFLFcW8/ZFY3tgHGqvFJM/RiUQ+uGrEY++ACJVh33mGH90hZPHxyEU7DTVk0Er f144hF8VzMNFsPQABJFBuUWywBD8mzIyXwpFmpw8nGcJfrc/hHq934DtCpsrfgmA2TQi zG5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of bfoster@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=bfoster@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 34-v6si4184245ots.119.2018.05.30.06.35.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 06:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of bfoster@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of bfoster@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=bfoster@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 092F03177BEF; Wed, 30 May 2018 13:35:41 +0000 (UTC) Received: from bfoster.bfoster (dhcp-41-20.bos.redhat.com [10.18.41.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id C268E5D6B4; Wed, 30 May 2018 13:35:40 +0000 (UTC) Received: by bfoster.bfoster (Postfix, from userid 1000) id 92F7B12378C; Wed, 30 May 2018 09:35:39 -0400 (EDT) Date: Wed, 30 May 2018 09:35:39 -0400 From: Brian Foster To: Christoph Hellwig Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 03/18] xfs: simplify xfs_bmap_punch_delalloc_range Message-ID: <20180530133538.GC112411@bfoster.bfoster> References: <20180530100013.31358-1-hch@lst.de> <20180530100013.31358-4-hch@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180530100013.31358-4-hch@lst.de> User-Agent: Mutt/1.9.2 (2017-12-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 30 May 2018 13:35:41 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP On Wed, May 30, 2018 at 11:59:58AM +0200, Christoph Hellwig wrote: > Instead of using xfs_bmapi_read to find delalloc extents and then punch > them out using xfs_bunmapi, opencode the loop to iterate over the extents > and call xfs_bmap_del_extent_delay directly. This both simplifies the > code and reduces the number of extent tree lookups required. > > Signed-off-by: Christoph Hellwig > --- > fs/xfs/xfs_bmap_util.c | 84 ++++++++++++++---------------------------- > 1 file changed, 28 insertions(+), 56 deletions(-) > > diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c > index 06badcbadeb4..f2b87873612d 100644 > --- a/fs/xfs/xfs_bmap_util.c > +++ b/fs/xfs/xfs_bmap_util.c > @@ -695,12 +695,10 @@ xfs_getbmap( > } > > /* > - * dead simple method of punching delalyed allocation blocks from a range in > - * the inode. Walks a block at a time so will be slow, but is only executed in > - * rare error cases so the overhead is not critical. This will always punch out > - * both the start and end blocks, even if the ranges only partially overlap > - * them, so it is up to the caller to ensure that partial blocks are not > - * passed in. > + * Dead simple method of punching delalyed allocation blocks from a range in > + * the inode. This will always punch out both the start and end blocks, even > + * if the ranges only partially overlap them, so it is up to the caller to > + * ensure that partial blocks are not passed in. > */ > int > xfs_bmap_punch_delalloc_range( > @@ -708,63 +706,37 @@ xfs_bmap_punch_delalloc_range( > xfs_fileoff_t start_fsb, > xfs_fileoff_t length) > { ... > + if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) > + return 0; > > - /* > - * Note: while we initialise the firstblock/dfops pair, they > - * should never be used because blocks should never be > - * allocated or freed for a delalloc extent and hence we need > - * don't cancel or finish them after the xfs_bunmapi() call. > - */ > - xfs_defer_init(&dfops, &firstblock); > - error = xfs_bunmapi(NULL, ip, start_fsb, 1, 0, 1, &firstblock, > - &dfops, &done); > - if (error) > - break; > + while (got.br_startoff + got.br_blockcount > start_fsb) { > + del = got; > + xfs_trim_extent(&del, start_fsb, length); > > - ASSERT(!xfs_defer_has_unfinished_work(&dfops)); > -next_block: > - start_fsb++; > - remaining--; > - } while(remaining > 0); > + if (del.br_blockcount && isnullstartblock(del.br_startblock)) { I think there's subtle behavior here that warrants a comment (and describes the somewhat funky logic). E.g., something like: /* * got might point to the extent after del in some cases. The next * iteration will detect this and step back to the previous extent. */ Alternatively, I find separating the if/else a bit more readable (see the appended hunk). But otherwise looks fine: Reviewed-by: Brian Foster > + error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, > + &icur, &got, &del); > + if (error || !xfs_iext_get_extent(ifp, &icur, &got)) > + break; > + } else { > + if (!xfs_iext_prev_extent(ifp, &icur, &got)) > + break; > + } > + } > > return error; > } > -- > 2.17.0 --- 8< --- Reviewed-by: Darrick J. Wong diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index f2b87873612d..0070b877ed94 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -727,15 +727,22 @@ xfs_bmap_punch_delalloc_range( del = got; xfs_trim_extent(&del, start_fsb, length); - if (del.br_blockcount && isnullstartblock(del.br_startblock)) { - error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, - &icur, &got, &del); - if (error || !xfs_iext_get_extent(ifp, &icur, &got)) - break; - } else { + /* + * A delete can push the cursor forward. Step back to the + * previous extent on non-delalloc or extents outside the + * target range. + */ + if (!del.br_blockcount || + !isnullstartblock(del.br_startblock)) { if (!xfs_iext_prev_extent(ifp, &icur, &got)) break; + continue; } + + error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, + &got, &del); + if (error || !xfs_iext_get_extent(ifp, &icur, &got)) + break; } return error;