From patchwork Fri May 18 16:48:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10411321 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 153C76031B for ; Fri, 18 May 2018 16:49:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0500828619 for ; Fri, 18 May 2018 16:49:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE11C288BD; Fri, 18 May 2018 16:49:57 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 8D9EF28619 for ; Fri, 18 May 2018 16:49:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750882AbeERQtw (ORCPT ); Fri, 18 May 2018 12:49:52 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50814 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752447AbeERQts (ORCPT ); Fri, 18 May 2018 12:49:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9XpA3czMmiBtJpZDdKHeHP4WkMo4hX7IuQzvbyG2+vo=; b=d0pdCvSwZWBB4WcRoWV15g77N 8LgmRwg48uNsAjqlHLzfko97pWoFiRuHL7a9fGsfKiakB/4ilZaxYViaHBJ7Lww1QptkYBxZA/k4C /RDNQQvf1CF+OaOHrOJwA14GOGtvJfx2UWnssNaa92EMTosvwllCD8eNUr9D8C3hlL3Nt/Va7GDZE JJHSUKlaS/2L/qvdMVl+cDNtvPKiV0ysBPGbRwtZ5eZkT/jpmWufIqOm4ruYkOqRRClHQAAMt21QM zjql/Sc6YFa53e9YjZfKVvJQhVof48oDlwsguJz0gbgKoWqpA/QNzHP1bNcLf/xBpohUP6eP4Bn22 vskVk/uAg==; Received: from 80-109-164-210.cable.dynamic.surfer.at ([80.109.164.210] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fJiZe-0006tt-Au; Fri, 18 May 2018 16:49:46 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 25/34] xfs: remove xfs_reflink_trim_irec_to_next_cow Date: Fri, 18 May 2018 18:48:21 +0200 Message-Id: <20180518164830.1552-26-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518164830.1552-1-hch@lst.de> References: <20180518164830.1552-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the only caller we just did a lookup in the COW extent tree for the same offset. Reuse that result and save a lookup, as well as shortening the ilock hold time. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_aops.c | 25 +++++++++++++++++-------- fs/xfs/xfs_reflink.c | 33 --------------------------------- fs/xfs/xfs_reflink.h | 2 -- 3 files changed, 17 insertions(+), 43 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index a4b4a7037deb..354d26d66c12 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -383,11 +383,12 @@ xfs_map_blocks( struct xfs_inode *ip = XFS_I(inode); struct xfs_mount *mp = ip->i_mount; ssize_t count = i_blocksize(inode); - xfs_fileoff_t offset_fsb, end_fsb; + xfs_fileoff_t offset_fsb, end_fsb, cow_fsb = 0; int whichfork = XFS_DATA_FORK; struct xfs_iext_cursor icur; int error = 0; int nimaps = 1; + bool cow_valid = false; if (XFS_FORCED_SHUTDOWN(mp)) return -EIO; @@ -407,8 +408,11 @@ xfs_map_blocks( * it directly instead of looking up anything in the data fork. */ if (xfs_is_reflink_inode(ip) && - xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, imap) && - imap->br_startoff <= offset_fsb) { + xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, imap)) { + cow_fsb = imap->br_startoff; + cow_valid = true; + } + if (cow_valid && cow_fsb <= offset_fsb) { xfs_iunlock(ip, XFS_ILOCK_SHARED); /* * Truncate can race with writeback since writeback doesn't @@ -430,6 +434,10 @@ xfs_map_blocks( error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, imap, &nimaps, XFS_BMAPI_ENTIRE); + xfs_iunlock(ip, XFS_ILOCK_SHARED); + if (error) + return error; + if (!nimaps) { /* * Lookup returns no match? Beyond eof? regardless, @@ -451,16 +459,17 @@ xfs_map_blocks( * is a pending CoW reservation before the end of this extent, * so that we pick up the COW extents in the next iteration. */ - xfs_reflink_trim_irec_to_next_cow(ip, offset_fsb, imap); + if (cow_valid && + cow_fsb < imap->br_startoff + imap->br_blockcount) { + imap->br_blockcount = cow_fsb - imap->br_startoff; + trace_xfs_reflink_trim_irec(ip, imap); + } + if (imap->br_state == XFS_EXT_UNWRITTEN) *type = XFS_IO_UNWRITTEN; else *type = XFS_IO_OVERWRITE; } - xfs_iunlock(ip, XFS_ILOCK_SHARED); - if (error) - return error; - done: switch (*type) { case XFS_IO_HOLE: diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 8e5eb8e70c89..ff76bc56ff3d 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -484,39 +484,6 @@ xfs_reflink_allocate_cow( return error; } -/* - * Trim an extent to end at the next CoW reservation past offset_fsb. - */ -void -xfs_reflink_trim_irec_to_next_cow( - struct xfs_inode *ip, - xfs_fileoff_t offset_fsb, - struct xfs_bmbt_irec *imap) -{ - struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK); - struct xfs_bmbt_irec got; - struct xfs_iext_cursor icur; - - if (!xfs_is_reflink_inode(ip)) - return; - - /* Find the extent in the CoW fork. */ - if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got)) - return; - - /* This is the extent before; try sliding up one. */ - if (got.br_startoff < offset_fsb) { - if (!xfs_iext_next_extent(ifp, &icur, &got)) - return; - } - - if (got.br_startoff >= imap->br_startoff + imap->br_blockcount) - return; - - imap->br_blockcount = got.br_startoff - imap->br_startoff; - trace_xfs_reflink_trim_irec(ip, imap); -} - /* * Cancel CoW reservations for some block range of an inode. * diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index 15a456492667..e8d4d50c629f 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -32,8 +32,6 @@ extern int xfs_reflink_allocate_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap, bool *shared, uint *lockmode); extern int xfs_reflink_convert_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); -extern void xfs_reflink_trim_irec_to_next_cow(struct xfs_inode *ip, - xfs_fileoff_t offset_fsb, struct xfs_bmbt_irec *imap); extern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip, struct xfs_trans **tpp, xfs_fileoff_t offset_fsb,