All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: colyli@suse.de, kent.overstreet@linux.dev, msakai@redhat.com,
	peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org, bfoster@redhat.com, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com,
	bagasdotme@gmail.com, jserv@ccns.ncku.edu.tw,
	linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
	dm-devel@lists.linux.dev, linux-bcachefs@vger.kernel.org,
	linux-perf-users@vger.kernel.org
Subject: Re: [RESEND PATCH v5 04/16] lib min_heap: Add type safe interface
Date: Wed, 22 May 2024 16:10:48 -0700	[thread overview]
Message-ID: <20240522161048.8d8bbc7b153b4ecd92c50666@linux-foundation.org> (raw)
In-Reply-To: <20240514084724.557100-5-visitorckw@gmail.com>

On Tue, 14 May 2024 16:47:12 +0800 Kuan-Wei Chiu <visitorckw@gmail.com> wrote:

> Implement a type-safe interface for min_heap using strong type
> pointers instead of void * in the data field. This change includes
> adding small macro wrappers around functions, enabling the use of
> __minheap_cast and __minheap_obj_size macros for type casting and
> obtaining element size. This implementation removes the necessity of
> passing element size in min_heap_callbacks. Additionally, introduce the
> MIN_HEAP_PREALLOCATED macro for preallocating some elements.

I guess it's a nice change, although it's unclear how valuable all this
is.  Being able to remove the local implementations in bcache and
bcachefs is good.

> --- a/drivers/md/dm-vdo/repair.c
> +++ b/drivers/md/dm-vdo/repair.c
> @@ -51,6 +51,8 @@ struct recovery_point {
>  	bool increment_applied;
>  };
>  
> +MIN_HEAP(struct numbered_block_mapping, replay_heap);
>
> ...
>
> -struct min_heap {
> -	void *data;
> -	int nr;
> -	int size;
> -};
> +#define MIN_HEAP_PREALLOCATED(_type, _name, _nr)	\
> +struct _name {	\
> +	int nr;	\
> +	int size;	\
> +	_type *data;	\
> +	_type preallocated[_nr];	\
> +}

I think that the MIN_HEAP() macro would be better named
DEFINE_MIN_HEAP().  There's a lot of precedent for this and it's
unclear whether "MIN_HEAP" actually implements storage.  I looked at
the repair.c addition and thought "hm, shouldn't that be static"!

>  /* Sift the element at pos down the heap. */
>  static __always_inline
> -void min_heapify(struct min_heap *heap, int pos,
> +void __min_heapify(min_heap_char *heap, int pos, size_t elem_size,
>  		const struct min_heap_callbacks *func)
>  {

It's a separate project, but min_heap.h has some crazily huge inlined
functions.  I expect we'd have a smaller and faster kernel if those
were moved into a new lib/min_heap.c.


  reply	other threads:[~2024-05-22 23:10 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14  8:47 [RESEND PATCH v5 00/16] treewide: Refactor heap related implementation Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 01/16] perf/core: Fix several typos Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 02/16] bcache: Fix typo Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 03/16] bcachefs: " Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 04/16] lib min_heap: Add type safe interface Kuan-Wei Chiu
2024-05-22 23:10   ` Andrew Morton [this message]
2024-05-22 23:33     ` Kent Overstreet
2024-05-23  3:51       ` Ian Rogers
2024-05-23 15:35     ` Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 05/16] lib min_heap: Add min_heap_init() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 06/16] lib min_heap: Add min_heap_peek() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 07/16] lib min_heap: Add min_heap_full() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 08/16] lib min_heap: Add args for min_heap_callbacks Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 09/16] lib min_heap: Add min_heap_sift_up() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 10/16] lib min_heap: Add min_heap_del() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 11/16] lib min_heap: Update min_heap_push() and min_heap_pop() to return bool values Kuan-Wei Chiu
2024-05-15  8:37   ` Peter Zijlstra
2024-05-15  9:25     ` Kuan-Wei Chiu
2024-05-19 23:03     ` Kent Overstreet
2024-05-14  8:47 ` [RESEND PATCH v5 12/16] lib min_heap: Rename min_heapify() to min_heap_sift_down() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 13/16] lib min_heap: Update min_heap_push() to use min_heap_sift_up() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 14/16] lib/test_min_heap: Add test for heap_del() Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 15/16] bcache: Remove heap-related macros and switch to generic min_heap Kuan-Wei Chiu
2024-05-14  8:47 ` [RESEND PATCH v5 16/16] bcachefs: " Kuan-Wei Chiu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240522161048.8d8bbc7b153b4ecd92c50666@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bagasdotme@gmail.com \
    --cc=bfoster@redhat.com \
    --cc=colyli@suse.de \
    --cc=dm-devel@lists.linux.dev \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=jserv@ccns.ncku.edu.tw \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=msakai@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=visitorckw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.