From patchwork Wed May 23 14:43:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10421617 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 76F6560545 for ; Wed, 23 May 2018 14:45:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67EB228733 for ; Wed, 23 May 2018 14:45:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C7D5288B2; Wed, 23 May 2018 14:45:41 +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 DF4AD289B1 for ; Wed, 23 May 2018 14:45:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14A3C6B027A; Wed, 23 May 2018 10:45:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0D1266B027B; Wed, 23 May 2018 10:45:08 -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 E90EA6B027C; Wed, 23 May 2018 10:45:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 9FE366B027A for ; Wed, 23 May 2018 10:45:07 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id x21-v6so13086629pfn.23 for ; Wed, 23 May 2018 07:45:07 -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=Uiw5YPeaNXJMng7AxpenpSuolqG9C6H+bTosdL8+Uz1khm8o9bGq/kiuAWiJkN2tC5 YCP0h1yN74shoGT6rH6SzUxWVYDiJTEP2RQQMcQrOYprnlmP2nN66Jv3qVbJE8qnq9tq f670Ca8M0o8Jbg8z9J5jDfxtNYsS6ha17HPyuN9/SxdNEMbey88OEd5MY3IS1Zaw9tMF uSrprRqr9vmIz4FL3njKYBt7ShFKp7a6B1OVoGvxXSnYP0JdqF+5w0WK0z6Q+rN4SFLw C4PRMG8ErO+BK8mEzqRwmPt8KJ6jUszt6hGQfOZ2re/SXEaMVj835kh13/Wf1zdo+X4C ppWg== X-Gm-Message-State: ALKqPwcrxjzMuvhnQwGSaXKyC9M8AUJpoh+C7ANYjwLFWeuJ6Vbb2eWB CeMZIni9QNGyefsu7si5Py5LkYfqiCMbqfsvjw/KwHs9SjOOGAcDzfdq93ZW4he+px1wbIO2j8X JFa0FE/cdw3YFixeFGkCKpY+gml3fqMYmLlF+AEIPXGDuPy2aJoSJ3GoRwG8ryTE= X-Received: by 2002:a62:399c:: with SMTP id u28-v6mr3201126pfj.95.1527086707320; Wed, 23 May 2018 07:45:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZovlqNKsvnDxgr7PyV61ngUykxH0mddiUJGQCrkAJHi/xNj1Ugo41jX7rGaJcCpNzSPrcCv X-Received: by 2002:a62:399c:: with SMTP id u28-v6mr3201074pfj.95.1527086706344; Wed, 23 May 2018 07:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527086706; cv=none; d=google.com; s=arc-20160816; b=It89Wv19wQOyA7ImkL1tGsyt6eR+ug3A8JeyP4aBkUHy+OeBLjVVWw7eAfgQwnL0u3 PKYMTKUM+iYORM8xCz5i0GOrZR6VP4l3ld5InXgqyTx2g1917zAwtVAdozc8ud/tmZS8 n8vGmcwFJcmHqsWIleHKAs6rNYVmUp8P1wEdfRIHer9nbpnhBGym/bBcV4Ht0LLr0/Ub iawrfd9hz1lq8s4Q9GYtwv9eoCfANDfyEHet4ouZCyhLuhADZWOsMUk5UFfZWLTFa9uZ 261QWgQijJIvxmtce890gQQadXp6DI2SHjRQ4THTPXEVQHzCPyVlSosCG+iSkeAGG6At Bmtg== 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=YrNEUyyJIVuc25fMjflO3z2dBiOlOo4WZVwFMp1QyQ+AHPi3vqtLrMrS8yCCgdn92U Djha8wufEJgghBSqAsP+mKq4EXX34k1FemgENMctq0o86TeLNIykrEHC9Hdzy69ZgX3w 6mPv20sXz49m/dP3aBVC6ShvCMNVu6NY5o6+ul0U/nWM4oCMKJTWu8rztElA1lz3qYMy fZYYxe3kL17JFX1hfwXcxDDzbsxhlZ0UV2vgmDD0pieV7WQtvJtF8/Wb4i7re6458Oaa ao54dITrE8UWkmHrpQPaoH6i/dNjx1A8DkxvuwN5JczgF1RbfEMQP6P150RWq26vHgeQ c5hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=iGCzvZgf; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+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 t12-v6si15157653pgr.690.2018.05.23.07.45.06 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 07:45:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+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=iGCzvZgf; spf=pass (google.com: best guess record for domain of batv+df5a2477ff0fa86e9985+5386+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+df5a2477ff0fa86e9985+5386+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=iGCzvZgfgEFLFF7uBpEQpvV// 3EhEbS6suLaW8q+EqzR/R7yaAVjmsIR7Ak8HgeDMlzeqHjK6ednduMiM/92a0JGnaCeJ8pTPbgRAG FNbKJ33HHdtJ46TOb/Pr97taSOIY2VWzzbFP1nlL4X95wdrkUAj4d3ypoZwyEf8PIBrv7YxKReW2j +032kGy5R1lQOICsjyH25Z+JvStcLK4QWlpCmfYtdtnUGibw5lsxqD+C/Ld26JRpQotVdJJ0s+hMd alPRNZ37nLc73PsN9YI0ACr0CCnSiiu7dx6ukACgxNf4udYz/mr1rkCngBbCep9FPDHmhNAs5GipE oQPh/I01A==; Received: from 089144199016.atnat0008.highway.a1.net ([89.144.199.16] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLV0g-0000Zz-2n; Wed, 23 May 2018 14:45:02 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 20/34] xfs: simplify xfs_aops_discard_page Date: Wed, 23 May 2018 16:43:43 +0200 Message-Id: <20180523144357.18985-21-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180523144357.18985-1-hch@lst.de> References: <20180523144357.18985-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