summaryrefslogtreecommitdiffstats
path: root/mm/truncate.c
diff options
context:
space:
mode:
authorRoss Zwisler <ross.zwisler@linux.intel.com>2016-01-22 18:10:40 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-22 20:02:18 -0500
commitf9fe48bece3af2d60e1bad65db4825f5a025dd36 (patch)
tree78f56ae2a1636fa9f8ec26466d4a94a16eadd5dc /mm/truncate.c
parent3f4a2670deea53e3765e24a7f46aafe6f077cb68 (diff)
dax: support dirty DAX entries in radix tree
Add support for tracking dirty DAX entries in the struct address_space radix tree. This tree is already used for dirty page writeback, and it already supports the use of exceptional (non struct page*) entries. In order to properly track dirty DAX pages we will insert new exceptional entries into the radix tree that represent dirty DAX PTE or PMD pages. These exceptional entries will also contain the writeback addresses for the PTE or PMD faults that we can use at fsync/msync time. There are currently two types of exceptional entries (shmem and shadow) that can be placed into the radix tree, and this adds a third. We rely on the fact that only one type of exceptional entry can be found in a given radix tree based on its usage. This happens for free with DAX vs shmem but we explicitly prevent shadow entries from being added to radix trees for DAX mappings. The only shadow entries that would be generated for DAX radix trees would be to track zero page mappings that were created for holes. These pages would receive minimal benefit from having shadow entries, and the choice to have only one type of exceptional entry in a given radix tree makes the logic simpler both in clear_exceptional_entry() and in the rest of DAX. Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: "J. Bruce Fields" <bfields@fieldses.org> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Andreas Dilger <adilger.kernel@dilger.ca> Cc: Dave Chinner <david@fromorbit.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jan Kara <jack@suse.com> Cc: Jeff Layton <jlayton@poochiereds.net> Cc: Matthew Wilcox <willy@linux.intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Matthew Wilcox <matthew.r.wilcox@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Hugh Dickins <hughd@google.com> 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.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/mm/truncate.c b/mm/truncate.c
index 76e35ad97102..e3ee0e27cd17 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -9,6 +9,7 @@
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/backing-dev.h> 11#include <linux/backing-dev.h>
12#include <linux/dax.h>
12#include <linux/gfp.h> 13#include <linux/gfp.h>
13#include <linux/mm.h> 14#include <linux/mm.h>
14#include <linux/swap.h> 15#include <linux/swap.h>
@@ -34,31 +35,39 @@ static void clear_exceptional_entry(struct address_space *mapping,
34 return; 35 return;
35 36
36 spin_lock_irq(&mapping->tree_lock); 37 spin_lock_irq(&mapping->tree_lock);
37 /* 38
38 * Regular page slots are stabilized by the page lock even 39 if (dax_mapping(mapping)) {
39 * without the tree itself locked. These unlocked entries 40 if (radix_tree_delete_item(&mapping->page_tree, index, entry))
40 * need verification under the tree lock. 41 mapping->nrexceptional--;
41 */ 42 } else {
42 if (!__radix_tree_lookup(&mapping->page_tree, index, &node, &slot)) 43 /*
43 goto unlock; 44 * Regular page slots are stabilized by the page lock even
44 if (*slot != entry) 45 * without the tree itself locked. These unlocked entries
45 goto unlock; 46 * need verification under the tree lock.
46 radix_tree_replace_slot(slot, NULL); 47 */
47 mapping->nrshadows--; 48 if (!__radix_tree_lookup(&mapping->page_tree, index, &node,
48 if (!node) 49 &slot))
49 goto unlock; 50 goto unlock;
50 workingset_node_shadows_dec(node); 51 if (*slot != entry)
51 /* 52 goto unlock;
52 * Don't track node without shadow entries. 53 radix_tree_replace_slot(slot, NULL);
53 * 54 mapping->nrexceptional--;
54 * Avoid acquiring the list_lru lock if already untracked. 55 if (!node)
55 * The list_empty() test is safe as node->private_list is 56 goto unlock;
56 * protected by mapping->tree_lock. 57 workingset_node_shadows_dec(node);
57 */ 58 /*
58 if (!workingset_node_shadows(node) && 59 * Don't track node without shadow entries.
59 !list_empty(&node->private_list)) 60 *
60 list_lru_del(&workingset_shadow_nodes, &node->private_list); 61 * Avoid acquiring the list_lru lock if already untracked.
61 __radix_tree_delete_node(&mapping->page_tree, node); 62 * The list_empty() test is safe as node->private_list is
63 * protected by mapping->tree_lock.
64 */
65 if (!workingset_node_shadows(node) &&
66 !list_empty(&node->private_list))
67 list_lru_del(&workingset_shadow_nodes,
68 &node->private_list);
69 __radix_tree_delete_node(&mapping->page_tree, node);
70 }
62unlock: 71unlock:
63 spin_unlock_irq(&mapping->tree_lock); 72 spin_unlock_irq(&mapping->tree_lock);
64} 73}
@@ -228,7 +237,7 @@ void truncate_inode_pages_range(struct address_space *mapping,
228 int i; 237 int i;
229 238
230 cleancache_invalidate_inode(mapping); 239 cleancache_invalidate_inode(mapping);
231 if (mapping->nrpages == 0 && mapping->nrshadows == 0) 240 if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
232 return; 241 return;
233 242
234 /* Offsets within partial pages */ 243 /* Offsets within partial pages */
@@ -402,7 +411,7 @@ EXPORT_SYMBOL(truncate_inode_pages);
402 */ 411 */
403void truncate_inode_pages_final(struct address_space *mapping) 412void truncate_inode_pages_final(struct address_space *mapping)
404{ 413{
405 unsigned long nrshadows; 414 unsigned long nrexceptional;
406 unsigned long nrpages; 415 unsigned long nrpages;
407 416
408 /* 417 /*
@@ -416,14 +425,14 @@ void truncate_inode_pages_final(struct address_space *mapping)
416 425
417 /* 426 /*
418 * When reclaim installs eviction entries, it increases 427 * When reclaim installs eviction entries, it increases
419 * nrshadows first, then decreases nrpages. Make sure we see 428 * nrexceptional first, then decreases nrpages. Make sure we see
420 * this in the right order or we might miss an entry. 429 * this in the right order or we might miss an entry.
421 */ 430 */
422 nrpages = mapping->nrpages; 431 nrpages = mapping->nrpages;
423 smp_rmb(); 432 smp_rmb();
424 nrshadows = mapping->nrshadows; 433 nrexceptional = mapping->nrexceptional;
425 434
426 if (nrpages || nrshadows) { 435 if (nrpages || nrexceptional) {
427 /* 436 /*
428 * As truncation uses a lockless tree lookup, cycle 437 * As truncation uses a lockless tree lookup, cycle
429 * the tree lock to make sure any ongoing tree 438 * the tree lock to make sure any ongoing tree