linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Khlebnikov <koct9i@gmail.com>
To: Matthew Wilcox <matthew.r.wilcox@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Hugh Dickins <hughd@google.com>,
	Matthew Wilcox <willy@linux.intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [PATCH 5/5] radix-tree,shmem: Introduce radix_tree_iter_next()
Date: Thu, 4 Feb 2016 11:50:35 +0300	[thread overview]
Message-ID: <CALYGNiOr42QxHh4GrmB3REzXYDXaa7U=903VKHcDDWtd2Wureg@mail.gmail.com> (raw)
In-Reply-To: <1453929472-25566-6-git-send-email-matthew.r.wilcox@intel.com>

On Thu, Jan 28, 2016 at 12:17 AM, Matthew Wilcox
<matthew.r.wilcox@intel.com> wrote:
> From: Matthew Wilcox <willy@linux.intel.com>
>
> 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 <willy@linux.intel.com>
> ---
>  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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2016-02-04  8:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-27 21:17 [PATCH 0/5] Fix races & improve the radix tree iterator patterns Matthew Wilcox
2016-01-27 21:17 ` [PATCH 1/5] radix-tree: Fix race in gang lookup Matthew Wilcox
2016-02-03 21:37   ` Konstantin Khlebnikov
2016-02-04  8:44     ` Konstantin Khlebnikov
2016-03-04 13:21   ` zhong jiang
2016-01-27 21:17 ` [PATCH 2/5] hwspinlock: Fix race between radix tree insertion and lookup Matthew Wilcox
2016-01-27 21:17 ` [PATCH 3/5] btrfs: Use radix_tree_iter_retry() Matthew Wilcox
2016-02-01 14:34   ` David Sterba
2016-01-27 21:17 ` [PATCH 4/5] mm: " Matthew Wilcox
2016-01-29 14:45   ` Vlastimil Babka
2016-01-29 14:50     ` Matthew Wilcox
2016-02-19 18:02   ` Sasha Levin
2016-01-27 21:17 ` [PATCH 5/5] radix-tree,shmem: Introduce radix_tree_iter_next() Matthew Wilcox
2016-02-04  8:50   ` Konstantin Khlebnikov [this message]
2016-01-28  7:17 ` [PATCH 0/5] Fix races & improve the radix tree iterator patterns Konstantin Khlebnikov
2016-02-03  6:27   ` Konstantin Khlebnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALYGNiOr42QxHh4GrmB3REzXYDXaa7U=903VKHcDDWtd2Wureg@mail.gmail.com' \
    --to=koct9i@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew.r.wilcox@intel.com \
    --cc=willy@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox