From patchwork Tue Mar 6 19:23:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10262825 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 1E7D4602C8 for ; Tue, 6 Mar 2018 19:46:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D4382912C for ; Tue, 6 Mar 2018 19:46:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 019B629161; Tue, 6 Mar 2018 19:46:38 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9111C2912C for ; Tue, 6 Mar 2018 19:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754149AbeCFTqg (ORCPT ); Tue, 6 Mar 2018 14:46:36 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48726 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932604AbeCFTYU (ORCPT ); Tue, 6 Mar 2018 14:24:20 -0500 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=L58tEN6gAjGqWdCEBSpkYfoj8VFhsagKG4f/Zw+AXjE=; b=uKNw1nFKGoERd0HMdaVNVctpM YOgSSXxUjienxl3J6jFBGBYLt3ANgvvqE1Zmxi05Q0PLVHVMEbWQqRS9CXsrXSiqGfMBodvVU9jTC 25u6aqdcMv/sXCbxjMNbRPFQ8OLOwNgsVUA7xH92+e/iwXDhZ72PE2+RJjIOeXHKunC+I+lIdDSGy LtgZMz5c/zYMmjrr9CNhfALV5oQr6+fEcaNxpUxy4xGytxI2nehEE5wErgRea11+Zl0/bhLf1Cykj 6RsBnJVviHBgFhhJ0nidEuOXUd6GnABOta5fAzVMPVX+K6kufE844fo37mDEY7hKUWOPdTx/wuh2k VpS/Fw0ag==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1etICA-0001Su-OT; Tue, 06 Mar 2018 19:24:18 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Ryusuke Konishi , linux-nilfs@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH v8 06/63] btrfs: Use filemap_range_has_page() Date: Tue, 6 Mar 2018 11:23:16 -0800 Message-Id: <20180306192413.5499-7-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180306192413.5499-1-willy@infradead.org> References: <20180306192413.5499-1-willy@infradead.org> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox The current implementation of btrfs_page_exists_in_range() gives the wrong answer if the workingset code has stored a shadow entry in the page cache. The filemap_range_has_page() function does not have this problem, and it's shared code, so use it instead. Signed-off-by: Matthew Wilcox --- fs/btrfs/btrfs_inode.h | 6 ++++- fs/btrfs/inode.c | 70 -------------------------------------------------- 2 files changed, 5 insertions(+), 71 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index f527e99c9f8d..078a53e01ece 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -364,6 +364,10 @@ static inline void btrfs_print_data_csum_error(struct btrfs_inode *inode, logical_start, csum, csum_expected, mirror_num); } -bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end); +static inline bool btrfs_page_exists_in_range(struct inode *inode, + loff_t start, loff_t end) +{ + return filemap_range_has_page(inode->i_mapping, start, end); +} #endif diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1f5b93ecffca..3340de232944 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7476,76 +7476,6 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, return ret; } -bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end) -{ - struct radix_tree_root *root = &inode->i_mapping->page_tree; - bool found = false; - void **pagep = NULL; - struct page *page = NULL; - unsigned long start_idx; - unsigned long end_idx; - - start_idx = start >> PAGE_SHIFT; - - /* - * end is the last byte in the last page. end == start is legal - */ - end_idx = end >> PAGE_SHIFT; - - rcu_read_lock(); - - /* Most of the code in this while loop is lifted from - * find_get_page. It's been modified to begin searching from a - * page and return just the first page found in that range. If the - * found idx is less than or equal to the end idx then we know that - * a page exists. If no pages are found or if those pages are - * outside of the range then we're fine (yay!) */ - while (page == NULL && - radix_tree_gang_lookup_slot(root, &pagep, NULL, start_idx, 1)) { - page = radix_tree_deref_slot(pagep); - if (unlikely(!page)) - break; - - if (radix_tree_exception(page)) { - if (radix_tree_deref_retry(page)) { - page = NULL; - continue; - } - /* - * Otherwise, shmem/tmpfs must be storing a swap entry - * here as an exceptional entry: so return it without - * attempting to raise page count. - */ - page = NULL; - break; /* TODO: Is this relevant for this use case? */ - } - - if (!page_cache_get_speculative(page)) { - page = NULL; - continue; - } - - /* - * Has the page moved? - * This is part of the lockless pagecache protocol. See - * include/linux/pagemap.h for details. - */ - if (unlikely(page != *pagep)) { - put_page(page); - page = NULL; - } - } - - if (page) { - if (page->index <= end_idx) - found = true; - put_page(page); - } - - rcu_read_unlock(); - return found; -} - static int lock_extent_direct(struct inode *inode, u64 lockstart, u64 lockend, struct extent_state **cached_state, int writing) {