aboutsummaryrefslogtreecommitdiffstats
path: root/mm/truncate.c
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2014-04-03 17:47:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-03 19:21:01 -0400
commit91b0abe36a7b2b3b02d7500925a5f8455334f0e5 (patch)
treee3d2cb9400fbfb24500a082721c1123b7a3942c0 /mm/truncate.c
parent0cd6144aadd2afd19d1aca880153530c52957604 (diff)
mm + fs: store shadow entries in page cache
Reclaim will be leaving shadow entries in the page cache radix tree upon evicting the real page. As those pages are found from the LRU, an iput() can lead to the inode being freed concurrently. At this point, reclaim must no longer install shadow pages because the inode freeing code needs to ensure the page tree is really empty. Add an address_space flag, AS_EXITING, that the inode freeing code sets under the tree lock before doing the final truncate. Reclaim will check for this flag before installing shadow pages. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Rik van Riel <riel@redhat.com> Reviewed-by: Minchan Kim <minchan@kernel.org> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Bob Liu <bob.liu@oracle.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Dave Chinner <david@fromorbit.com> Cc: Greg Thelen <gthelen@google.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jan Kara <jack@suse.cz> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Luigi Semenzato <semenzato@google.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Metin Doslu <metin@citusdata.com> Cc: Michel Lespinasse <walken@google.com> Cc: Ozgun Erdogan <ozgun@citusdata.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Roman Gushchin <klamm@yandex-team.ru> Cc: Ryan Mallon <rmallon@gmail.com> Cc: Tejun Heo <tj@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/truncate.c')
-rw-r--r--mm/truncate.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/mm/truncate.c b/mm/truncate.c
index 2e84fe59190b..0db9258319f0 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -35,7 +35,8 @@ static void clear_exceptional_entry(struct address_space *mapping,
35 * without the tree itself locked. These unlocked entries 35 * without the tree itself locked. These unlocked entries
36 * need verification under the tree lock. 36 * need verification under the tree lock.
37 */ 37 */
38 radix_tree_delete_item(&mapping->page_tree, index, entry); 38 if (radix_tree_delete_item(&mapping->page_tree, index, entry) == entry)
39 mapping->nrshadows--;
39 spin_unlock_irq(&mapping->tree_lock); 40 spin_unlock_irq(&mapping->tree_lock);
40} 41}
41 42
@@ -229,7 +230,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
229 int i; 230 int i;
230 231
231 cleancache_invalidate_inode(mapping); 232 cleancache_invalidate_inode(mapping);
232 if (mapping->nrpages == 0) 233 if (mapping->nrpages == 0 && mapping->nrshadows == 0)
233 return; 234 return;
234 235
235 /* Offsets within partial pages */ 236 /* Offsets within partial pages */
@@ -392,6 +393,53 @@ void truncate_inode_pages(struct address_space *mapping, loff_t lstart)
392EXPORT_SYMBOL(truncate_inode_pages); 393EXPORT_SYMBOL(truncate_inode_pages);
393 394
394/** 395/**
396 * truncate_inode_pages_final - truncate *all* pages before inode dies
397 * @mapping: mapping to truncate
398 *
399 * Called under (and serialized by) inode->i_mutex.
400 *
401 * Filesystems have to use this in the .evict_inode path to inform the
402 * VM that this is the final truncate and the inode is going away.
403 */
404void truncate_inode_pages_final(struct address_space *mapping)
405{
406 unsigned long nrshadows;
407 unsigned long nrpages;
408
409 /*
410 * Page reclaim can not participate in regular inode lifetime
411 * management (can't call iput()) and thus can race with the
412 * inode teardown. Tell it when the address space is exiting,
413 * so that it does not install eviction information after the
414 * final truncate has begun.
415 */
416 mapping_set_exiting(mapping);
417
418 /*
419 * When reclaim installs eviction entries, it increases
420 * nrshadows first, then decreases nrpages. Make sure we see
421 * this in the right order or we might miss an entry.
422 */
423 nrpages = mapping->nrpages;
424 smp_rmb();
425 nrshadows = mapping->nrshadows;
426
427 if (nrpages || nrshadows) {
428 /*
429 * As truncation uses a lockless tree lookup, cycle
430 * the tree lock to make sure any ongoing tree
431 * modification that does not see AS_EXITING is
432 * completed before starting the final truncate.
433 */
434 spin_lock_irq(&mapping->tree_lock);
435 spin_unlock_irq(&mapping->tree_lock);
436
437 truncate_inode_pages(mapping, 0);
438 }
439}
440EXPORT_SYMBOL(truncate_inode_pages_final);
441
442/**
395 * invalidate_mapping_pages - Invalidate all the unlocked pages of one inode 443 * invalidate_mapping_pages - Invalidate all the unlocked pages of one inode
396 * @mapping: the address_space which holds the pages to invalidate 444 * @mapping: the address_space which holds the pages to invalidate
397 * @start: the offset 'from' which to invalidate 445 * @start: the offset 'from' which to invalidate
@@ -484,7 +532,7 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)
484 goto failed; 532 goto failed;
485 533
486 BUG_ON(page_has_private(page)); 534 BUG_ON(page_has_private(page));
487 __delete_from_page_cache(page); 535 __delete_from_page_cache(page, NULL);
488 spin_unlock_irq(&mapping->tree_lock); 536 spin_unlock_irq(&mapping->tree_lock);
489 mem_cgroup_uncharge_cache_page(page); 537 mem_cgroup_uncharge_cache_page(page);
490 538