From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755618AbcBDIui (ORCPT ); Thu, 4 Feb 2016 03:50:38 -0500 Received: from mail-lf0-f44.google.com ([209.85.215.44]:33463 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751127AbcBDIuh (ORCPT ); Thu, 4 Feb 2016 03:50:37 -0500 MIME-Version: 1.0 In-Reply-To: <1453929472-25566-6-git-send-email-matthew.r.wilcox@intel.com> References: <1453929472-25566-1-git-send-email-matthew.r.wilcox@intel.com> <1453929472-25566-6-git-send-email-matthew.r.wilcox@intel.com> Date: Thu, 4 Feb 2016 11:50:35 +0300 Message-ID: Subject: Re: [PATCH 5/5] radix-tree,shmem: Introduce radix_tree_iter_next() From: Konstantin Khlebnikov To: Matthew Wilcox Cc: Andrew Morton , Hugh Dickins , Matthew Wilcox , Linux Kernel Mailing List , linux-fsdevel , "linux-mm@kvack.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 28, 2016 at 12:17 AM, Matthew Wilcox wrote: > 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; > +} > + > +/** This works for normal iterator but not for tagged. It must also reset iter->tags to zero. > * 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(); > -- > 2.7.0.rc3 > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 In-Reply-To: <1453929472-25566-6-git-send-email-matthew.r.wilcox@intel.com> References: <1453929472-25566-1-git-send-email-matthew.r.wilcox@intel.com> <1453929472-25566-6-git-send-email-matthew.r.wilcox@intel.com> Date: Thu, 4 Feb 2016 11:50:35 +0300 Message-ID: Subject: Re: [PATCH 5/5] radix-tree,shmem: Introduce radix_tree_iter_next() From: Konstantin Khlebnikov To: Matthew Wilcox Cc: Andrew Morton , Hugh Dickins , Matthew Wilcox , Linux Kernel Mailing List , linux-fsdevel , "linux-mm@kvack.org" Content-Type: text/plain; charset=UTF-8 Sender: owner-linux-mm@kvack.org List-ID: On Thu, Jan 28, 2016 at 12:17 AM, Matthew Wilcox wrote: > 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; > +} > + > +/** This works for normal iterator but not for tagged. It must also reset iter->tags to zero. > * 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(); > -- > 2.7.0.rc3 > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org