Skip to content

mm: use augmented rbtrees for finding unmapped areas

Michel Lespinasse linux-arm-kernel linux-mips linux-mm linux-sh lkml sparclinux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest16 patches 25 repliesIn review

Change log since the previous (RFC) send from the cover letter

- Added bug fix in validate_mm(), noticed by Sasha Levin and figured out by Bob Liu, which sometimes caused NULL pointer dereference when running with CONFIG_DEBUG_VM_RB=y
- Fixed generic and x86_64 arch_get_unmapped_area_topdown to avoid allocating new areas at addr=0 as suggested by Rik Van Riel
- Converted more architectures to use the new vm_unmapped_area() search function
- Converted hugetlbfs (generic / i386 / sparc64 / tile) to use the new vm_unmapped_area() search function as well.

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16mm: add anon_vma_lock to validate_mm()mm/mmap.c+2 -02 replies
2/16mm: augment vma rbtree with rb_subtree_gapinclude/linux/mm_types.h mm/mmap.c+114 -90 replies
3/16mm: check rb_subtree_gap correctnessmm/mmap.c+16 -84 replies
4/16mm: rearrange vm_area_struct for fewer cache missesinclude/linux/mm_types.h+8 -40 replies
5/16mm: vm_unmapped_area() lookup functioninclude/linux/mm.h mm/mmap.c+253 -900 replies
6/16mm: use vm_unmapped_area() on x86_64 architecturearch/x86/include/asm/elf.h arch/x86/kernel/sys_x86_64.c arch/x86/vdso/vma.c+33 -1260 replies
7/16mm: fix cache coloring on x86_64 architecturearch/x86/kernel/sys_x86_64.c+2 -21 reply
8/16mm: use vm_unmapped_area() in hugetlbfsfs/hugetlbfs/inode.c+8 -341 reply
9/16mm: use vm_unmapped_area() in hugetlbfs on i386 architecturearch/x86/mm/hugetlbpage.c+25 -1053 replies
10/16mm: use vm_unmapped_area() on mips architecturearch/mips/mm/mmap.c+17 -822 replies
11/16mm: use vm_unmapped_area() on arm architecturearch/arm/mm/mmap.c+23 -962 replies
12/16mm: use vm_unmapped_area() on sh architecturearch/sh/mm/mmap.c+24 -1021 reply
13/16mm: use vm_unmapped_area() on sparc64 architecturearch/sparc/kernel/sys_sparc_64.c+30 -1021 reply
14/16mm: use vm_unmapped_area() in hugetlbfs on sparc64 architecturearch/sparc/mm/hugetlbpage.c+30 -931 reply
15/16mm: use vm_unmapped_area() on sparc32 architecturearch/sparc/kernel/sys_sparc_32.c+9 -155 replies
16/16mm: use vm_unmapped_area() in hugetlbfs on tile architecturearch/tile/mm/hugetlbpage.c+25 -1141 reply

Reviews trailers per patch

14 of 16 patches have a Reviewed-by or Acked-by.

PatchBob LiuRik van RielDavid S. Miller
1/16Figured-out-by R-b
2/16R-b
3/16R-b
4/16
5/16R-b
6/16R-b
7/16Proposed-by
8/16R-b
9/16R-b
10/16R-b
11/16R-b
12/16R-b
13/16R-b
14/16R-b
15/16R-b A-b
16/16R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [PATCH 00/16] mm: use augmented rbtrees for finding unmapped areas

Earlier this year, Rik proposed using augmented rbtrees to optimize our search for a suitable unmapped area during mmap(). This prompted my work on improving the augmented rbtree code. Rik doesn't seem to have time to follow up on his idea at this time, so I'm sending this series to revive the idea.

These changes are against v3.7-rc4. I have not converted all applicable architectuers yet, but we don't necessarily need to get them all onboard at once - the series is fully bisectable and additional architectures can be added later on. I am confident enough in my tests for patches 1-8; however the second half of the series basically didn't get tested as I don't have access to all the relevant architectures.

