From: Colin Vidal Date: Fri, 5 Dec 2025 21:02:36 +0000 (+0100) Subject: shrunk cfgobj down from 48 bytes to 40 bytes X-Git-Tag: v9.21.17~57^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c82d15bc2c40316eba032eca5941254f6f050e0;p=thirdparty%2Fbind9.git shrunk cfgobj down from 48 bytes to 40 bytes Follow-up of 38ce2906 as the size of the `cfg_obj_t` can actually goes down to 40 bytes "for free", by using bitfields to only use 31 bits for the `line` field, so the remaining bit can be use to hold the `cloned` state without paying the extra 8 bytes padding. --- diff --git a/lib/isccfg/include/isccfg/grammar.h b/lib/isccfg/include/isccfg/grammar.h index 6d1ef1e503c..9ad371b7e06 100644 --- a/lib/isccfg/include/isccfg/grammar.h +++ b/lib/isccfg/include/isccfg/grammar.h @@ -206,9 +206,20 @@ struct cfg_obj { * These two 4 byte fields are contiguous to avoid an extra * padding of 4 bytes each, avoiding an extra 8 bytes in the * struct. + * + * `line` is 31 bits long (~2,000,000,000 is likely enough lines in a + * named config) so the `cloned` boolean fit in the extra bit, and won't + * take extra 8 bits because of padding. */ unsigned int magic; - unsigned int line; + unsigned int line : 31; + + /*% + * Indicates that an object was cloned from the defaults + * or otherwise generated during the configuration merge + * process. + */ + bool cloned : 1; isc_refcount_t references; cfg_obj_t *file; /*%< separate string with its own refcount */ @@ -226,13 +237,6 @@ struct cfg_obj { cfg_netprefix_t *netprefix; isccfg_duration_t *duration; } value; - - /*% - * Indicates that an object was cloned from the defaults - * or otherwise generated during the configuration merge - * process. - */ - bool cloned; }; /*% A list element. */ diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index e7980be9cd3..83722cb858f 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -73,8 +73,8 @@ * can take a significant amount of memory. This assert ensures that we * won't increase its size by mistake without getting a warning. */ -static_assert(sizeof(struct cfg_obj) <= 48, - "sizeof(cfg_obj_t) must be 48 bytes"); +static_assert(sizeof(struct cfg_obj) <= 40, + "sizeof(cfg_obj_t) must be 40 bytes"); /* Shorthand */ #define CAT CFG_LOGCATEGORY_CONFIG