Commit 2cf938aa authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

mm: use radix_tree_iter_retry()

Instead of a 'goto restart', we can now use radix_tree_iter_retry() to
restart from our current position.  This will make a difference when
there are more ways to happen across an indirect pointer.  And it
eliminates some confusing gotos.

[vbabka@suse.cz: remove now-obsolete-and-misleading comment]
Signed-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c28f2420
...@@ -1255,7 +1255,6 @@ unsigned find_get_entries(struct address_space *mapping, ...@@ -1255,7 +1255,6 @@ unsigned find_get_entries(struct address_space *mapping,
return 0; return 0;
rcu_read_lock(); rcu_read_lock();
restart:
radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) { radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) {
struct page *page; struct page *page;
repeat: repeat:
...@@ -1263,8 +1262,10 @@ unsigned find_get_entries(struct address_space *mapping, ...@@ -1263,8 +1262,10 @@ unsigned find_get_entries(struct address_space *mapping,
if (unlikely(!page)) if (unlikely(!page))
continue; continue;
if (radix_tree_exception(page)) { if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) if (radix_tree_deref_retry(page)) {
goto restart; slot = radix_tree_iter_retry(&iter);
continue;
}
/* /*
* A shadow entry of a recently evicted page, a swap * A shadow entry of a recently evicted page, a swap
* entry from shmem/tmpfs or a DAX entry. Return it * entry from shmem/tmpfs or a DAX entry. Return it
...@@ -1317,7 +1318,6 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, ...@@ -1317,7 +1318,6 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
return 0; return 0;
rcu_read_lock(); rcu_read_lock();
restart:
radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) { radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) {
struct page *page; struct page *page;
repeat: repeat:
...@@ -1327,13 +1327,8 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, ...@@ -1327,13 +1327,8 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
if (radix_tree_exception(page)) { if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) { if (radix_tree_deref_retry(page)) {
/* slot = radix_tree_iter_retry(&iter);
* Transient condition which can only trigger continue;
* when entry at index 0 moves out of or back
* to root: none yet gotten, safe to restart.
*/
WARN_ON(iter.index);
goto restart;
} }
/* /*
* A shadow entry of a recently evicted page, * A shadow entry of a recently evicted page,
...@@ -1384,7 +1379,6 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, ...@@ -1384,7 +1379,6 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index,
return 0; return 0;
rcu_read_lock(); rcu_read_lock();
restart:
radix_tree_for_each_contig(slot, &mapping->page_tree, &iter, index) { radix_tree_for_each_contig(slot, &mapping->page_tree, &iter, index) {
struct page *page; struct page *page;
repeat: repeat:
...@@ -1395,12 +1389,8 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, ...@@ -1395,12 +1389,8 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index,
if (radix_tree_exception(page)) { if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) { if (radix_tree_deref_retry(page)) {
/* slot = radix_tree_iter_retry(&iter);
* Transient condition which can only trigger continue;
* when entry at index 0 moves out of or back
* to root: none yet gotten, safe to restart.
*/
goto restart;
} }
/* /*
* A shadow entry of a recently evicted page, * A shadow entry of a recently evicted page,
...@@ -1460,7 +1450,6 @@ unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index, ...@@ -1460,7 +1450,6 @@ unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
return 0; return 0;
rcu_read_lock(); rcu_read_lock();
restart:
radix_tree_for_each_tagged(slot, &mapping->page_tree, radix_tree_for_each_tagged(slot, &mapping->page_tree,
&iter, *index, tag) { &iter, *index, tag) {
struct page *page; struct page *page;
...@@ -1471,12 +1460,8 @@ unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index, ...@@ -1471,12 +1460,8 @@ unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
if (radix_tree_exception(page)) { if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) { if (radix_tree_deref_retry(page)) {
/* slot = radix_tree_iter_retry(&iter);
* Transient condition which can only trigger continue;
* when entry at index 0 moves out of or back
* to root: none yet gotten, safe to restart.
*/
goto restart;
} }
/* /*
* A shadow entry of a recently evicted page. * A shadow entry of a recently evicted page.
...@@ -1539,7 +1524,6 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start, ...@@ -1539,7 +1524,6 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
return 0; return 0;
rcu_read_lock(); rcu_read_lock();
restart:
radix_tree_for_each_tagged(slot, &mapping->page_tree, radix_tree_for_each_tagged(slot, &mapping->page_tree,
&iter, start, tag) { &iter, start, tag) {
struct page *page; struct page *page;
...@@ -1549,12 +1533,8 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start, ...@@ -1549,12 +1533,8 @@ unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
continue; continue;
if (radix_tree_exception(page)) { if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) { if (radix_tree_deref_retry(page)) {
/* slot = radix_tree_iter_retry(&iter);
* Transient condition which can only trigger continue;
* when entry at index 0 moves out of or back
* to root: none yet gotten, safe to restart.
*/
goto restart;
} }
/* /*
...@@ -2171,9 +2151,10 @@ void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -2171,9 +2151,10 @@ void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf)
if (unlikely(!page)) if (unlikely(!page))
goto next; goto next;
if (radix_tree_exception(page)) { if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) if (radix_tree_deref_retry(page)) {
break; slot = radix_tree_iter_retry(&iter);
else continue;
}
goto next; goto next;
} }
......
...@@ -383,13 +383,10 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, ...@@ -383,13 +383,10 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping,
page = radix_tree_deref_slot(slot); page = radix_tree_deref_slot(slot);
/* if (radix_tree_deref_retry(page)) {
* This should only be possible to happen at index 0, so we slot = radix_tree_iter_retry(&iter);
* don't need to reset the counter, nor do we risk infinite continue;
* restarts. }
*/
if (radix_tree_deref_retry(page))
goto restart;
if (radix_tree_exceptional_entry(page)) if (radix_tree_exceptional_entry(page))
swapped++; swapped++;
...@@ -1951,8 +1948,10 @@ static void shmem_tag_pins(struct address_space *mapping) ...@@ -1951,8 +1948,10 @@ static void shmem_tag_pins(struct address_space *mapping)
radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) { radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) {
page = radix_tree_deref_slot(slot); page = radix_tree_deref_slot(slot);
if (!page || radix_tree_exception(page)) { if (!page || radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) if (radix_tree_deref_retry(page)) {
goto restart; slot = radix_tree_iter_retry(&iter);
continue;
}
} else if (page_count(page) - page_mapcount(page) > 1) { } else if (page_count(page) - page_mapcount(page) > 1) {
spin_lock_irq(&mapping->tree_lock); spin_lock_irq(&mapping->tree_lock);
radix_tree_tag_set(&mapping->page_tree, iter.index, radix_tree_tag_set(&mapping->page_tree, iter.index,
...@@ -2006,8 +2005,10 @@ static int shmem_wait_for_pins(struct address_space *mapping) ...@@ -2006,8 +2005,10 @@ static int shmem_wait_for_pins(struct address_space *mapping)
page = radix_tree_deref_slot(slot); page = radix_tree_deref_slot(slot);
if (radix_tree_exception(page)) { if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) if (radix_tree_deref_retry(page)) {
goto restart; slot = radix_tree_iter_retry(&iter);
continue;
}
page = NULL; page = NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment