[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZxSR50u0qLYPUeH+@visitorckw-System-Product-Name>
Date: Sun, 20 Oct 2024 13:15:19 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: colyli@...e.de, kent.overstreet@...ux.dev, msakai@...hat.com,
corbet@....net, mingo@...hat.com, acme@...nel.org,
namhyung@...nel.org, akpm@...ux-foundation.org,
mark.rutland@....com, alexander.shishkin@...ux.intel.com,
jolsa@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
kan.liang@...ux.intel.com, jserv@...s.ncku.edu.tw,
linux-kernel@...r.kernel.org, linux-bcache@...r.kernel.org,
dm-devel@...ts.linux.dev, linux-bcachefs@...r.kernel.org,
linux-perf-users@...r.kernel.org, linux-doc@...r.kernel.org
Subject: Re: [PATCH 1/3] lib/min_heap: Introduce non-inline versions of min
heap API functions
On Mon, Oct 14, 2024 at 10:13:58AM +0200, Peter Zijlstra wrote:
> On Mon, Oct 14, 2024 at 02:47:01AM +0800, Kuan-Wei Chiu wrote:
> > All current min heap API functions are marked with '__always_inline'.
> > However, as the number of users increases, inlining these functions
> > everywhere leads to a significant increase in kernel size.
> >
> > In performance-critical paths, such as when perf events are enabled and
> > min heap functions are called on every context switch, it is important
> > to retain the inline versions for optimal performance. To balance this,
> > the original inline functions are kept, and additional non-inline
> > versions of the functions have been added in lib/min_heap.c.
>
> The reason it is all __always_inline is because then the whole
> min_heap_callbacks thing can be constant propagated and the func->less()
> etc calls become direct calls.
>
> Doing out of line for this stuff, makes them indirect calls, and
> indirect calls are super retarded expensive ever since spectre. But also
> things like kCFI add significant cost to indirect calls.
>
> Something that would be a trivial subtract instruction becomes this
> giant mess of an indirect function call.
>
> Given the whole min_heap thing is basically a ton of less() and swp()
> calls, I really don't think this trade off makes any kind of sense.
BTW, Regarding the concerns about the efficiency impact of indirect
function calls, should we also consider converting some calls to
sort()/list_sort() into inline function calls? The comparison functions
they require could lead to a significant number of indirect calls.
For instance, the comparison function passed to list_sort() in ubifs
calls cond_resched(), which implies that the linked list could be
lengthy, further increasing the likelihood of numerous indirect calls.
Regards,
Kuan-Wei
Powered by blists - more mailing lists