Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: make the vma list be doubly linked

It's a really simple list, and several of the users want to go backwards
in it to find the previous vma. So rather than have to look up the
previous entry with 'find_vma_prev()' or something similar, just make it
doubly linked instead.

Tested-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+28 -9
+1 -1
include/linux/mm_types.h
··· 134 134 within vm_mm. */ 135 135 136 136 /* linked list of VM areas per task, sorted by address */ 137 - struct vm_area_struct *vm_next; 137 + struct vm_area_struct *vm_next, *vm_prev; 138 138 139 139 pgprot_t vm_page_prot; /* Access permissions of this VMA. */ 140 140 unsigned long vm_flags; /* Flags, see mm.h. */
+5 -2
kernel/fork.c
··· 300 300 #ifdef CONFIG_MMU 301 301 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) 302 302 { 303 - struct vm_area_struct *mpnt, *tmp, **pprev; 303 + struct vm_area_struct *mpnt, *tmp, *prev, **pprev; 304 304 struct rb_node **rb_link, *rb_parent; 305 305 int retval; 306 306 unsigned long charge; ··· 328 328 if (retval) 329 329 goto out; 330 330 331 + prev = NULL; 331 332 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { 332 333 struct file *file; 333 334 ··· 360 359 goto fail_nomem_anon_vma_fork; 361 360 tmp->vm_flags &= ~VM_LOCKED; 362 361 tmp->vm_mm = mm; 363 - tmp->vm_next = NULL; 362 + tmp->vm_next = tmp->vm_prev = NULL; 364 363 file = tmp->vm_file; 365 364 if (file) { 366 365 struct inode *inode = file->f_path.dentry->d_inode; ··· 393 392 */ 394 393 *pprev = tmp; 395 394 pprev = &tmp->vm_next; 395 + tmp->vm_prev = prev; 396 + prev = tmp; 396 397 397 398 __vma_link_rb(mm, tmp, rb_link, rb_parent); 398 399 rb_link = &tmp->vm_rb.rb_right;
+17 -4
mm/mmap.c
··· 388 388 __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma, 389 389 struct vm_area_struct *prev, struct rb_node *rb_parent) 390 390 { 391 + struct vm_area_struct *next; 392 + 393 + vma->vm_prev = prev; 391 394 if (prev) { 392 - vma->vm_next = prev->vm_next; 395 + next = prev->vm_next; 393 396 prev->vm_next = vma; 394 397 } else { 395 398 mm->mmap = vma; 396 399 if (rb_parent) 397 - vma->vm_next = rb_entry(rb_parent, 400 + next = rb_entry(rb_parent, 398 401 struct vm_area_struct, vm_rb); 399 402 else 400 - vma->vm_next = NULL; 403 + next = NULL; 401 404 } 405 + vma->vm_next = next; 406 + if (next) 407 + next->vm_prev = vma; 402 408 } 403 409 404 410 void __vma_link_rb(struct mm_struct *mm, struct vm_area_struct *vma, ··· 489 483 __vma_unlink(struct mm_struct *mm, struct vm_area_struct *vma, 490 484 struct vm_area_struct *prev) 491 485 { 492 - prev->vm_next = vma->vm_next; 486 + struct vm_area_struct *next = vma->vm_next; 487 + 488 + prev->vm_next = next; 489 + if (next) 490 + next->vm_prev = prev; 493 491 rb_erase(&vma->vm_rb, &mm->mm_rb); 494 492 if (mm->mmap_cache == vma) 495 493 mm->mmap_cache = prev; ··· 1925 1915 unsigned long addr; 1926 1916 1927 1917 insertion_point = (prev ? &prev->vm_next : &mm->mmap); 1918 + vma->vm_prev = NULL; 1928 1919 do { 1929 1920 rb_erase(&vma->vm_rb, &mm->mm_rb); 1930 1921 mm->map_count--; ··· 1933 1922 vma = vma->vm_next; 1934 1923 } while (vma && vma->vm_start < end); 1935 1924 *insertion_point = vma; 1925 + if (vma) 1926 + vma->vm_prev = prev; 1936 1927 tail_vma->vm_next = NULL; 1937 1928 if (mm->unmap_area == arch_unmap_area) 1938 1929 addr = prev ? prev->vm_end : mm->mmap_base;
+5 -2
mm/nommu.c
··· 604 604 */ 605 605 static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma) 606 606 { 607 - struct vm_area_struct *pvma, **pp; 607 + struct vm_area_struct *pvma, **pp, *next; 608 608 struct address_space *mapping; 609 609 struct rb_node **p, *parent; 610 610 ··· 664 664 break; 665 665 } 666 666 667 - vma->vm_next = *pp; 667 + next = *pp; 668 668 *pp = vma; 669 + vma->vm_next = next; 670 + if (next) 671 + next->vm_prev = vma; 669 672 } 670 673 671 674 /*