* Improving mutex_init() optimisation for !lockdep
@ 2025-06-23 9:28 Sebastian Andrzej Siewior
2025-06-23 10:42 ` Peter Zijlstra
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-06-23 9:28 UTC (permalink / raw)
To: linux-kernel
Cc: Boqun Feng, Ingo Molnar, Peter Zijlstra, Waiman Long, Will Deacon
Hi,
while looking at the assembly of something else I stumbled upon
code that originated from mutex_int() on a !LOCKDEP kernel.
We have this macro:
| #define mutex_init(mutex) \
| do { \
| static struct lock_class_key __key; \
| \
| __mutex_init((mutex), #mutex, &__key); \
| } while (0)
and the compiler computed an offset for __key and an offset and storage
for #mutex. These two arguments aren't used by __mutex_init() but the
compiler can't know that.
If I remove these two arguments on a x86-64 defconfig, I see:
| text data bss dec hex filename
| 29753523 8033942 1306232 39093697 25485c1 vmlinux.before
| 29748880 8021654 1306168 39076702 254435e vmlinux.after
| 4643 12288 64 16995 0x4263 diff in bytes
That is 4KiB in text and 12KiB in data. I don't know why we lost 64
bytes in BSS.
Any objections in redoing this to save some bytes?
Sebastian
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Improving mutex_init() optimisation for !lockdep
2025-06-23 9:28 Improving mutex_init() optimisation for !lockdep Sebastian Andrzej Siewior
@ 2025-06-23 10:42 ` Peter Zijlstra
0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2025-06-23 10:42 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-kernel, Boqun Feng, Ingo Molnar, Waiman Long, Will Deacon
On Mon, Jun 23, 2025 at 11:28:32AM +0200, Sebastian Andrzej Siewior wrote:
> Hi,
>
> while looking at the assembly of something else I stumbled upon
> code that originated from mutex_int() on a !LOCKDEP kernel.
> We have this macro:
>
> | #define mutex_init(mutex) \
> | do { \
> | static struct lock_class_key __key; \
> | \
> | __mutex_init((mutex), #mutex, &__key); \
> | } while (0)
>
> and the compiler computed an offset for __key and an offset and storage
> for #mutex. These two arguments aren't used by __mutex_init() but the
> compiler can't know that.
> If I remove these two arguments on a x86-64 defconfig, I see:
>
> | text data bss dec hex filename
> | 29753523 8033942 1306232 39093697 25485c1 vmlinux.before
> | 29748880 8021654 1306168 39076702 254435e vmlinux.after
> | 4643 12288 64 16995 0x4263 diff in bytes
>
> That is 4KiB in text and 12KiB in data. I don't know why we lost 64
> bytes in BSS.
>
> Any objections in redoing this to save some bytes?
Nope, easy win :-)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-23 10:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-23 9:28 Improving mutex_init() optimisation for !lockdep Sebastian Andrzej Siewior
2025-06-23 10:42 ` Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®