linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/12] rbtree updates
@ 2012-07-13  0:31 Michel Lespinasse
  2012-07-13  0:31 ` [PATCH v2 01/12] rbtree: reference Documentation/rbtree.txt for usage instructions Michel Lespinasse
                   ` (11 more replies)
  0 siblings, 12 replies; 27+ messages in thread
From: Michel Lespinasse @ 2012-07-13  0:31 UTC (permalink / raw)
  To: aarcange, dwmw2, riel, peterz, daniel.santos, axboe, ebiederm, akpm
  Cc: linux-mm, linux-kernel, torvalds

Change log since v1:
- Added tree graphs as comments as suggested by Peter
- Fixed coding style in rest of lib/rbtree.c as suggested by Peter
- made clear rb_parent_color is private, not to be directly accessed,
  by renaming it to __rb_parent_color
- collapsed some low level optimization patches instead of splitting out
  the parts that were related to tree rotatoins from the parts that were
  related to color flips.
- Added build system support in patch 5

These are quite minor changes against v1, which already got good reviews
from Peter, so I think all that is required now is for Andrea to say he
doesn't oppose this.

--

I recently started looking at the rbtree code (with an eye towards
improving the augmented rbtree support, but I haven't gotten there
yet). I noticed a lot of possible speed improvements, which I am now
proposing in this patch set.

Patches 1-4 are preparatory: remove internal functions from rbtree.h
so that users won't be tempted to use them instead of the documented
APIs, clean up some incorrect usages I've noticed (in particular, with
the recently added fs/proc/proc_sysctl.c rbtree usage), reference the
documentation so that people have one less excuse to miss it, etc.

Patch 5 is a small module I wrote to check the rbtree performance.
It creates 100 nodes with random keys and repeatedly inserts and erases
them from an rbtree. Additionally, it has code to check for rbtree
invariants after each insert or erase operation.

Patches 6-12 is where the rbtree optimizations are done, and they touch
only that one file, lib/rbtree.c . I am getting good results out of these -
in my small benchmark doing rbtree insertion (including search) and erase,
I'm seeing a 30% runtime reduction on Sandybridge E5, which is more than
I initially thought would be possible. (the results aren't as impressive
on my two other test hosts though, AMD barcelona and Intel Westmere, where
I am seeing 14% runtime reduction only). The code size - both source
(ommiting comments) and compiled - is also shorter after these changes.
However, I do admit that the updated code is more arduous to read - one
big reason for that is the removal of the tree rotation helpers, which
added some overhead but also made it easier to reason about things locally.
Overall, I believe this is an acceptable compromise, given that this code
doesn't get modified very often, and that I have good tests for it.

Upon Peter's suggestion, I added comments showing the rtree configuration
before every rotation. I think they help; however it's still best to have
a copy of the cormen/leiserson/rivest book when digging into this code.

This patchset is against v3.4. This code doesn't change very often, so
the patchset should apply to the latest and greatest too.

My proposal would be for this to go in -mm tree to be used as a base to add
on the augmented rbtree support enhancements, which I am already working on.

Michel Lespinasse (12):
  rbtree: reference Documentation/rbtree.txt for usage instructions
  rbtree: empty nodes have no color
  rbtree: fix incorrect rbtree node insertion in fs/proc/proc_sysctl.c
  rbtree: move some implementation details from rbtree.h to rbtree.c
  rbtree: performance and correctness test
  rbtree: break out of rb_insert_color loop after tree rotation
  rbtree: adjust root color in rb_insert_color() only when necessary
  rbtree: low level optimizations in rb_insert_color()
  rbtree: adjust node color in __rb_erase_color() only when necessary
  rbtree: optimize case selection logic in __rb_erase_color()
  rbtree: low level optimizations in __rb_erase_color()
  rbtree: coding style adjustments

 Makefile                   |    2 +-
 fs/proc/proc_sysctl.c      |    5 +-
 include/linux/rbtree.h     |  112 ++---------
 include/linux/timerqueue.h |    2 +-
 lib/Kconfig.debug          |    1 +
 lib/rbtree.c               |  487 ++++++++++++++++++++++++++++----------------
 tests/Kconfig              |   18 ++
 tests/Makefile             |    1 +
 tests/rbtree_test.c        |  135 ++++++++++++
 9 files changed, 487 insertions(+), 276 deletions(-)
 create mode 100644 tests/Kconfig
 create mode 100644 tests/Makefile
 create mode 100644 tests/rbtree_test.c

-- 
1.7.7.3


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

end of thread, other threads:[~2012-09-08 11:49 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-13  0:31 [PATCH v2 00/12] rbtree updates Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 01/12] rbtree: reference Documentation/rbtree.txt for usage instructions Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 02/12] rbtree: empty nodes have no color Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 03/12] rbtree: fix incorrect rbtree node insertion in fs/proc/proc_sysctl.c Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 04/12] rbtree: move some implementation details from rbtree.h to rbtree.c Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 05/12] rbtree: performance and correctness test Michel Lespinasse
2012-07-13 20:15   ` Andrew Morton
2012-07-13 22:33     ` Michel Lespinasse
2012-07-13 22:45       ` Andrew Morton
2012-07-13 23:09         ` Michel Lespinasse
2012-07-13 23:11           ` Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 06/12] rbtree: break out of rb_insert_color loop after tree rotation Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 07/12] rbtree: adjust root color in rb_insert_color() only when necessary Michel Lespinasse
2012-08-31  8:01   ` Adrian Hunter
2012-08-31  8:07     ` Michel Lespinasse
2012-08-31  8:15       ` Andrew Morton
2012-08-31  8:35         ` Adrian Hunter
2012-08-31  8:39           ` Michel Lespinasse
2012-09-06 20:47             ` Olof Johansson
2012-08-31  9:25           ` Alexander Shishkin
2012-09-08  1:26           ` Arnaldo Carvalho de Melo
2012-09-08 11:49     ` [tip:perf/core] perf tools: Fix build for another rbtree.c change tip-bot for Adrian Hunter
2012-07-13  0:31 ` [PATCH v2 08/12] rbtree: low level optimizations in rb_insert_color() Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 09/12] rbtree: adjust node color in __rb_erase_color() only when necessary Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 10/12] rbtree: optimize case selection logic in __rb_erase_color() Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 11/12] rbtree: low level optimizations " Michel Lespinasse
2012-07-13  0:31 ` [PATCH v2 12/12] rbtree: coding style adjustments 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).