Change log since the previous (RFC) send:
- Added bug fix in validate_mm(), noticed by Sasha Levin and figured out by Bob Liu, which sometimes caused NULL pointer dereference when running with CONFIG_DEBUG_VM_RB=y
- Fixed generic and x86_64 arch_get_unmapped_area_topdown to avoid allocating new areas at addr=0 as suggested by Rik Van Riel
- Converted more architectures to use the new vm_unmapped_area() search function
- Converted hugetlbfs (generic / i386 / sparc64 / tile) to use the new vm_unmapped_area() search function as well.

In this resend, I have kept Rik's Reviewed-by tags from the original RFC submission for patches that haven't been updated other than applying his suggestions.

Patch 1 is the validate_mm() fix from Bob Liu (+ fixed-the-fix from me :)

Patch 2 augments the VMA rbtree with a new rb_subtree_gap field, indicating the length of the largest gap immediately preceding any VMAs in a subtree.

Patch 3 adds new checks to CONFIG_DEBUG_VM_RB to verify the above information is correctly maintained.

Patch 4 rearranges the vm_area_struct layout so that rbtree searches only need data that is contained in the first cacheline (this one is from Rik's original patch series)

Patch 5 adds a generic vm_unmapped_area() search function, which allows for searching for an address space of any desired length, within [low; high[ address constraints, with any desired alignment. The generic arch_get_unmapped_area[_topdown] functions are also converted to use this.

Patch 6 converts the x86_64 arch_get_unmapped_area[_topdown] functions to use vm_unmapped_area() as well.

Patch 7 fixes cache coloring on x86_64, as suggested by Rik in his previous series.

Patch 8 and 9 convert the generic and i386 hugetlbfs code to use vm_unmapped_area()

Patches 10-16 convert extra architectures to use vm_unmapped_area()

I'm happy that this series removes more code than it adds, as calling vm_unmapped_area() with the desired arguments is quite shorter than duplicating the brute force algorithm all over the place. There is still a bit of repetition between various implementations of arch_get_unmapped_area[_topdown] functions that could probably be simplified somehow, but I feel we can keep that for a later step...

Michel Lespinasse (15):
mm: add anon_vma_lock to validate_mm()
mm: augment vma rbtree with rb_subtree_gap
mm: check rb_subtree_gap correctness
mm: vm_unmapped_area() lookup function
mm: use vm_unmapped_area() on x86_64 architecture
mm: fix cache coloring on x86_64 architecture
mm: use vm_unmapped_area() in hugetlbfs
mm: use vm_unmapped_area() in hugetlbfs on i386 architecture
mm: use vm_unmapped_area() on mips architecture
mm: use vm_unmapped_area() on arm architecture
mm: use vm_unmapped_area() on sh architecture
mm: use vm_unmapped_area() on sparc64 architecture
mm: use vm_unmapped_area() in hugetlbfs on sparc64 architecture
mm: use vm_unmapped_area() on sparc32 architecture
mm: use vm_unmapped_area() in hugetlbfs on tile architecture

Rik van Riel (1):
mm: rearrange vm_area_struct for fewer cache misses

 arch/arm/mm/mmap.c               |  119 ++--------
 arch/mips/mm/mmap.c              |   99 ++-------
 arch/sh/mm/mmap.c                |  126 ++---------
 arch/sparc/kernel/sys_sparc_32.c |   24 +--
 arch/sparc/kernel/sys_sparc_64.c |  132 +++---------
 arch/sparc/mm/hugetlbpage.c      |  123 +++--------
 arch/tile/mm/hugetlbpage.c       |  139 ++----------
 arch/x86/include/asm/elf.h       |    6 +-
 arch/x86/kernel/sys_x86_64.c     |  151 +++----------
 arch/x86/mm/hugetlbpage.c        |  130 ++---------
 arch/x86/vdso/vma.c              |    2 +-
 fs/hugetlbfs/inode.c             |   42 +---
 include/linux/mm.h               |   31 +++
 include/linux/mm_types.h         |   19 ++-
 mm/mmap.c                        |  452 +++++++++++++++++++++++++++++---------
 15 files changed, 616 insertions(+), 979 deletions(-)
Signature · 1 line
1.7.7.3