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: 10439005 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 72BAE601E9 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 5E05728DEA for ; Wed, 30 May 2018 13:35:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5283128DEF; 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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 E97B428DEA for ; Wed, 30 May 2018 13:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753079AbeE3Nfl (ORCPT ); Wed, 30 May 2018 09:35:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56099 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752634AbeE3Nfl (ORCPT ); Wed, 30 May 2018 09:35:41 -0400 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) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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;