Skip to content

treewide: Refactor heap related implementation

Kuan-Wei Chiu dm-devel linux-bcache linux-bcachefs linux-perf-users lkml 7 versions – Applied

Status from this message: [merged mm-nonmm-stable] bcachefs-remove-heap-related-macros-and-switch-to-generic-min_heap.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest16 patches 0 repliesApplied 16/16
  2. v5 posting 2/216 patches 7 repliesSuperseded
  3. v5 posting 1/22 of 16 patches 0 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v416 patches2 repliesSuperseded
v317 patches14 repliesSuperseded
v215 patches19 repliesSuperseded
v113 patches19 repliesSuperseded

Changes in v6 from the cover letter

- Rename the MIN_HEAP() macro to DEFINE_MIN_HEAP().

Patches in v6 All 16 applied

#Subject and filesSizeRepliesApplied
1/16perf/core: Fix several typoskernel/events/core.c+4 -40 repliesApplied
2/16bcache: Fix typodrivers/md/bcache/util.c+1 -10 repliesApplied
3/16bcachefs: Fix typofs/bcachefs/util.c+1 -10 repliesApplied
4/16lib min_heap: Add type safe interfacedrivers/md/dm-vdo/repair.c drivers/md/dm-vdo/slab-depot.c include/linux/min_heap.h +2 more+70 -470 repliesApplied
5/16lib min_heap: Add min_heap_init()include/linux/min_heap.h+15 -00 repliesApplied
6/16lib min_heap: Add min_heap_peek()include/linux/min_heap.h+10 -00 repliesApplied
7/16lib min_heap: Add min_heap_full()include/linux/min_heap.h+10 -00 repliesApplied
8/16lib min_heap: Add args for min_heap_callbacksdrivers/md/dm-vdo/repair.c drivers/md/dm-vdo/slab-depot.c include/linux/min_heap.h +2 more+54 -520 repliesApplied
9/16lib min_heap: Add min_heap_sift_up()include/linux/min_heap.h+20 -00 repliesApplied
10/16lib min_heap: Add min_heap_del()include/linux/min_heap.h+24 -00 repliesApplied
11/16lib min_heap: Update min_heap_push() and min_heap_pop() to return bool valuesinclude/linux/min_heap.h+8 -40 repliesApplied
12/16lib min_heap: Rename min_heapify() to min_heap_sift_down()drivers/md/dm-vdo/repair.c include/linux/min_heap.h kernel/events/core.c+9 -90 repliesApplied
13/16lib min_heap: Update min_heap_push() to use min_heap_sift_up()include/linux/min_heap.h+1 -80 repliesApplied
14/16lib/test_min_heap: Add test for heap_del()lib/test_min_heap.c+36 -00 repliesApplied
15/16bcache: Remove heap-related macros and switch to generic min_heapdrivers/md/bcache/alloc.c drivers/md/bcache/bcache.h drivers/md/bcache/bset.c +8 more+263 -2170 repliesApplied
16/16bcachefs: Remove heap-related macros and switch to generic min_heapfs/bcachefs/clock.c fs/bcachefs/clock_types.h fs/bcachefs/ec.c +2 more+87 -1540 repliesApplied

Reviews trailers per patch

All 16 patches have a Reviewed-by or Acked-by.

PatchIan RogersRandy DunlapColy LiKent Overstreet
1/16R-b R-b
2/16R-b R-b
3/16R-b R-b
4/16R-b
5/16R-b
6/16R-b
7/16R-b
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 A-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 4 reviewers.

Read the v6 thread

Cover letter [PATCH v6 00/16] treewide: Refactor heap related implementation

This patch series focuses on several adjustments related to heap implementation. Firstly, a type-safe interface has been added to the min_heap, along with the introduction of several new functions to enhance its functionality. Additionally, the heap implementation for bcache and bcachefs has been replaced with the generic min_heap implementation from include/linux. Furthermore, several typos have been corrected.

Previous discussion with Kent Overstreet:
https://lkml.kernel.org/ioyfizrzq7w7mjrqcadtzsfgpuntowtjdw5pgn4qhvsdp4mqqg@nrlek5vmisbu

Regards,
Kuan-Wei

---

You can preview this patch series on the 'refactor-heap' branch of the repository at the following link:

