From patchwork Fri May 18 16:48:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10411315 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 5A6926031B for ; Fri, 18 May 2018 16:49:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ACAD28619 for ; Fri, 18 May 2018 16:49:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FA9C288BD; Fri, 18 May 2018 16:49:50 +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=ham 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 A0D3228619 for ; Fri, 18 May 2018 16:49:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D9296B061C; Fri, 18 May 2018 12:49:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 33A8F6B061E; Fri, 18 May 2018 12:49:33 -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 18C556B061D; Fri, 18 May 2018 12:49:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id C4B686B061B for ; Fri, 18 May 2018 12:49:32 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id b36-v6so5392104pli.2 for ; Fri, 18 May 2018 09:49:32 -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=U6RiyySxRShxlIOxyZUWd6C6r6vm8wKIKEc/1y/5OaBINtR2w0S9G8I8fKKSdTQgCb 8iluxYCUINhZDHb6dI/suNyb5QEv09JgG+Fv81VoQr2CWov9BwadoygtwMbctJ+rNR+l 9eI5avqdo5/9YfLnNS80mIbSdIAlK0TM6UVB/55cErJTxr2C+CnO0hA8S0PU0vxcbZcU KWyXoGtJiyk7coW5NlskWw76JB4IkWBjku0k6T6VePcjGvHCEUYI9UHkJMPeKh5M8tF6 Y32crpq21OAL/9uS0kTR+NH7ilzfryhC7/IT4xRDGVmijLD84fJbMsyb9bJV5lzXEE+i j5sQ== X-Gm-Message-State: ALKqPwfCDkH4D6SsaESGCA9flouP02JILsZO3n0/1uMBX2fUdwIPpSEY pHHuZdiaXRyA/7iD4npqWJjakL6e49QPDvHvqokdMkr6/CAb8i8FMpDM7NAdq6gXPRylornsVuX Tp5sgbT9++sRZxW1iuIKj6MI3p+0J6Ob6pzcViGPKx4R3D5E8VS9NVjKmGckokCA= X-Received: by 2002:a62:dc4e:: with SMTP id t75-v6mr10105825pfg.139.1526662172478; Fri, 18 May 2018 09:49:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpJ3Q0x9Wj8xjjypXaVeoFq0HmUPICj8yDgP8Hlbv65oUrXtvuCtkvov/VcGI1fy/Mw7m0D X-Received: by 2002:a62:dc4e:: with SMTP id t75-v6mr10105788pfg.139.1526662171706; Fri, 18 May 2018 09:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526662171; cv=none; d=google.com; s=arc-20160816; b=WafsrfrQkVLwfmHwWm5KXIz2fsAYdPRHqsuhTd0kRUVsWm1A3Ts2rLrERsO7pCpQq/ x04/Tw5nl4B+VQz4QH7BHpEoOY5fPGS6BqF6q7ngPYZA4DKaCooWCUNwgdgPm7/OmsGc gRDJwRPVmzrTFs+LCRYHbqxPWxQ7kLMlWBBrSWj9+jhdjasTOsVJ51dAzNPSwWg0cq/1 3jWqkyHg8JAhtHCZN7482ZocWwC0xy4iXnygRYm5uc4fFIrt6ls/A8dlF+I4PKkbxUSw 6p2kChS4DqYfApLn5XVdvz4uzHZzlu+9M+6DXGFoFDigoFfWafcgwDm6gDkDqkvJpDqc a3ew== 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=q3lEIHivhdSoLETPpw6tXToVpm0o9tGNcBWVeeW0cLGDLprBULXw7cgI13M6E90Avl tD3VcaTBu12LCI+mhTgMpX4hv8hchQdW5QRMdZcvXLvxRwU2NLVGKXBPjxqmggyE/AIO K+Vr5vVJfqQKfAsAgLmJAloo4nYl5KllCQyJOZsVepaQ2KIYR6xNgNNauImCiImg6IYG j3qoK4S0eBRF0qcrVVYsLHsPjrDjQNxz7luWWL4eig/X16dx6orIke6oeB0kkC04d379 zr4V3CfNmcAbgv0BUrFollJGucXla3LRk6dLxUzjW3MRkueZciuJF1yz8F3zGRl7wiqX BwDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=kxmgNjte; spf=pass (google.com: best guess record for domain of batv+77ddf8e9b1b344f28472+5381+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+77ddf8e9b1b344f28472+5381+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 h68-v6si8166395pfa.238.2018.05.18.09.49.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 09:49:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+77ddf8e9b1b344f28472+5381+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=kxmgNjte; spf=pass (google.com: best guess record for domain of batv+77ddf8e9b1b344f28472+5381+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+77ddf8e9b1b344f28472+5381+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=kxmgNjtehQnqPsX2UxN4Y5VlV zU7qa6Ni3mOnZ0l5WEGDeB9K3bzQUcqwgC2hYkXjRKTxnxKq9pfe1dcsurKSczo2lmgGHpmcV/yvD mSR0QS9VNnEIZwolG0kI+ky0ApEqPW7RBStc4l+rpj51WzY1POisbL0hmyLsqtYhEEQe9zy+wWlhl IueAAcKOzYVBO+jY9qtrQqWc+XQY4CnFyvuykxapGTW+7brQhEJzeuyfYcimNiCgBjyBGRaMF9JzJ hlWKuGvknQ+4x5vS0TJQQ/GqP7XNXPpqWcm9iOrW/MQvg6XZDELNmnxqkrJpUHDErMGvLv6VBm8uT FEMtdOd1A==; 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 1fJiZO-0006m6-Qz; Fri, 18 May 2018 16:49:31 +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 20/34] xfs: simplify xfs_aops_discard_page Date: Fri, 18 May 2018 18:48:16 +0200 Message-Id: <20180518164830.1552-21-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 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 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