From patchwork Thu Jun 1 09:32:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 9758937 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 2E1C36038E for ; Thu, 1 Jun 2017 09:33:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 124EC284C3 for ; Thu, 1 Jun 2017 09:33:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 066D7284EA; Thu, 1 Jun 2017 09:33:55 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 82AD4284C3 for ; Thu, 1 Jun 2017 09:33:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751797AbdFAJdu (ORCPT ); Thu, 1 Jun 2017 05:33:50 -0400 Received: from mx2.suse.de ([195.135.220.15]:50900 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751672AbdFAJdW (ORCPT ); Thu, 1 Jun 2017 05:33:22 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 76AB9ADF5; Thu, 1 Jun 2017 09:33:15 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 63E6D1E35B9; Thu, 1 Jun 2017 11:33:12 +0200 (CEST) From: Jan Kara To: Cc: Hugh Dickins , David Howells , linux-afs@lists.infradead.org, Ryusuke Konishi , linux-nilfs@vger.kernel.org, Bob Peterson , cluster-devel@redhat.com, Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net, tytso@mit.edu, linux-ext4@vger.kernel.org, Ilya Dryomov , "Yan, Zheng" , ceph-devel@vger.kernel.org, linux-btrfs@vger.kernel.org, David Sterba , "Darrick J . Wong" , linux-xfs@vger.kernel.org, Nadia Yvette Chambers , Jan Kara Subject: [PATCH 32/35] mm: Convert truncate code to pagevec_lookup_entries_range() Date: Thu, 1 Jun 2017 11:32:42 +0200 Message-Id: <20170601093245.29238-33-jack@suse.cz> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170601093245.29238-1-jack@suse.cz> References: <20170601093245.29238-1-jack@suse.cz> 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 All radix tree scanning code in truncate paths is interested only in pages from given range. Convert them to pagevec_lookup_entries_range(). Signed-off-by: Jan Kara --- mm/truncate.c | 52 +++++++++------------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 9efc82f18b74..31d5c5f3da30 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -289,16 +289,11 @@ void truncate_inode_pages_range(struct address_space *mapping, pagevec_init(&pvec, 0); index = start; - while (index < end && pagevec_lookup_entries(&pvec, mapping, &index, - min(end - index, (pgoff_t)PAGEVEC_SIZE), - indices)) { + while (index < end && pagevec_lookup_entries_range(&pvec, mapping, + &index, end - 1, PAGEVEC_SIZE, indices)) { for (i = 0; i < pagevec_count(&pvec); i++) { struct page *page = pvec.pages[i]; - /* We rely upon deletion not changing page->index */ - if (indices[i] >= end) - break; - if (radix_tree_exceptional_entry(page)) { truncate_exceptional_entry(mapping, indices[i], page); @@ -352,20 +347,14 @@ void truncate_inode_pages_range(struct address_space *mapping, put_page(page); } } - /* - * If the truncation happened within a single page no pages - * will be released, just zeroed, so we can bail out now. - */ - if (start >= end) - goto out; index = start; - for ( ; ; ) { + while (index < end) { pgoff_t lookup_start = index; cond_resched(); - if (!pagevec_lookup_entries(&pvec, mapping, &index, - min(end - index, (pgoff_t)PAGEVEC_SIZE), indices)) { + if (!pagevec_lookup_entries_range(&pvec, mapping, &index, + end - 1, PAGEVEC_SIZE, indices)) { /* If all gone from start onwards, we're done */ if (lookup_start == start) break; @@ -373,22 +362,9 @@ void truncate_inode_pages_range(struct address_space *mapping, index = start; continue; } - if (lookup_start == start && indices[0] >= end) { - /* All gone out of hole to be punched, we're done */ - pagevec_remove_exceptionals(&pvec); - pagevec_release(&pvec); - break; - } for (i = 0; i < pagevec_count(&pvec); i++) { struct page *page = pvec.pages[i]; - /* We rely upon deletion not changing page->index */ - if (indices[i] >= end) { - /* Restart punch to make sure all gone */ - index = start; - break; - } - if (radix_tree_exceptional_entry(page)) { truncate_exceptional_entry(mapping, indices[i], page); @@ -499,16 +475,11 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping, int i; pagevec_init(&pvec, 0); - while (index <= end && pagevec_lookup_entries(&pvec, mapping, &index, - min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1, - indices)) { + while (index <= end && pagevec_lookup_entries_range(&pvec, mapping, + &index, end, PAGEVEC_SIZE, indices)) { for (i = 0; i < pagevec_count(&pvec); i++) { struct page *page = pvec.pages[i]; - /* We rely upon deletion not changing page->index */ - if (indices[i] > end) - break; - if (radix_tree_exceptional_entry(page)) { invalidate_exceptional_entry(mapping, indices[i], page); @@ -629,16 +600,11 @@ int invalidate_inode_pages2_range(struct address_space *mapping, pagevec_init(&pvec, 0); index = start; - while (index <= end && pagevec_lookup_entries(&pvec, mapping, &index, - min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1, - indices)) { + while (index <= end && pagevec_lookup_entries_range(&pvec, mapping, + &index, end, PAGEVEC_SIZE, indices)) { for (i = 0; i < pagevec_count(&pvec); i++) { struct page *page = pvec.pages[i]; - /* We rely upon deletion not changing page->index */ - if (indices[i] > end) - break; - if (radix_tree_exceptional_entry(page)) { if (!invalidate_exceptional_entry2(mapping, indices[i], page))