From 0a35e7f6be4c1b21221f51f696c1952cc3379977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 19 Feb 2024 12:02:55 +0100 Subject: [PATCH 1/5] core/kmod-setup: drop another pointless bitfield annotation We have two bools followed by a func pointer, which is aligned to e.g. 8 bytes, so whether the two bools take one bit, one byte, or even a full word, makes no difference in storage size. But the code generated to service a bitfield is more complicated. Also switch to FOREACH_ARRAY(). --- src/core/kmod-setup.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c index b8e3f7aadd5..f4801318dea 100644 --- a/src/core/kmod-setup.c +++ b/src/core/kmod-setup.c @@ -113,12 +113,11 @@ static bool in_qemu(void) { int kmod_setup(void) { #if HAVE_KMOD - static const struct { const char *module; const char *path; - bool warn_if_unavailable:1; - bool warn_if_module:1; + bool warn_if_unavailable; + bool warn_if_module; bool (*condition_fn)(void); } kmod_table[] = { /* This one we need to load explicitly, since auto-loading on use doesn't work @@ -166,23 +165,23 @@ int kmod_setup(void) { { "tpm", "/sys/class/tpmrm", false, false, efi_has_tpm2 }, #endif }; - _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL; - unsigned i; if (have_effective_cap(CAP_SYS_MODULE) <= 0) return 0; - for (i = 0; i < ELEMENTSOF(kmod_table); i++) { - if (kmod_table[i].path && access(kmod_table[i].path, F_OK) >= 0) + _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL; + + FOREACH_ARRAY(kmod, kmod_table, ELEMENTSOF(kmod_table)) { + if (kmod->path && access(kmod->path, F_OK) >= 0) continue; - if (kmod_table[i].condition_fn && !kmod_table[i].condition_fn()) + if (kmod->condition_fn && !kmod->condition_fn()) continue; - if (kmod_table[i].warn_if_module) + if (kmod->warn_if_module) log_debug("Your kernel apparently lacks built-in %s support. Might be " "a good idea to compile it in. We'll now try to work around " - "this by loading the module...", kmod_table[i].module); + "this by loading the module...", kmod->module); if (!ctx) { ctx = kmod_new(NULL, NULL); @@ -193,7 +192,7 @@ int kmod_setup(void) { kmod_load_resources(ctx); } - (void) module_load_and_warn(ctx, kmod_table[i].module, kmod_table[i].warn_if_unavailable); + (void) module_load_and_warn(ctx, kmod->module, kmod->warn_if_unavailable); } #endif From 6e2be1d97a5798fe38d14ec5658c22551967a45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 19 Feb 2024 12:10:34 +0100 Subject: [PATCH 2/5] sysupdate: drop pointless bitfields Again, even without considering how many copies of the struct there can be, this bitfield is useless because of alignment. --- src/sysupdate/sysupdate-partition.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sysupdate/sysupdate-partition.h b/src/sysupdate/sysupdate-partition.h index 672eb93e905..094d8e0ca49 100644 --- a/src/sysupdate/sysupdate-partition.h +++ b/src/sysupdate/sysupdate-partition.h @@ -29,9 +29,9 @@ struct PartitionInfo { sd_id128_t type, uuid; char *label; char *device; /* Note that this might point to some non-existing path in case we operate on a loopback file */ - bool no_auto:1; - bool read_only:1; - bool growfs:1; + bool no_auto; + bool read_only; + bool growfs; }; #define PARTITION_INFO_NULL \ From 611a6d15cbcc98751326bcfffd82da09f996b55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 19 Feb 2024 12:11:19 +0100 Subject: [PATCH 3/5] systemctl: drop pointless bitfield --- src/systemctl/systemctl-show.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 5bb8ad9fa07..e81afee058f 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -204,7 +204,7 @@ typedef struct UnitStatusInfo { pid_t control_pid; const char *status_text; const char *pid_file; - bool running:1; + bool running; int status_errno; uint32_t fd_store_max; From d53017292edcad2dfe94340320fdd91a80f56cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 19 Feb 2024 12:20:20 +0100 Subject: [PATCH 4/5] timesyncd: reorder structs instead of useless bitfields Because of alignment, those bitfields were not doing anything useful, and were causing the generated code to be more complicated. But in this case, at least potentially there might be a number of copies of those structs (if we have a bunch of time servers configured), so let's actually implement the intended space savings by reording the fields to reduce the size of holes. --- src/timesync/timesyncd-manager.h | 3 +-- src/timesync/timesyncd-server.h | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h index f4447874897..027ec52dac7 100644 --- a/src/timesync/timesyncd-manager.h +++ b/src/timesync/timesyncd-manager.h @@ -45,10 +45,9 @@ struct Manager { LIST_HEAD(ServerName, runtime_servers); LIST_HEAD(ServerName, fallback_servers); - bool have_fallbacks:1; - RateLimit ratelimit; bool exhausted_servers; + bool have_fallbacks; /* network */ sd_event_source *network_event_source; diff --git a/src/timesync/timesyncd-server.h b/src/timesync/timesyncd-server.h index e22917aa129..a4b56377312 100644 --- a/src/timesync/timesyncd-server.h +++ b/src/timesync/timesyncd-server.h @@ -30,11 +30,11 @@ struct ServerAddress { struct ServerName { Manager *manager; + bool marked; + ServerType type; char *string; - bool marked:1; - LIST_HEAD(ServerAddress, addresses); LIST_FIELDS(ServerName, names); }; From 6169bb19a9daaab2652af2ac20a771c74c89b0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 19 Feb 2024 12:25:29 +0100 Subject: [PATCH 5/5] logind: drop bitfield annotations As in other cases, this is simpler but better. pahole: - /* size: 336, cachelines: 6, members: 50 */ - /* sum members: 316, holes: 4, sum holes: 19 */ - /* sum bitfield members: 4 bits, bit holes: 1, sum bit holes: 4 bits */ - /* last cacheline: 16 bytes */ + /* size: 328, cachelines: 6, members: 50 */ + /* sum members: 320, holes: 3, sum holes: 8 */ + /* last cacheline: 8 bytes */ --- src/login/logind-session.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/login/logind-session.h b/src/login/logind-session.h index b36d4221411..f344fb6a61d 100644 --- a/src/login/logind-session.h +++ b/src/login/logind-session.h @@ -135,16 +135,16 @@ struct Session { sd_event_source *fifo_event_source; sd_event_source *leader_pidfd_event_source; - bool idle_hint; - dual_timestamp idle_hint_timestamp; + bool in_gc_queue; + bool started; + bool stopping; + + bool was_active; bool locked_hint; - bool in_gc_queue:1; - bool started:1; - bool stopping:1; - - bool was_active:1; + bool idle_hint; + dual_timestamp idle_hint_timestamp; sd_bus_message *create_message; /* The D-Bus message used to create the session, which we haven't responded to yet */ sd_bus_message *upgrade_message; /* The D-Bus message used to upgrade the session class user-incomplete → user, which we haven't responded to yet */