From 01bf2b9f523d3bcddf74cac6af4ac5c36ce75550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 29 Apr 2026 10:54:43 +0200 Subject: [PATCH 1/3] sd-varlink: drop pointless bitfield As is often the case, in this case because of alignment, we are actually not saving any space. With the bitfield we are using one bit of the 8 bytes allocated, and without the bitfield we are using 8 bits of that. But we're paying a price in generated code, at every access site to the field: $ diff <(objdump -S build/libsystemd.so.old) <(objdump -S build/libsystemd.so.new) ... v->protocol_upgrade = false; - fa2d2: 48 8b 45 a8 mov -0x58(%rbp),%rax - fa2d6: 0f b6 90 90 01 00 00 movzbl 0x190(%rax),%edx - fa2dd: 83 e2 fe and $0xfffffffe,%edx - fa2e0: 88 90 90 01 00 00 mov %dl,0x190(%rax) + fa2a9: 48 8b 45 a8 mov -0x58(%rbp),%rax + fa2ad: c6 80 90 01 00 00 00 movb $0x0,0x190(%rax) --- src/libsystemd/sd-varlink/varlink-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd/sd-varlink/varlink-internal.h b/src/libsystemd/sd-varlink/varlink-internal.h index 8087c2c432..ff359852f4 100644 --- a/src/libsystemd/sd-varlink/varlink-internal.h +++ b/src/libsystemd/sd-varlink/varlink-internal.h @@ -107,7 +107,7 @@ typedef struct sd_varlink { * ensure the caller's contract is honored. The transport-layer "stop reading at the * next message boundary" behavior is governed independently by the JsonStream's * bounded_reads flag. */ - bool protocol_upgrade:1; + bool protocol_upgrade; void *userdata; From 242fca7516eeedb3157be47be83f608d56592a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 29 Apr 2026 11:00:00 +0200 Subject: [PATCH 2/3] sd-varlink: reduce size of varlink structs struct sd_varlink: - /* size: 448, cachelines: 7, members: 21 */ + /* size: 432, cachelines: 7, members: 21 */ struct sd_varlink_server: - /* size: 160, cachelines: 3, members: 21 */ + /* size: 152, cachelines: 3, members: 21 */ --- src/libsystemd/sd-varlink/varlink-internal.h | 28 +++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/libsystemd/sd-varlink/varlink-internal.h b/src/libsystemd/sd-varlink/varlink-internal.h index ff359852f4..32d6d5983a 100644 --- a/src/libsystemd/sd-varlink/varlink-internal.h +++ b/src/libsystemd/sd-varlink/varlink-internal.h @@ -74,9 +74,8 @@ typedef enum VarlinkState { typedef struct sd_varlink { unsigned n_ref; - sd_varlink_server *server; - VarlinkState state; + sd_varlink_server *server; /* Transport layer: input/output buffers, fd passing, output queue, read/write/parse * step functions, sd-event integration (input/output/time event sources, idle @@ -87,6 +86,13 @@ typedef struct sd_varlink { unsigned n_pending; + /* Per-call protocol-upgrade marker: set when the *current* method call carries the + * SD_VARLINK_METHOD_UPGRADE flag. Validated by sd_varlink_reply_and_upgrade() to + * ensure the caller's contract is honored. The transport-layer "stop reading at the + * next message boundary" behavior is governed independently by the JsonStream's + * bounded_reads flag. */ + bool protocol_upgrade; + sd_varlink_reply_t reply_callback; sd_json_variant *current; @@ -102,13 +108,6 @@ typedef struct sd_varlink { size_t n_previous_fds; char *sentinel; - /* Per-call protocol-upgrade marker: set when the *current* method call carries the - * SD_VARLINK_METHOD_UPGRADE flag. Validated by sd_varlink_reply_and_upgrade() to - * ensure the caller's contract is honored. The transport-layer "stop reading at the - * next message boundary" behavior is governed independently by the JsonStream's - * bounded_reads flag. */ - bool protocol_upgrade; - void *userdata; sd_event_source *quit_event_source; @@ -145,8 +144,12 @@ typedef struct sd_varlink_server { sd_event *event; int64_t event_priority; - unsigned n_connections; Hashmap *by_uid; /* UID_TO_PTR(uid) → UINT_TO_PTR(n_connections) */ + unsigned n_connections; + unsigned connections_max; + unsigned connections_per_uid_max; + + bool exit_on_idle; void *userdata; @@ -155,11 +158,6 @@ typedef struct sd_varlink_server { char *product; char *version; char *url; - - unsigned connections_max; - unsigned connections_per_uid_max; - - bool exit_on_idle; } sd_varlink_server; #define varlink_log_errno(v, error, fmt, ...) \ From d9e0883316d119fb484c677f27ba24f31baded72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 29 Apr 2026 11:20:06 +0200 Subject: [PATCH 3/3] sd-json: stop printing debug messages about extension fields The intent was good, but we now print two or three of those messages for each report metrics received on the wire. If the json object is extensible, then it's all good and we don't need to inundate the user with this trivial information. (And the message also sounds like something is wrong or unexpected, when it totally isn't.) ... (string):1:73: Unrecognized object field 'object', assuming extension. (string):1:89: Unrecognized object field 'value', assuming extension. json-stream: Received message: {"parameters":{"name":"io.systemd.Network.CarrierState","object":"virbr0","value":"degraded-carrier"},"continues":true} (string):1:66: Unrecognized object field 'object', assuming extension. (string):1:83: Unrecognized object field 'value', assuming extension. json-stream: Received message: {"parameters":{"name":"io.systemd.Network.CarrierState","object":"lo","value":"carrier"},"continues":true} (string):1:66: Unrecognized object field 'object', assuming extension. (string):1:79: Unrecognized object field 'value', assuming extension. json-stream: Received message: {"parameters":{"name":"io.systemd.Network.CarrierState","object":"wlp0s20f3","value":"carrier"},"continues":true} (string):1:66: Unrecognized object field 'object', assuming extension. (string):1:86: Unrecognized object field 'value', assuming extension. ... --- src/libsystemd/sd-json/sd-json.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libsystemd/sd-json/sd-json.c b/src/libsystemd/sd-json/sd-json.c index 4c541275c4..fbc2e55d23 100644 --- a/src/libsystemd/sd-json/sd-json.c +++ b/src/libsystemd/sd-json/sd-json.c @@ -5294,10 +5294,8 @@ _public_ int sd_json_dispatch_full( done++; } else { - if (flags & SD_JSON_ALLOW_EXTENSIONS) { - json_log(value, flags|SD_JSON_DEBUG, 0, "Unrecognized object field '%s', assuming extension.", sd_json_variant_string(key)); + if (flags & SD_JSON_ALLOW_EXTENSIONS) continue; - } json_log(value, flags, 0, "Unexpected object field '%s'.", sd_json_variant_string(key)); if (flags & SD_JSON_PERMISSIVE)