mm: madvise: fix MADV_WILLNEED on shmem swapouts
[platform/adaptation/renesas_rcar/renesas_kernel.git] / mm / interval_tree.c
index 4ab7b9e..4a5822a 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/mm.h>
 #include <linux/fs.h>
+#include <linux/rmap.h>
 #include <linux/interval_tree_generic.h>
 
 static inline unsigned long vma_start_pgoff(struct vm_area_struct *v)
@@ -57,3 +58,55 @@ void vma_interval_tree_insert_after(struct vm_area_struct *node,
        rb_insert_augmented(&node->shared.linear.rb, root,
                            &vma_interval_tree_augment);
 }
+
+static inline unsigned long avc_start_pgoff(struct anon_vma_chain *avc)
+{
+       return vma_start_pgoff(avc->vma);
+}
+
+static inline unsigned long avc_last_pgoff(struct anon_vma_chain *avc)
+{
+       return vma_last_pgoff(avc->vma);
+}
+
+INTERVAL_TREE_DEFINE(struct anon_vma_chain, rb, unsigned long, rb_subtree_last,
+                    avc_start_pgoff, avc_last_pgoff,
+                    static inline, __anon_vma_interval_tree)
+
+void anon_vma_interval_tree_insert(struct anon_vma_chain *node,
+                                  struct rb_root *root)
+{
+#ifdef CONFIG_DEBUG_VM_RB
+       node->cached_vma_start = avc_start_pgoff(node);
+       node->cached_vma_last = avc_last_pgoff(node);
+#endif
+       __anon_vma_interval_tree_insert(node, root);
+}
+
+void anon_vma_interval_tree_remove(struct anon_vma_chain *node,
+                                  struct rb_root *root)
+{
+       __anon_vma_interval_tree_remove(node, root);
+}
+
+struct anon_vma_chain *
+anon_vma_interval_tree_iter_first(struct rb_root *root,
+                                 unsigned long first, unsigned long last)
+{
+       return __anon_vma_interval_tree_iter_first(root, first, last);
+}
+
+struct anon_vma_chain *
+anon_vma_interval_tree_iter_next(struct anon_vma_chain *node,
+                                unsigned long first, unsigned long last)
+{
+       return __anon_vma_interval_tree_iter_next(node, first, last);
+}
+
+#ifdef CONFIG_DEBUG_VM_RB
+void anon_vma_interval_tree_verify(struct anon_vma_chain *node)
+{
+       WARN_ON_ONCE(node->cached_vma_start != avc_start_pgoff(node));
+       WARN_ON_ONCE(node->cached_vma_last != avc_last_pgoff(node));
+}
+#endif