rmap 16: pretend prio_tree
Subsystems (9)
PATCH 31/57 rmap 16: pretend prio_tree
From: Hugh Dickins <[email protected]>
Pave the way for prio_tree by switching over to its interfaces, but actually still implement them with the same old lists as before.
Most of the vma_prio_tree interfaces are straightforward. The interesting one is vma_prio_tree_next, used to search the tree for all vmas which overlap the given range: unlike the list_for_each_entry it replaces, it does not find every vma, just those that match.
But this does leave handling of nonlinear vmas in a very unsatisfactory state:
for now we have to search again over the maximum range to find all the nonlinear vmas which might contain a page, which of course takes away the point of the tree. Fixed in later patch of this batch.
There is no need to initialize vma linkage all over, just do it before inserting the vma in list or tree. /proc/pid/statm had an odd test for its shared count: simplified to an equivalent test on vm_file.
---
25-akpm/fs/exec.c | 1 25-akpm/fs/hugetlbfs/inode.c | 30 ++++----------- 25-akpm/fs/inode.c | 4 +- 25-akpm/fs/proc/task_mmu.c | 2 - 25-akpm/include/linux/fs.h | 13 +++--- 25-akpm/include/linux/mm.h | 31 ++++++++++++++- 25-akpm/include/linux/prio_tree.h | 27 +++++++++++++ 25-akpm/kernel/fork.c | 4 +- 25-akpm/mm/memory.c | 41 ++++++++++++++------ 25-akpm/mm/mmap.c | 62 ++++++++++++++++++++++++------- 25-akpm/mm/rmap.c | 75 +++++++++++++++++++------------------- 11 files changed, 191 insertions(+), 99 deletions(-)
fs/exec.c renamed from fs/exec.c~rmap-16-pretend-prio_tree +0 -1
@@ -429,7 +429,6 @@ int setup_arg_pages(struct linux_binprm mpnt->vm_pgoff =0 ; mpnt->vm_file =NULL ;mpol_set_vma_default (mpnt); -INIT_LIST_HEAD (&mpnt->shared); mpnt->vm_private_data = (void *)0 ;insert_vm_struct (mm, mpnt); mm->total_vm = (mpnt->vm_end - mpnt->vm_start) >>PAGE_SHIFT ;
fs/hugetlbfs/inode.c renamed from fs/hugetlbfs/inode.c~rmap-16-pretend-prio_tree +9 -21
@@ -267,39 +267,27 @@ static void hugetlbfs_drop_inode(struct* vma->vm_pgoff is in PAGE_SIZE units. */ static void -hugetlb_vmtruncate_list (struct list_head *list,unsigned long h_pgoff) +hugetlb_vmtruncate_list (struct prio_tree_root *root,unsigned long h_pgoff) { -struct vm_area_struct *vma; +struct vm_area_struct *vma =NULL ; +struct prio_tree_iter iter; -list_for_each_entry (vma, list, shared) { +while ((vma =vma_prio_tree_next (vma, root, &iter, + h_pgoff,ULONG_MAX )) !=NULL ) {unsigned long h_vm_pgoff;unsigned long v_length; -unsigned long h_length;unsigned long v_offset; h_vm_pgoff = vma->vm_pgoff << (HPAGE_SHIFT -PAGE_SHIFT ); v_length = vma->vm_end - vma->vm_start; - h_length = v_length >>HPAGE_SHIFT ; v_offset = (h_pgoff - h_vm_pgoff) <<HPAGE_SHIFT ;/* * Is this VMA fully outside the truncation point? */ -if (h_vm_pgoff >= h_pgoff) { -zap_hugepage_range (vma, vma->vm_start, v_length); -continue ; - } - -/* -* Is this VMA fully inside the truncaton point? -*/ -if (h_vm_pgoff + (v_length >>HPAGE_SHIFT ) <= h_pgoff) -continue ; +if (h_vm_pgoff >= h_pgoff) + v_offset =0 ; -/* -* The VMA straddles the truncation point. v_offset is the -* offset (in bytes) into the VMA where the point lies. -*/ zap_hugepage_range (vma, vma->vm_start + v_offset, v_length - v_offset);
@@ -322,9 +310,9 @@ static int hugetlb_vmtruncate(struct ino inode->i_size = offset;spin_lock (&mapping->i_mmap_lock); -if (!list_empty (&mapping->i_mmap)) +if (!prio_tree_empty (&mapping->i_mmap))hugetlb_vmtruncate_list (&mapping->i_mmap, pgoff); -if (!list_empty (&mapping->i_mmap_shared)) +if (!prio_tree_empty (&mapping->i_mmap_shared))hugetlb_vmtruncate_list (&mapping->i_mmap_shared, pgoff);spin_unlock (&mapping->i_mmap_lock);truncate_hugepages (mapping, offset);
fs/inode.c renamed from fs/inode.c~rmap-16-pretend-prio_tree +2 -2
@@ -200,8 +200,8 @@ void inode_init_once(struct inode *inodeatomic_set (&inode->i_data.truncate_count,0 );INIT_LIST_HEAD (&inode->i_data.private_list);spin_lock_init (&inode->i_data.private_lock); -INIT_LIST_HEAD (&inode->i_data.i_mmap); -INIT_LIST_HEAD (&inode->i_data.i_mmap_shared); +INIT_PRIO_TREE_ROOT (&inode->i_data.i_mmap); +INIT_PRIO_TREE_ROOT (&inode->i_data.i_mmap_shared);spin_lock_init (&inode->i_lock);i_size_ordered_init (inode); }
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~rmap-16-pretend-prio_tree +1 -1
@@ -65,7 +65,7 @@ int task_statm(struct mm_struct *mm, int *shared += pages;continue ; } -if (vma->vm_flags &VM_SHARED || !list_empty (&vma->shared)) +if (vma->vm_file) *shared += pages;if (vma->vm_flags &VM_EXECUTABLE ) *text += pages;
include/linux/fs.h renamed from include/linux/fs.h~rmap-16-pretend-prio_tree +7 -6
@@ -18,6 +18,7 @@#include <linux/stat.h> #include <linux/cache.h> #include <linux/radix-tree.h> +#include <linux/prio_tree.h> #include <linux/kobject.h> #include <asm/atomic.h> #include <linux/audit.h>
@@ -329,9 +330,9 @@ struct address_space {unsigned long nrpages;/* number of total pages */ pgoff_t writeback_index;/* writeback starts here */ struct address_space_operations *a_ops;/* methods */ -struct list_head i_mmap;/* list of private mappings */ -struct list_head i_mmap_shared;/* list of shared mappings */ -spinlock_t i_mmap_lock;/* protect both above lists */ +struct prio_tree_root i_mmap;/* tree of private mappings */ +struct prio_tree_root i_mmap_shared;/* tree of shared mappings */ +spinlock_t i_mmap_lock;/* protect trees & list above */ atomic_t truncate_count;/* Cover race condition with truncate */ unsigned long flags;/* error bits/gfp mask */ struct backing_dev_info *backing_dev_info;/* device readahead, etc */
@@ -380,8 +381,8 @@ int mapping_tagged(struct address_space*/ static inline int mapping_mapped (struct address_space *mapping) { -return !list_empty (&mapping->i_mmap) || - !list_empty (&mapping->i_mmap_shared); +return !prio_tree_empty (&mapping->i_mmap) || + !prio_tree_empty (&mapping->i_mmap_shared); }/*
@@ -392,7 +393,7 @@ static inline int mapping_mapped(struct*/ static inline int mapping_writably_mapped (struct address_space *mapping) { -return !list_empty (&mapping->i_mmap_shared); +return !prio_tree_empty (&mapping->i_mmap_shared); }/*
include/linux/mm.h renamed from include/linux/mm.h~rmap-16-pretend-prio_tree +29 -2
@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mmzone.h> #include <linux/rbtree.h> +#include <linux/prio_tree.h> #include <linux/fs.h> struct mempolicy ;
@@ -70,8 +71,7 @@ struct vm_area_struct {/* * For areas with an address space and backing store, -* one of the address_space->i_mmap{,shared} lists, -* for shm areas, the list of attaches, otherwise unused. +* one of the address_space->i_mmap{,shared} trees. */ struct list_head shared;
@@ -587,6 +587,33 @@ extern void show_mem(void);extern void si_meminfo (struct sysinfo * val);extern void si_meminfo_node (struct sysinfo *val,int nid); +static inline void vma_prio_tree_init (struct vm_area_struct *vma) +{ +INIT_LIST_HEAD (&vma->shared); +} + +static inline void vma_prio_tree_add (struct vm_area_struct *vma, +struct vm_area_struct *old) +{ +list_add (&vma->shared, &old->shared); +} + +static inline void vma_prio_tree_insert (struct vm_area_struct *vma, +struct prio_tree_root *root) +{ +list_add_tail (&vma->shared, &root->list); +} + +static inline void vma_prio_tree_remove (struct vm_area_struct *vma, +struct prio_tree_root *root) +{ +list_del_init (&vma->shared); +} + +struct vm_area_struct *vma_prio_tree_next ( +struct vm_area_struct *,struct prio_tree_root *, +struct prio_tree_iter *,pgoff_t begin,pgoff_t end); +/* mmap.c */ extern void vma_adjust (struct vm_area_struct *vma,unsigned long start,unsigned long end,pgoff_t pgoff,struct vm_area_struct *next);
include/linux/prio_tree.h new file +27 -0
@@ -0,0 +1,27 @@ +#ifndef _LINUX_PRIO_TREE_H +#define _LINUX_PRIO_TREE_H +/* +* Dummy version of include/linux/prio_tree.h, just for this patch: +* no radix priority search tree whatsoever, just implement interfaces +* using the old lists. +*/ + +struct prio_tree_root { +struct list_head list; +}; + +struct prio_tree_iter { +int not_used_yet; +}; + +#define INIT_PRIO_TREE_ROOT (ptr) \ +do { \ + INIT_LIST_HEAD(&(ptr)->list); \ +} while (0) \ + +static inline int prio_tree_empty (const struct prio_tree_root *root) +{ +return list_empty (&root->list); +} + +#endif /* _LINUX_PRIO_TREE_H */
kernel/fork.c renamed from kernel/fork.c~rmap-16-pretend-prio_tree +2 -2
@@ -323,7 +323,7 @@ static inline int dup_mmap(struct mm_str tmp->vm_mm = mm; tmp->vm_next =NULL ; file = tmp->vm_file; -INIT_LIST_HEAD (&tmp->shared); +vma_prio_tree_init (tmp);if (file) {struct inode *inode = file->f_dentry->d_inode;get_file (file);
@@ -332,7 +332,7 @@ static inline int dup_mmap(struct mm_str/* insert tmp into the share list, just after mpnt */ spin_lock (&file->f_mapping->i_mmap_lock); -list_add (&tmp->shared, &mpnt->shared); +vma_prio_tree_add (tmp, mpnt);spin_unlock (&file->f_mapping->i_mmap_lock); }
mm/memory.c renamed from mm/memory.c~rmap-16-pretend-prio_tree +28 -13
73 lines not on this page · raw message
mm/mmap.c renamed from mm/mmap.c~rmap-16-pretend-prio_tree +48 -14
144 lines not on this page · raw message
mm/rmap.c renamed from mm/rmap.c~rmap-16-pretend-prio_tree +38 -37
162 lines not on this page · raw message
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>