Skip to content

Commit c499c71

Browse files
visitorckwakpm00
authored andcommitted
lib min_heap: optimize number of calls to min_heapify()
Patch series "lib min_heap: Min heap optimizations". The purpose of this patch series is to enhance the existing min heap implementation. The optimization focuses on both the heap construction process and the number of comparisons made during the heapify operation. This patch (of 2): Improve the heap construction process by reducing unnecessary heapify operations. Specifically, adjust the starting condition from n / 2 to n / 2 - 1 in the loop that iterates over all non-leaf elements. Link: https://lkml.kernel.org/r/20240110081213.2289636-1-visitorckw@gmail.com Link: https://lkml.kernel.org/r/20240110081213.2289636-2-visitorckw@gmail.com Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b73aa53 commit c499c71

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/linux/min_heap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void min_heapify_all(struct min_heap *heap,
7070
{
7171
int i;
7272

73-
for (i = heap->nr / 2; i >= 0; i--)
73+
for (i = heap->nr / 2 - 1; i >= 0; i--)
7474
min_heapify(heap, i, func);
7575
}
7676

0 commit comments

Comments
 (0)