Re: [PATCH v2 12/15] lib min_heap: Rename min_heapify() to min_heap_sift_down()

From: Ian Rogers
Date: Wed Mar 20 2024 - 13:18:19 EST


On Wed, Mar 20, 2024 at 7:55 AM Kuan-Wei Chiu <visitorckw@xxxxxxxxx> wrote:
>
> After adding min_heap_sift_up(), the naming convention has been
> adjusted to maintain consistency with the min_heap_sift_up().
> Consequently, min_heapify() has been renamed to min_heap_sift_down().
>
> Link: https://lkml.kernel.org/CAP-5=fVcBAxt8Mw72=NCJPRJfjDaJcqk4rjbadgouAEAHz_q1A@xxxxxxxxxxxxxx
> Signed-off-by: Kuan-Wei Chiu <visitorckw@xxxxxxxxx>

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks,
Ian

> ---
> drivers/md/dm-vdo/repair.c | 2 +-
> include/linux/min_heap.h | 14 +++++++-------
> kernel/events/core.c | 2 +-
> 3 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/md/dm-vdo/repair.c b/drivers/md/dm-vdo/repair.c
> index 6acaebcd305d..e99f908bbdb9 100644
> --- a/drivers/md/dm-vdo/repair.c
> +++ b/drivers/md/dm-vdo/repair.c
> @@ -183,7 +183,7 @@ static struct numbered_block_mapping *sort_next_heap_element(struct repair_compl
> */
> last = &repair->entries[--heap->heap.nr];
> swap_mappings(heap->heap.data, last, NULL);
> - min_heapify(heap, 0, &repair_min_heap, NULL);
> + min_heap_sift_down(heap, 0, &repair_min_heap, NULL);
> return last;
> }
>
> diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h
> index 586965977104..436997070f4e 100644
> --- a/include/linux/min_heap.h
> +++ b/include/linux/min_heap.h
> @@ -78,7 +78,7 @@ bool __min_heap_full(struct __min_heap *heap)
>
> /* Sift the element at pos down the heap. */
> static __always_inline
> -void __min_heapify(struct __min_heap *heap, int pos, size_t elem_size,
> +void __min_heap_sift_down(struct __min_heap *heap, int pos, size_t elem_size,
> const struct min_heap_callbacks *func, void *args)
> {
> void *left, *right;
> @@ -111,8 +111,8 @@ void __min_heapify(struct __min_heap *heap, int pos, size_t elem_size,
> }
> }
>
> -#define min_heapify(_heap, _pos, _func, _args) \
> - __min_heapify(&(_heap)->heap, _pos, __minheap_obj_size(_heap), _func, _args)
> +#define min_heap_sift_down(_heap, _pos, _func, _args) \
> + __min_heap_sift_down(&(_heap)->heap, _pos, __minheap_obj_size(_heap), _func, _args)
>
> /* Floyd's approach to heapification that is O(nr). */
> static __always_inline
> @@ -122,7 +122,7 @@ void __min_heapify_all(struct __min_heap *heap, size_t elem_size,
> int i;
>
> for (i = heap->nr / 2 - 1; i >= 0; i--)
> - __min_heapify(heap, i, elem_size, func, args);
> + __min_heap_sift_down(heap, i, elem_size, func, args);
> }
>
> #define min_heapify_all(_heap, _func, _args) \
> @@ -141,7 +141,7 @@ bool __min_heap_pop(struct __min_heap *heap, size_t elem_size,
> /* Place last element at the root (position 0) and then sift down */
> heap->nr--;
> memcpy(data, data + (heap->nr * elem_size), elem_size);
> - __min_heapify(heap, 0, elem_size, func, args);
> + __min_heap_sift_down(heap, 0, elem_size, func, args);
>
> return true;
> }
> @@ -161,7 +161,7 @@ void __min_heap_pop_push(struct __min_heap *heap,
> void *args)
> {
> memcpy(heap->data, element, elem_size);
> - __min_heapify(heap, 0, elem_size, func, args);
> + __min_heap_sift_down(heap, 0, elem_size, func, args);
> }
>
> #define min_heap_pop_push(_heap, _element, _func, _args) \
> @@ -235,7 +235,7 @@ bool __min_heap_del(struct __min_heap *heap, size_t elem_size, size_t idx,
> return true;
> memcpy(data, data + (heap->nr * elem_size), elem_size);
> __min_heap_sift_up(heap, elem_size, idx, func, args);
> - __min_heapify(heap, idx, elem_size, func, args);
> + __min_heap_sift_down(heap, idx, elem_size, func, args);
>
> return true;
> }
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index c32a78c489f3..314fb7ea4ec3 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -3788,7 +3788,7 @@ static noinline int visit_groups_merge(struct perf_event_context *ctx,
>
> *evt = perf_event_groups_next(*evt, pmu);
> if (*evt)
> - min_heapify(&event_heap, 0, &perf_min_heap, NULL);
> + min_heap_sift_down(&event_heap, 0, &perf_min_heap, NULL);
> else
> min_heap_pop(&event_heap, &perf_min_heap, NULL);
> }
> --
> 2.34.1
>