From patchwork Wed Jan 27 21:17:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wilcox, Matthew R" X-Patchwork-Id: 8143031 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 98EC79F9E8 for ; Wed, 27 Jan 2016 21:20:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AB5A8201F4 for ; Wed, 27 Jan 2016 21:20:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0256201E4 for ; Wed, 27 Jan 2016 21:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965642AbcA0VSn (ORCPT ); Wed, 27 Jan 2016 16:18:43 -0500 Received: from mga04.intel.com ([192.55.52.120]:39448 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161759AbcA0VSF (ORCPT ); Wed, 27 Jan 2016 16:18:05 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP; 27 Jan 2016 13:18:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,356,1449561600"; d="scan'208";a="902446018" Received: from pdkerr-mobl.amr.corp.intel.com (HELO thog.int.wil.cx) ([10.252.192.47]) by fmsmga002.fm.intel.com with SMTP; 27 Jan 2016 13:18:00 -0800 Received: by thog.int.wil.cx (Postfix, from userid 1000) id C38225FDE1; Wed, 27 Jan 2016 16:17:57 -0500 (EST) From: Matthew Wilcox To: Andrew Morton , Hugh Dickins Cc: Matthew Wilcox , Konstantin Khlebnikov , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/5] radix-tree,shmem: Introduce radix_tree_iter_next() Date: Wed, 27 Jan 2016 16:17:52 -0500 Message-Id: <1453929472-25566-6-git-send-email-matthew.r.wilcox@intel.com> X-Mailer: git-send-email 2.7.0.rc3 In-Reply-To: <1453929472-25566-1-git-send-email-matthew.r.wilcox@intel.com> References: <1453929472-25566-1-git-send-email-matthew.r.wilcox@intel.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox shmem likes to occasionally drop the lock, schedule, then reacqire the lock and continue with the iteration from the last place it left off. This is currently done with a pretty ugly goto. Introduce radix_tree_iter_next() and use it throughout shmem.c. Signed-off-by: Matthew Wilcox --- include/linux/radix-tree.h | 15 +++++++++++++++ mm/shmem.c | 12 +++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h index db0ed595749b..dec2c6c77eea 100644 --- a/include/linux/radix-tree.h +++ b/include/linux/radix-tree.h @@ -403,6 +403,21 @@ void **radix_tree_iter_retry(struct radix_tree_iter *iter) } /** + * radix_tree_iter_next - resume iterating when the chunk may be invalid + * @iter: iterator state + * + * If the iterator needs to release then reacquire a lock, the chunk may + * have been invalidated by an insertion or deletion. Call this function + * to continue the iteration from the next index. + */ +static inline __must_check +void **radix_tree_iter_next(struct radix_tree_iter *iter) +{ + iter->next_index = iter->index + 1; + return NULL; +} + +/** * radix_tree_chunk_size - get current chunk size * * @iter: pointer to radix tree iterator diff --git a/mm/shmem.c b/mm/shmem.c index 6ec14b70d82d..438ea8004c26 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -376,7 +376,6 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, rcu_read_lock(); -restart: radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) { if (iter.index >= end) break; @@ -398,8 +397,7 @@ restart: if (need_resched()) { cond_resched_rcu(); - start = iter.index + 1; - goto restart; + slot = radix_tree_iter_next(&iter); } } @@ -1950,7 +1948,6 @@ static void shmem_tag_pins(struct address_space *mapping) start = 0; rcu_read_lock(); -restart: radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) { page = radix_tree_deref_slot(slot); if (!page || radix_tree_exception(page)) { @@ -1967,8 +1964,7 @@ restart: if (need_resched()) { cond_resched_rcu(); - start = iter.index + 1; - goto restart; + slot = radix_tree_iter_next(&iter); } } rcu_read_unlock(); @@ -2005,7 +2001,6 @@ static int shmem_wait_for_pins(struct address_space *mapping) start = 0; rcu_read_lock(); -restart: radix_tree_for_each_tagged(slot, &mapping->page_tree, &iter, start, SHMEM_TAG_PINNED) { @@ -2039,8 +2034,7 @@ restart: continue_resched: if (need_resched()) { cond_resched_rcu(); - start = iter.index + 1; - goto restart; + slot = radix_tree_iter_next(&iter); } } rcu_read_unlock();