* [PATCH] mm: don't return 0 too early from find_get_pages()
@ 2011-02-24 5:35 Hugh Dickins
2011-02-24 12:40 ` Peter Zijlstra
0 siblings, 1 reply; 2+ messages in thread
From: Hugh Dickins @ 2011-02-24 5:35 UTC (permalink / raw)
To: Nick Piggin
Cc: Andrew Morton, Peter Zijlstra, Wu Fengguang, Salman Qazi,
linux-kernel, linux-mm
Callers of find_get_pages(), or its wrapper pagevec_lookup() - notably
truncate_inode_pages_range() - stop looking further when it returns 0.
But if an interrupt comes just after its radix_tree_gang_lookup_slot(),
especially if we have preemptible RCU enabled, isn't it conceivable
that all 14 pages returned could be removed from the page cache by
shrink_page_list(), before find_get_pages() gets to process them? So
causing it to return 0 although there may be plenty more pages beyond.
Make find_get_pages() and find_get_pages_tag() check for this unlikely
case, and restart should it occur; but callers of find_get_pages_contig()
have no such expectation, it's okay for that to return 0 early.
I have not seen this in practice, just worried by the possibility.
Signed-off-by: Hugh Dickins <hughd@google.com>
---
mm/filemap.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
--- 2.6.38-rc6/mm/filemap.c 2011-01-18 22:04:56.000000000 -0800
+++ linux/mm/filemap.c 2011-02-23 16:06:19.000000000 -0800
@@ -800,6 +800,13 @@ repeat:
pages[ret] = page;
ret++;
}
+
+ /*
+ * If all entries were removed before we could secure them,
+ * try again, because callers stop trying once 0 is returned.
+ */
+ if (unlikely(!ret && nr_found))
+ goto restart;
rcu_read_unlock();
return ret;
}
@@ -909,6 +916,13 @@ repeat:
pages[ret] = page;
ret++;
}
+
+ /*
+ * If all entries were removed before we could secure them,
+ * try again, because callers stop trying once 0 is returned.
+ */
+ if (unlikely(!ret && nr_found))
+ goto restart;
rcu_read_unlock();
if (ret)
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: don't return 0 too early from find_get_pages()
2011-02-24 5:35 [PATCH] mm: don't return 0 too early from find_get_pages() Hugh Dickins
@ 2011-02-24 12:40 ` Peter Zijlstra
0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2011-02-24 12:40 UTC (permalink / raw)
To: Hugh Dickins
Cc: Nick Piggin, Andrew Morton, Wu Fengguang, Salman Qazi,
linux-kernel, linux-mm
On Wed, 2011-02-23 at 21:35 -0800, Hugh Dickins wrote:
> Callers of find_get_pages(), or its wrapper pagevec_lookup() - notably
> truncate_inode_pages_range() - stop looking further when it returns 0.
>
> But if an interrupt comes just after its radix_tree_gang_lookup_slot(),
> especially if we have preemptible RCU enabled, isn't it conceivable
> that all 14 pages returned could be removed from the page cache by
> shrink_page_list(), before find_get_pages() gets to process them? So
> causing it to return 0 although there may be plenty more pages beyond.
>
> Make find_get_pages() and find_get_pages_tag() check for this unlikely
> case, and restart should it occur; but callers of find_get_pages_contig()
> have no such expectation, it's okay for that to return 0 early.
>
> I have not seen this in practice, just worried by the possibility.
>
> Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-02-24 12:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-24 5:35 [PATCH] mm: don't return 0 too early from find_get_pages() Hugh Dickins
2011-02-24 12:40 ` Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).