https://github.com/visitorckw/linux

Changes in v6:
- Rename the MIN_HEAP() macro to DEFINE_MIN_HEAP().

Changes in RESEND v5:
- Resend because the mail service failed to send out all patches.

Changes in v5:
- Rebase on the block tree to resolve the conflict in bcache.
- Fix missing initialization for heap data pointer in bcache's bch_btree_node_read_done().

Changes in v4:
- Change struct initializations to use designated initializers.
- Replace memcpy() with func->swp() in heap_del() due to issues with set_backpointer in bcachefs when setting idx.
- Fix an error in ec_stripes_heap_swap() where ec_stripes_heap_set_backpointer() should be called after swapping.

Changes in v3:
- Avoid heap->heap.nr to eliminate the nested types.
- Add MIN_HEAP_PREALLOCATED macro for preallocating some elements.
- Use min_heap_sift_up() in min_heap_push().
- Fix a bug in heap_del() where we should copy the last element to 'data + idx * element_size' instead of 'data'.
- Add testcases for heap_del().
- Fix bugs in bcache/bcachefs patches where the parameter types in some compare functions should have been 'type **', but were mistakenly written as 'type *'.

Changes in v2:
- Add attribute __always_unused to the compare and swap functions that do not use the args parameter.
- Rename min_heapify() to min_heap_sift_down().
- Update lib/test_min_heap.c to use min_heap_init().
- Refine the commit message for bcache and bcachefs.
- Adjust the order of patches in the patch series.

Link to resend v5: https://lore.kernel.org/[email protected]
Link to v5: https://lore.kernel.org/[email protected]
Link to v4: https://lore.kernel.org/[email protected]
Link to v3: https://lore.kernel.org/[email protected]
Link to v2: https://lore.kernel.org/[email protected]
Link to v1: https://lkml.kernel.org/[email protected]

Kuan-Wei Chiu (16):
perf/core: Fix several typos
bcache: Fix typo
bcachefs: Fix typo
lib min_heap: Add type safe interface
lib min_heap: Add min_heap_init()
lib min_heap: Add min_heap_peek()
lib min_heap: Add min_heap_full()
lib min_heap: Add args for min_heap_callbacks
lib min_heap: Add min_heap_sift_up()
lib min_heap: Add min_heap_del()
lib min_heap: Update min_heap_push() and min_heap_pop() to return bool
values
lib min_heap: Rename min_heapify() to min_heap_sift_down() lib min_heap: Update min_heap_push() to use min_heap_sift_up() lib/test_min_heap: Add test for heap_del()
bcache: Remove heap-related macros and switch to generic min_heap
bcachefs: Remove heap-related macros and switch to generic min_heap

 drivers/md/bcache/alloc.c      |  64 ++++++++---
 drivers/md/bcache/bcache.h     |   2 +-
 drivers/md/bcache/bset.c       | 124 ++++++++++++++--------
 drivers/md/bcache/bset.h       |  40 +++----
 drivers/md/bcache/btree.c      |  69 +++++++-----
 drivers/md/bcache/extents.c    |  53 ++++++----
 drivers/md/bcache/movinggc.c   |  41 +++++--
 drivers/md/bcache/super.c      |   3 +-
 drivers/md/bcache/sysfs.c      |   4 +-
 drivers/md/bcache/util.c       |   2 +-
 drivers/md/bcache/util.h       |  67 +-----------
 drivers/md/bcache/writeback.c  |  13 ++-
 drivers/md/dm-vdo/repair.c     |  19 ++--
 drivers/md/dm-vdo/slab-depot.c |  14 +--
 fs/bcachefs/clock.c            |  43 ++++++--
 fs/bcachefs/clock_types.h      |   2 +-
 fs/bcachefs/ec.c               |  76 ++++++++-----
 fs/bcachefs/ec_types.h         |   2 +-
 fs/bcachefs/util.c             |   2 +-
 fs/bcachefs/util.h             | 118 +--------------------
 include/linux/min_heap.h       | 188 +++++++++++++++++++++++++--------
 kernel/events/core.c           |  29 ++---
 lib/test_min_heap.c            |  75 +++++++++----
 23 files changed, 583 insertions(+), 467 deletions(-)
Signature · 1 line
2.34.1