Skip to content

Generic rb tree code

Kent Overstreet linux-bcache lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 9 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3rbtree: Add rb_insert(), rb_search(), etc.include/linux/rbtree.h lib/rbtree.c+138 -01 reply
2/3timerqueue: convert to generic rb tree codelib/timerqueue.c+9 -140 replies
3/3block: convert elevator to generic rb tree codeblock/elevator.c+12 -304 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] Generic rb tree code

Right now, users of the rb tree code have to open code their own search and insert functions. This provides generic versions that you pass a comparison function to.

I highly doubt the extra function calls are going to have a measurable performance impact in practice - the pointer chasing is going to dominate. I did provide inline versions just in case, though - it's modelled after the spinlock code.

The inline version of rb_search() is important for another reason, though - you have to pass rb_search a pointer to your struct for it to compare against, which has to be allocated on the stack. For most users I think that'll be fine, but for the elevator code struct rb_node is embedded in struct request, which is rather large. By using the inline version that stack allocation goes away.

(I looked at the generated assembly of elv_rb_find() before and after, and if I'm reading it right it's not using any extra stack. Code is a bit worse, but IMO removing code duplication is worth it).

Kent Overstreet (3):
rbtree: Add rb_insert(), rb_search(), etc.
timerqueue: convert to generic rb tree code
block: convert elevator to generic rb tree code

 block/elevator.c       |   42 ++++++------------
 include/linux/rbtree.h |  110 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/rbtree.c           |   28 ++++++++++++
 lib/timerqueue.c       |   23 ++++------
 4 files changed, 159 insertions(+), 44 deletions(-)
Signature · 1 line
1.7.9.3.327.g2980b