From: Zbigniew Jędrzejewski-Szmek Date: Sun, 8 Jun 2025 11:41:31 +0000 (+0200) Subject: sd-event: make some more bools non-bitfield X-Git-Tag: v258-rc1~186^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9ea39689f5e0f24ba0882d268bb9808ab27541a;p=thirdparty%2Fsystemd.git sd-event: make some more bools non-bitfield In sd_event_source.child, we have 5 bools. If we make them each take one byte, the structure size increases. So let's do that for the three of them, and leave the other two (less frequently used) squished into the last byte. This allows more efficient code to be generated, without changing the size of the struct: $ diff -u <(objdump -S build/src/shared/libsystemd-shared-258.so.0|awk '/^static void source_io_unregister/,/^\}/') \ <(objdump -S build/src/shared/libsystemd-shared-258.so|awk '/^static void source_io_unregister/,/^\}/') s->io.registered = false; - 34d46f: 48 8b 45 d8 mov -0x28(%rbp),%rax - 34d473: 0f b6 90 a4 00 00 00 movzbl 0xa4(%rax),%edx - 34d47a: 83 e2 fe and $0xfffffffe,%edx - 34d47d: 88 90 a4 00 00 00 mov %dl,0xa4(%rax) - 34d483: eb 04 jmp 34d489 + 34bffe: 48 8b 45 d8 mov -0x28(%rbp),%rax + 34c002: c6 80 a4 00 00 00 00 movb $0x0,0xa4(%rax) + 34c009: eb 04 jmp 34c00f return; --- diff --git a/src/libsystemd/sd-event/event-source.h b/src/libsystemd/sd-event/event-source.h index 385779df2c6..a7c1807cd45 100644 --- a/src/libsystemd/sd-event/event-source.h +++ b/src/libsystemd/sd-event/event-source.h @@ -106,11 +106,16 @@ struct sd_event_source { pid_t pid; int options; int pidfd; - bool registered:1; /* whether the pidfd is registered in the epoll */ + /* We have five bools, and we want to fit them into 4 bytes so the whole struct + * remains 32 bytes. Thus, use bitfields for two of them and single bytes for the + * other three. */ + bool registered; /* whether the pidfd is registered in the epoll */ bool pidfd_owned:1; /* close pidfd when event source is freed */ bool process_owned:1; /* kill+reap process when event source is freed */ - bool exited:1; /* true if process exited (i.e. if there's value in SIGKILLing it if we want to get rid of it) */ - bool waited:1; /* true if process was waited for (i.e. if there's value in waitid(P_PID)'ing it if we want to get rid of it) */ + bool exited; /* true if process exited (i.e. if there's value in SIGKILLing it if + * we want to get rid of it) */ + bool waited; /* true if process was waited for (i.e. if there's value in + * waitid(P_PID)'ing it if we want to get rid of it) */ } child; struct { sd_event_handler_t callback;