linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] rbtree based interval tree as a prio_tree replacement
@ 2012-08-07  7:25 Michel Lespinasse
  2012-08-07  7:25 ` [PATCH 1/5] rbtree: add prio tree and interval tree tests Michel Lespinasse
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Michel Lespinasse @ 2012-08-07  7:25 UTC (permalink / raw)
  To: riel, peterz, vrajesh, daniel.santos, aarcange, dwmw2, akpm
  Cc: linux-mm, linux-kernel, torvalds

This patchset goes over the rbtree changes that have been already integrated
into Andrew's -mm tree, as well as the augmented rbtree proposal which is
currently pending.

Patch 1 implements support for interval trees, on top of the augmented
rbtree API. It also adds synthetic tests to compare the performance of
interval trees vs prio trees. Short answers is that interval trees are
slightly faster (~25%) on insert/erase, and much faster (~2.4 - 3x)
on search. It is debatable how realistic the synthetic test is, and I have
not made such measurements yet, but my impression is that interval trees
would still come out faster.

Patch 2 uses a preprocessor template to make the interval tree generic,
and uses it as a replacement for the vma prio_tree.

Patch 3 takes the other prio_tree user, kmemleak, and converts it to use
a basic rbtree. We don't actually need the augmented rbtree support here
because the intervals are always non-overlapping.

Patch 4 removes the now-unused prio tree library.

Patch 5 proposes an additional optimization to rb_erase_augmented, now
providing it as an inline function so that the augmented callbacks can be
inlined in. This provides an additional 5-10% performance improvement
for the interval tree insert/erase benchmark. There is a maintainance cost
as it exposes augmented rbtree users to some of the rbtree library internals;
however I think this cost shouldn't be too high as I expect the augmented
rbtree will always have much less users than the base rbtree.

I should probably add a quick summary of why I think it makes sense to
replace prio trees with augmented rbtree based interval trees now.
One of the drivers is that we need augmented rbtrees for Rik's vma
gap finding code, and once you have them, it just makes sense to use them
for interval trees as well, as this is the simpler and more well known
algorithm. prio trees, in comparison, seem *too* clever: they impose an
additional 'heap' constraint on the tree, which they use to guarantee
a faster worst-case complexity of O(k+log N) for stabbing queries in a
well-balanced prio tree, vs O(k*log N) for interval trees (where k=number
of matches, N=number of intervals). Now this sounds great, but in practice
prio trees don't realize this theorical benefit. First, the additional
constraint makes them harder to update, so that the kernel implementation
has to simplify things by balancing them like a radix tree, which is not
always ideal. Second, the fact that there are both index and heap
properties makes both tree manipulation and search more complex,
which results in a higher multiplicative time constant. As it turns out,
the simple interval tree algorithm ends up running faster than the more
clever prio tree.

Michel Lespinasse (5):
  rbtree: add prio tree and interval tree tests
  mm: replace vma prio_tree with an interval tree
  kmemleak: use rbtree instead of prio tree
  prio_tree: remove
  rbtree: move augmented rbtree functionality to rbtree_augmented.h

 Documentation/00-INDEX             |    2 -
 Documentation/prio_tree.txt        |  107 --------
 Documentation/rbtree.txt           |   13 +
 arch/arm/mm/fault-armv.c           |    3 +-
 arch/arm/mm/flush.c                |    3 +-
 arch/parisc/kernel/cache.c         |    3 +-
 arch/x86/mm/hugetlbpage.c          |    3 +-
 arch/x86/mm/pat_rbtree.c           |    2 +-
 fs/hugetlbfs/inode.c               |    9 +-
 fs/inode.c                         |    2 +-
 include/linux/fs.h                 |    6 +-
 include/linux/interval_tree.h      |   27 ++
 include/linux/interval_tree_tmpl.h |  219 +++++++++++++++++
 include/linux/mm.h                 |   30 ++-
 include/linux/mm_types.h           |   14 +-
 include/linux/prio_tree.h          |  120 ---------
 include/linux/rbtree.h             |   48 ----
 include/linux/rbtree_augmented.h   |  223 +++++++++++++++++
 init/main.c                        |    2 -
 kernel/events/uprobes.c            |    3 +-
 kernel/fork.c                      |    2 +-
 lib/Kconfig.debug                  |    6 +
 lib/Makefile                       |    5 +-
 lib/interval_tree.c                |   13 +
 lib/interval_tree_test_main.c      |  105 ++++++++
 lib/prio_tree.c                    |  466 ------------------------------------
 lib/rbtree.c                       |  162 +------------
 lib/rbtree_test.c                  |    2 +-
 mm/Makefile                        |    4 +-
 mm/filemap_xip.c                   |    3 +-
 mm/fremap.c                        |    2 +-
 mm/hugetlb.c                       |    3 +-
 mm/interval_tree.c                 |   61 +++++
 mm/kmemleak.c                      |   98 ++++----
 mm/memory-failure.c                |    3 +-
 mm/memory.c                        |    9 +-
 mm/mmap.c                          |   22 +-
 mm/nommu.c                         |   12 +-
 mm/prio_tree.c                     |  208 ----------------
 mm/rmap.c                          |   18 +-
 40 files changed, 803 insertions(+), 1240 deletions(-)
 delete mode 100644 Documentation/prio_tree.txt
 create mode 100644 include/linux/interval_tree.h
 create mode 100644 include/linux/interval_tree_tmpl.h
 delete mode 100644 include/linux/prio_tree.h
 create mode 100644 include/linux/rbtree_augmented.h
 create mode 100644 lib/interval_tree.c
 create mode 100644 lib/interval_tree_test_main.c
 delete mode 100644 lib/prio_tree.c
 create mode 100644 mm/interval_tree.c
 delete mode 100644 mm/prio_tree.c

-- 
1.7.7.3

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-08-30 22:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-07  7:25 [PATCH 0/5] rbtree based interval tree as a prio_tree replacement Michel Lespinasse
2012-08-07  7:25 ` [PATCH 1/5] rbtree: add prio tree and interval tree tests Michel Lespinasse
2012-08-07  7:25 ` [PATCH 2/5] mm: replace vma prio_tree with an interval tree Michel Lespinasse
2012-08-14 12:11   ` Hillf Danton
2012-08-07  7:25 ` [PATCH 3/5] kmemleak: use rbtree instead of prio tree Michel Lespinasse
2012-08-08 17:07   ` Michel Lespinasse
2012-08-09  8:31     ` Catalin Marinas
2012-08-15 16:36       ` Catalin Marinas
2012-08-15 20:53         ` Michel Lespinasse
2012-08-16 15:06           ` Catalin Marinas
2012-08-07  7:25 ` [PATCH 4/5] prio_tree: remove Michel Lespinasse
2012-08-07  7:25 ` [PATCH 5/5] rbtree: move augmented rbtree functionality to rbtree_augmented.h Michel Lespinasse
2012-08-08  1:19   ` Michel Lespinasse
2012-08-13  8:20 ` [PATCH 0/5] rbtree based interval tree as a prio_tree replacement Peter Zijlstra
2012-08-13 10:37   ` Michel Lespinasse
2012-08-30 21:34 ` Andrew Morton
2012-08-30 21:43   ` Rik van Riel
2012-08-30 22:33   ` Michel Lespinasse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).