From patchwork Wed May 30 10:00:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10438263 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 B9E7E601E9 for ; Wed, 30 May 2018 10:01:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB944288F6 for ; Wed, 30 May 2018 10:01:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97FD8288F3; Wed, 30 May 2018 10:01:25 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID 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 19E7A288EF for ; Wed, 30 May 2018 10:01:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F01B66B0283; Wed, 30 May 2018 06:01:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EB07F6B0284; Wed, 30 May 2018 06:01:00 -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 D502A6B0285; Wed, 30 May 2018 06:01:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id AB8236B0283 for ; Wed, 30 May 2018 06:01:00 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id t17-v6so9712269ply.13 for ; Wed, 30 May 2018 03:01:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=myWCdy02JBaMkr/dgxIxpBpZZDwEKfw04mc3m234VwI=; b=o7GASDK3na9YmXQw4GiOtpwIe85iJwx+GWWtCiZXlsbt9R95WRfFd0YwQvb5TDVQ3e O0Hf8sjhRRiYzGHQvJ5k+tLQs3TAegxt//bMHfRv9zuyEpr+etLQuh73uuPTEY96A1/2 cXOvvt1qEzR6qaEHgpV5RZfoZSrPHGQ6vkz9yL7AspVmXbajaxCN0hLEc5aJKoqDaZ8X 0+3FpQhRxzdbZl4cfRFov9hl9xyiKvPVaETms8qUo1AHX3mUpvfwxuHOibBI4RTGdUIU +nfm4DTEqBMcR45qtKVFy9A6LQnL2bFpjtAAIFeDAXmCSREzB911zZCEsOir+7nMP8st X4XQ== X-Gm-Message-State: ALKqPwdVfIAA2Rtvth2YnuavSUFCARc1sIbvXXtB5qSUw2sOqaR0A0s5 QpQZOXxhaoPzvYt2hyULy0zehJ4n8D1TUWvOZbmsX2K17DmRmBpgIq8+K23hFS3xjy9u2OuolUc fprB8WNwivRjv4DkrrdVo5rN0HpIjcKuSdfqwporSjs7pRszifE2uLRM5XkNCezU= X-Received: by 2002:a17:902:20c9:: with SMTP id v9-v6mr2210677plg.206.1527674460391; Wed, 30 May 2018 03:01:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIU4nODYAGNrxzHYkifDyB8toIPFCFDJYD0PiNvfOJZP/QSMy+Aysi6Pb1mYEHLQ/rZ5U5Q X-Received: by 2002:a17:902:20c9:: with SMTP id v9-v6mr2210616plg.206.1527674459546; Wed, 30 May 2018 03:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527674459; cv=none; d=google.com; s=arc-20160816; b=Vtw389PaemnBC1r31wKDEI1OaHY5klf0RM9/03kSZrubLm4GFWF47jX+E5OATXzkjM /7udWcsKnptE/gDwdh7CETGqQSccqX/z6ggWRT8RIkxaspcWYg2SOzMckDF4R+vqp2Nw ZOBbD4eh5fH2IgMbshDjOGxCUGx0Uj53XvMg/3WCHEVqUiaENWWjJgP2blehm5GxKh3U 5GF7mxtt0DTzgfreL7gCMalmdbLhai+DzWj9gUGd8CAzqG+UKUiOOWw+TPYwLHcWKKSf dEpVVqT2N8Mwg4t/TEFfMEGyKlONyw3ixvkJ/em/vNQ5gUlu1B9EBqqelnV4CXPlziLv yXkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=myWCdy02JBaMkr/dgxIxpBpZZDwEKfw04mc3m234VwI=; b=enJ70Y2U0XPcn4k5Oe6khsNOvTz0ylxoimSKmpYAxExei0EiFx4hqXsajWRnW099mg flMWXaZpZPOSa/CYJsVzf8jhgXEp1GVJ8MaGa5igSs8Y++Ul4pg2XL5Q+KJO1bVXk+EJ CRvIdLqGp/tAoU5/aeTw4RIlyVy0HmEcIOAtSVBnh/50hrWpLJmizWZFQCnAUPy+7v5O +XaVlryeCh1bgSfLJXg4UsoduCuzTu9W2IrBVxOzHofsbSS3Fjr8ZCqVoOll8O1HTjLY HjCgbkIaKZKLRSfbiLeuNmr7b8+mypyn+Pkn4Xb8P2ba81+srn1DkiAqZXQNmuRy43bS wyeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=rDxv9uVL; spf=pass (google.com: best guess record for domain of batv+1f4557cc97fec8e307c5+5393+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+1f4557cc97fec8e307c5+5393+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id o7-v6si34415033pfh.103.2018.05.30.03.00.58 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 03:00:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+1f4557cc97fec8e307c5+5393+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=rDxv9uVL; spf=pass (google.com: best guess record for domain of batv+1f4557cc97fec8e307c5+5393+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+1f4557cc97fec8e307c5+5393+infradead.org+hch@bombadil.srs.infradead.org 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=myWCdy02JBaMkr/dgxIxpBpZZDwEKfw04mc3m234VwI=; b=rDxv9uVLHicJZPXEuogEDxGPS crNAivAJFxgMalN6A88bIhO18OCq7M+0Rm7aKVxs42B1off74/lf7RBAjtTUa6J0HdSLc1TN7YK4d ifjPwX4E5uionvVPUNV2ATUBeogxxr8faTkPWPS7UbpyGlGJn2+yYoHy0Tiiq1mUj8KQ8BR5yoJF8 rFRS3FMxUwgZUkEKboiAvT1vNtd+qTI1XOmyY8YVYSmnQ8QUHVaRyg175o6k/A4h/EkZZ0IZP670j Y6Cnn5oKq6jXIVCGvTB7vW4QluAibQfGvpZmwC+507LMZuoQXXzgeDb4rL87tgFzCO2MMqRZFaXW2 w2tCrXePg==; Received: from 213-225-38-123.nat.highway.a1.net ([213.225.38.123] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fNxuZ-0008RS-RB; Wed, 30 May 2018 10:00:56 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/18] xfs: remove xfs_reflink_trim_irec_to_next_cow Date: Wed, 30 May 2018 12:00:04 +0200 Message-Id: <20180530100013.31358-10-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180530100013.31358-1-hch@lst.de> References: <20180530100013.31358-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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 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 Reviewed-by: Darrick J. Wong Reviewed-by: Brian Foster --- fs/xfs/xfs_aops.c | 25 ++++++++++++++++--------- fs/xfs/xfs_reflink.c | 33 --------------------------------- fs/xfs/xfs_reflink.h | 2 -- 3 files changed, 16 insertions(+), 44 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index e2671b223409..587493e9c8a1 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -383,7 +383,7 @@ 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 = NULLFILEOFF; int whichfork = XFS_DATA_FORK; struct xfs_iext_cursor icur; int error = 0; @@ -407,8 +407,9 @@ 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; + if (cow_fsb != NULLFILEOFF && cow_fsb <= offset_fsb) { xfs_iunlock(ip, XFS_ILOCK_SHARED); /* * Truncate can race with writeback since writeback doesn't @@ -430,6 +431,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, @@ -454,21 +459,23 @@ 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_fsb != NULLFILEOFF && + 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); trace_xfs_map_blocks_found(ip, offset, count, *type, imap); - return error; + return 0; allocate_blocks: - xfs_iunlock(ip, XFS_ILOCK_SHARED); - if (!error) - error = xfs_iomap_write_allocate(ip, whichfork, offset, imap); + error = xfs_iomap_write_allocate(ip, whichfork, offset, imap); if (!error) trace_xfs_map_blocks_alloc(ip, offset, count, *type, imap); return error; 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,