One cautionary thing with C programming: the cost of macro expansion
Posted by jpluimers on 2024/10/03
The result C macros having become more lenient on the types they expect, is that they can become very large expansions. This not only causes long expanded code lines, but also
This shows you some examples:
[Wayback/Archive] Lorenzo Stoakes on social.kernel.org: For those interested in the ‘combinatorial explosion of min()/max() macro’ thing slowing down kernel builds, witness the horrors :))
[Wayback/Archive] Re: [PATCH 0/7] minmax: reduce compilation time – Linus Torvalds
โฆ
So it _looks_ like "pageblock_order", and it *acts* like a simple compile-time constant, but our complex type-checking min() macro ends up making it horrible.โฆ
so we have a single expansion that is 253kB in size. And it comes from this:โฆ
so once again it's "pageblock_order", it's just that it's now mixed in with "max()".โฆ
which looks very tame indeed, but it turns out that "bio_for_each_segment()" expands to 82kB of code.โฆ
The solution is relatively simple: introduce macros that are less relaxed about the parameters and be cautions using them. That’s what the above PATCH actually does,
--jeroen






Leave a comment