From patchwork Wed May 9 07:48:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10388393 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 D60AA602C2 for ; Wed, 9 May 2018 07:49:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C948B28E05 for ; Wed, 9 May 2018 07:49:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE34328E2B; Wed, 9 May 2018 07:49:34 +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 25AEB28E05 for ; Wed, 9 May 2018 07:49:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 239B36B0358; Wed, 9 May 2018 03:49:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 19C1A6B0359; Wed, 9 May 2018 03:49:28 -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 E6A196B035A; Wed, 9 May 2018 03:49:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 9FE976B0358 for ; Wed, 9 May 2018 03:49:27 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id c4so25787569pfg.22 for ; Wed, 09 May 2018 00:49:27 -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=EclpvJel1JSdJnNsYJD7VfMKbcBE+yGn6V9d/lBzoLI=; b=LSPXYh4SbNMCV/I+X7pDPQ4E42vRUxkm7isN/NkCSxg9rOKaIKjgvcISaP1Jq2wy4e DXYkIAFDhV5K6Xlap8b2yTXuQLCPpL28jXtHPrQiQBhP1ZJOKv+HgjbL/C1YN0s2EwUD RKrDMEaapDZXCjszyUHOMLPGjUsU2yJvvzaM6KkJ7o8GDPhBTXMCYJfmQFXZQC79nH/x Lnj5izRdVCTf+wDIoDKLemTe5oSC2rbcK4Ydh4BbWGRvGvlwKR1Ud6Eb2sEgcjzjvmH6 DTuNhKWJIvkyYBbjz4adpNgrzh6IblR6tyJEGARfRASL3IGkPs4vZhNA+Vpi7RTfdzum 1K/A== X-Gm-Message-State: ALQs6tBbaj5y7Tp03zsjnr5qvsiK8GF2xjAcUnTsFebDiWcCT/mtKE8Y KOgyLfbW7f7KypbG9Co0sT4ONL12XRp4hwtEXhLUCTGEyF/o0xNhLDi7yFP2miZhiGGOCtMDJ1s nN7pUf2/di3kxZz6QfsK0+0RfXeHiiQq9ZlxVQHfYch358z6QH31v423oZFT2Q+A= X-Received: by 10.98.138.193 with SMTP id o62mr43252762pfk.141.1525852167338; Wed, 09 May 2018 00:49:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoZo5KihyiCno9cukciWLZvqjSNTRsR9xZPd0dXf63g9FVZUDR90eE+52Zb9hRcBlT4z2nh X-Received: by 10.98.138.193 with SMTP id o62mr43252719pfk.141.1525852166501; Wed, 09 May 2018 00:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525852166; cv=none; d=google.com; s=arc-20160816; b=flV0RnBFZpF8ELS6+UnzIwUhNU6Kv3NsdHuj8OlfOQx+4CWNVJ9gcEQm9mUam1KVxy 895hMOOg56ukxDaqQl3SHs82vWNM1zgfllONqc735v7N+tsbX69D+AreXPcvRDXfYtrV qR0AFh8zzBnDdrDVpK/OQJ/ymdKrdNLGN6kZPNP4m69+lmQhTZfMgRxepm7BbAAWweTL aqtK+VW9jUp4h6uN4VDDQGxFXwjdFQVPP+UX+g2n/8AKgUIZbbiIQeuGiEvKzP6pVGic v5kw7IPD8+5CRc753NQunqtCWBHke7tKsOBKQLnwL8hVjyZbmB8ShaoVNdRRCrW3irdI cefQ== 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=EclpvJel1JSdJnNsYJD7VfMKbcBE+yGn6V9d/lBzoLI=; b=KQbtewKh8W/M6biHTNLaUDgMnx/9cciNrxpXqUqkjCG+naUknfCoxH1IO111cQXrUK G+t0iPqRPR/7R7nzhv+C8jgJCq9Zq5AELWV2IucMds+n8YPQyx3NPm9hu7XzGb4C9Akt +06mRnapJ1exj585E5G16JwPZ7TYvbk7O1sg/UjRDDvDQ5ypd9TSIeRoaJjeGcP8woZe LrDnPGRGp36SI3SWNz2J/Z+3Om9fDYAeyZSHugCuneAeFb9NXtETh18PDC/ZkQmUbut/ TounOW4cJE9f+M36KzkCN0SU+n96p+gRV9P4IeVFFPhQkrbjAbnYNAB2VFDI6/E+tMTu e+nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=tReaO/ZL; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+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 l81si26186224pfj.127.2018.05.09.00.49.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 00:49:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+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=tReaO/ZL; spf=pass (google.com: best guess record for domain of batv+e0efdd19ce80d487e3da+5372+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+e0efdd19ce80d487e3da+5372+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=EclpvJel1JSdJnNsYJD7VfMKbcBE+yGn6V9d/lBzoLI=; b=tReaO/ZLNkf9YzcWsiyaguK7w 6qZlotYUD+6c174lwB6qPejY2i2vejXhoUedp3aiQbplADJov6UuHUFNOn3WEQgzRswR8cT2L1eng SXFIVefXSJyStRl+9ccHksvRlniUSDqGW3o6SSvBhHSl62td/EOOD2UuWZF9U51TEiCYFOxOfdctL KsJbUtCAPm5W2jzhYiJLD5xuXr3ft6XyiBm3YkFU1PzzG5alVQO3w2pNJJbh8GwySl2jwNN4W3gVP fTVsrm09UyrBefOkUrr/njfVLxIfmjQWMDNj/VrC0XlDh/8hsYvkxK1+Dl8McpftjKMytfyzPynwZ xY/L78IKw==; Received: from 213-225-15-246.nat.highway.a1.net ([213.225.15.246] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fGJqn-0001aM-Fs; Wed, 09 May 2018 07:49:25 +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 15/33] xfs: simplify xfs_aops_discard_page Date: Wed, 9 May 2018 09:48:12 +0200 Message-Id: <20180509074830.16196-16-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509074830.16196-1-hch@lst.de> References: <20180509074830.16196-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 Instead of looking at the buffer heads to see if a block is delalloc just call xfs_bmap_punch_delalloc_range on the whole page - this will leave any non-delalloc block intact and handle the iteration for us. As a side effect one more place stops caring about buffer heads and we can remove the xfs_check_page_type function entirely. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_aops.c | 85 +++++------------------------------------------ 1 file changed, 9 insertions(+), 76 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 8e4d01e76fc8..313449ac0288 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -711,49 +711,6 @@ xfs_map_at_offset( clear_buffer_unwritten(bh); } -/* - * Test if a given page contains at least one buffer of a given @type. - * If @check_all_buffers is true, then we walk all the buffers in the page to - * try to find one of the type passed in. If it is not set, then the caller only - * needs to check the first buffer on the page for a match. - */ -STATIC bool -xfs_check_page_type( - struct page *page, - unsigned int type, - bool check_all_buffers) -{ - struct buffer_head *bh; - struct buffer_head *head; - - if (PageWriteback(page)) - return false; - if (!page->mapping) - return false; - if (!page_has_buffers(page)) - return false; - - bh = head = page_buffers(page); - do { - if (buffer_unwritten(bh)) { - if (type == XFS_IO_UNWRITTEN) - return true; - } else if (buffer_delay(bh)) { - if (type == XFS_IO_DELALLOC) - return true; - } else if (buffer_dirty(bh) && buffer_mapped(bh)) { - if (type == XFS_IO_OVERWRITE) - return true; - } - - /* If we are only checking the first buffer, we are done now. */ - if (!check_all_buffers) - break; - } while ((bh = bh->b_this_page) != head); - - return false; -} - STATIC void xfs_vm_invalidatepage( struct page *page, @@ -785,9 +742,6 @@ xfs_vm_invalidatepage( * transaction. Indeed - if we get ENOSPC errors, we have to be able to do this * truncation without a transaction as there is no space left for block * reservation (typically why we see a ENOSPC in writeback). - * - * This is not a performance critical path, so for now just do the punching a - * buffer head at a time. */ STATIC void xfs_aops_discard_page( @@ -795,47 +749,26 @@ xfs_aops_discard_page( { struct inode *inode = page->mapping->host; struct xfs_inode *ip = XFS_I(inode); - struct buffer_head *bh, *head; + struct xfs_mount *mp = ip->i_mount; loff_t offset = page_offset(page); + xfs_fileoff_t start_fsb = XFS_B_TO_FSBT(mp, offset); + int error; - if (!xfs_check_page_type(page, XFS_IO_DELALLOC, true)) - goto out_invalidate; - - if (XFS_FORCED_SHUTDOWN(ip->i_mount)) + if (XFS_FORCED_SHUTDOWN(mp)) goto out_invalidate; - xfs_alert(ip->i_mount, + xfs_alert(mp, "page discard on page "PTR_FMT", inode 0x%llx, offset %llu.", page, ip->i_ino, offset); xfs_ilock(ip, XFS_ILOCK_EXCL); - bh = head = page_buffers(page); - do { - int error; - xfs_fileoff_t start_fsb; - - if (!buffer_delay(bh)) - goto next_buffer; - - start_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); - error = xfs_bmap_punch_delalloc_range(ip, start_fsb, 1); - if (error) { - /* something screwed, just bail */ - if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) { - xfs_alert(ip->i_mount, - "page discard unable to remove delalloc mapping."); - } - break; - } -next_buffer: - offset += i_blocksize(inode); - - } while ((bh = bh->b_this_page) != head); - + error = xfs_bmap_punch_delalloc_range(ip, start_fsb, + PAGE_SIZE / i_blocksize(inode)); xfs_iunlock(ip, XFS_ILOCK_EXCL); + if (error && !XFS_FORCED_SHUTDOWN(mp)) + xfs_alert(mp, "page discard unable to remove delalloc mapping."); out_invalidate: xfs_vm_invalidatepage(page, 0, PAGE_SIZE); - return; } static int