aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2016-12-19 19:23:03 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-20 12:48:46 -0500
commit4dd72b4a47a5309333c8ddf9ec7df3380dede30d (patch)
tree9539134564a629ffb9c6c8c53d15911bae2aec4e
parent98e1d55d033eed2a474924c94fc2051ab20de402 (diff)
mm: fadvise: avoid expensive remote LRU cache draining after FADV_DONTNEED
When FADV_DONTNEED cannot drop all pages in the range, it observes that some pages might still be on per-cpu LRU caches after recent instantiation and so initiates remote calls to all CPUs to flush their local caches. However, in most cases, the fadvise happens from the same context that instantiated the pages, and any pre-LRU pages in the specified range are most likely sitting on the local CPU's LRU cache, and so in many cases this results in unnecessary remote calls, which, in a loaded system, can hold up the fadvise() call significantly. [ I didn't record it in the extreme case we observed at Facebook, unfortunately. We had a slow-to-respond system and noticed it lru_add_drain_all() leading the profile during fadvise calls. This patch came out of thinking about the code and how we commonly call FADV_DONTNEED. FWIW, I wrote a silly directory tree walker/searcher that recurses through /usr to read and FADV_DONTNEED each file it finds. On a 2 socket 40 ht machine, over 1% is spent in lru_add_drain_all(). With the patch, that cost is gone; the local drain cost shows at 0.09%. ] Try to avoid the remote call by flushing the local LRU cache before even attempting to invalidate anything. It's a cheap operation, and the local LRU cache is the most likely to hold any pre-LRU pages in the specified fadvise range. Link: http://lkml.kernel.org/r/20161214210017.GA1465@cmpxchg.org Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Mel Gorman <mgorman@suse.de> Acked-by: Hillf Danton <hillf.zj@alibaba-inc.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/fadvise.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/mm/fadvise.c b/mm/fadvise.c
index 6c707bfe02fd..a43013112581 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -139,7 +139,20 @@ SYSCALL_DEFINE4(fadvise64_64, int, fd, loff_t, offset, loff_t, len, int, advice)
139 } 139 }
140 140
141 if (end_index >= start_index) { 141 if (end_index >= start_index) {
142 unsigned long count = invalidate_mapping_pages(mapping, 142 unsigned long count;
143
144 /*
145 * It's common to FADV_DONTNEED right after
146 * the read or write that instantiates the
147 * pages, in which case there will be some
148 * sitting on the local LRU cache. Try to
149 * avoid the expensive remote drain and the
150 * second cache tree walk below by flushing
151 * them out right away.
152 */
153 lru_add_drain();
154
155 count = invalidate_mapping_pages(mapping,
143 start_index, end_index); 156 start_index, end_index);
144 157
145 /* 158 /*