From patchwork Wed May 30 09:59:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10438215 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 117E7602CC for ; Wed, 30 May 2018 10:00:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0251E288ED for ; Wed, 30 May 2018 10:00:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB736288F4; Wed, 30 May 2018 10:00:45 +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 6CD05288ED for ; Wed, 30 May 2018 10:00:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DB196B027C; Wed, 30 May 2018 06:00:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 539156B027D; Wed, 30 May 2018 06:00:41 -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 4099C6B027E; Wed, 30 May 2018 06:00:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id E92F36B027C for ; Wed, 30 May 2018 06:00:40 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id t11-v6so4981271pgn.9 for ; Wed, 30 May 2018 03:00:40 -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=0OfOqN1lxegz/1awq0SxQv8HJnRmF2FXaCLvFI7v25A=; b=teuw4L1Ti8C779kx8LIj454amLWHz4MysF6TcznCPXkDaVb8KOchzwZvjYUHWRaSop jwP8rNnG+IvfT8uzTwnvwDif+oTDlv11G+zi30HnrNvHuYAfHsv1D7Ik2xc19bL5lvI1 tCfwcRajjq7FA8xcnXCYIcaWk3PErzrLNx70LpwuYTkyJvk0MdvF953eQv+PZR0mxcSj fgCVlhSXoJyammHW0FW8SfKvYpSurHP8VA4C/1BpJQwPBsQW9hGa1/UXEJos8ekOR9Q5 VCzYzJgA/mMQNFdUfQg1vOkPf20+3zudpfwe3ZRwMsFDHAUGaRcWCJ4U5+7IwIN+A1sG 01Uw== X-Gm-Message-State: ALKqPweIDKhRbDNNlJLKx10v8ifSUnarVYvepysKP5k3K+jPlhyXke3b CKtbk3DnlgpURvEM/GkWaeugleAQ3OtkqgQMU9grGBqHLW8uL1UhObLNo+Y5MeH4m3vHMU1/zOa RC/lI+pjQnKlo5k0heBXe8K/IxTf6fdmQOUfOCxIdT8ZDmG6ZmUCBxFbSZzyznWY= X-Received: by 2002:a17:902:6bc1:: with SMTP id m1-v6mr2196077plt.91.1527674440651; Wed, 30 May 2018 03:00:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJW1VsJwL05LHmlwDmm6MeYY9knPu18Z/nUlvFsmdC1cK15LryXQl2wmKQVPhot9XBCLUuB X-Received: by 2002:a17:902:6bc1:: with SMTP id m1-v6mr2196002plt.91.1527674439725; Wed, 30 May 2018 03:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527674439; cv=none; d=google.com; s=arc-20160816; b=VCSgXxMoi2H+Nyv7U/n/Ho8X2L/a11REJradO1XIDV3jgdh6nxmf96BhZndLybDuXx 4MkbuFoGyuu9WU99WjKuh8rXSLjdpopPILsf6POuO/C99xWsxG+Lnwafdi9QGInMOdyP rTQfNNsYNL/JUPGpnmHjAXUlfvVVVSzIafIkj0wDMF9hnnprmQwEN0qNxJSs6bFPGahB A5VbjBE4e2V0X0scV8T2XPv8fVmHy/0d8bL3zLLnd6hZ4XNocs2Ss7fzPLJ9NSDBEkAl uHd3+Abtjp46JvdDL4KRFAOAnt5Su2R+u0ScGs7pqhOZ/SphVm9T4gaOv8V1aV9oMu/4 1YGA== 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=0OfOqN1lxegz/1awq0SxQv8HJnRmF2FXaCLvFI7v25A=; b=pcp2ivlMljtnhf0w0ZWI7yjXepQRVwQ+ckKXlATgx+ZXjnULmcb2ytLlaDZo969lGw 2ZTruUgeDU1xer1jXKbVaOaBkqcHggm5ytBNtMrQL+IXdhlSGJ4umFUMZ3MeE5jL0vd+ Y1RVSzbVri17VvuiiDgyAeVOg//UFaSwUmKAXKsBGODBDeX/RDil7B/joDls9jaJh7Ns kGo2tXW32Yzr7ZByU2OuQb4SuHYKJ23Kgk6yz1AUdIH6RTArjX2M0/8BNg7fzjvNbYK+ KMGWm5jdEaWH9bIB++/z/1Z27JF7zGokJVF3c9meRRXEBl5M+euD3v95aLB5gMxvDhhX U26w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=SPMJpcX4; 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 1-v6si34735086plw.519.2018.05.30.03.00.39 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 03:00:39 -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=SPMJpcX4; 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=0OfOqN1lxegz/1awq0SxQv8HJnRmF2FXaCLvFI7v25A=; b=SPMJpcX4egVECMQx12ijmM0Nc /g7/wXYwx/8ueD47PqdUz+1BZE8C8NJWHFEO9Mk+oPvw2XZOPgvbGsREe6euJZ6zPOywrVI/7yDzX wXMTH1DnfN7Ytg5WfA1+UuBysXicQXCROfHZyFv+Bxks7e96nvGeacTmptTvAwOpaeP6SfMSl4XDr 2jSxXY63P36TTHpPKQZyVVs8EWHngTt1zkd9sGEMnNmpkjU2C4Q+j2YIRANipZXwxAwRh21NQET1P yAqN0QguxqQY7KE7+FYE019OeiHVWZnQ6xfh/bpX+bLOYxbgXwLHD4/5IaVlzgOsVPs1rC2N6V67V 6WK+SQdLA==; 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 1fNxuD-00083F-PC; Wed, 30 May 2018 10:00:34 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 04/18] xfs: simplify xfs_aops_discard_page Date: Wed, 30 May 2018 11:59:59 +0200 Message-Id: <20180530100013.31358-5-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 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 Reviewed-by: Brian Foster Reviewed-by: Darrick J. Wong --- 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 c631c457b444..f2333e351e07 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