regmap: Reorder fields in 'struct regmap_bus' to save some memory
Commit Message
Group some bool variables to reduce hole and avoid padding.
On x86_64, this shrinks the size from 136 to 128 bytes.
As an example:
$ size drivers/base/regmap/regmap-fsi.o (Before)
text data bss dec hex filename
4837 136 0 4973 136d drivers/base/regmap/regmap-fsi.o
$ size drivers/base/regmap/regmap-fsi.o (After)
text data bss dec hex filename
4701 136 0 4837 12e5 drivers/base/regmap/regmap-fsi.o
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole
Before:
======
struct regmap_bus {
bool fast_io; /* 0 1 */
/* XXX 7 bytes hole, try to pack */
regmap_hw_write write; /* 8 8 */
regmap_hw_gather_write gather_write; /* 16 8 */
regmap_hw_async_write async_write; /* 24 8 */
regmap_hw_reg_write reg_write; /* 32 8 */
regmap_hw_reg_noinc_write reg_noinc_write; /* 40 8 */
regmap_hw_reg_update_bits reg_update_bits; /* 48 8 */
regmap_hw_read read; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
regmap_hw_reg_read reg_read; /* 64 8 */
regmap_hw_reg_noinc_read reg_noinc_read; /* 72 8 */
regmap_hw_free_context free_context; /* 80 8 */
regmap_hw_async_alloc async_alloc; /* 88 8 */
u8 read_flag_mask; /* 96 1 */
/* XXX 3 bytes hole, try to pack */
enum regmap_endian reg_format_endian_default; /* 100 4 */
enum regmap_endian val_format_endian_default; /* 104 4 */
/* XXX 4 bytes hole, try to pack */
size_t max_raw_read; /* 112 8 */
size_t max_raw_write; /* 120 8 */
/* --- cacheline 2 boundary (128 bytes) --- */
bool free_on_exit; /* 128 1 */
/* size: 136, cachelines: 3, members: 18 */
/* sum members: 115, holes: 3, sum holes: 14 */
/* padding: 7 */
/* last cacheline: 8 bytes */
};
After:
=====
struct regmap_bus {
bool fast_io; /* 0 1 */
bool free_on_exit; /* 1 1 */
/* XXX 6 bytes hole, try to pack */
regmap_hw_write write; /* 8 8 */
regmap_hw_gather_write gather_write; /* 16 8 */
regmap_hw_async_write async_write; /* 24 8 */
regmap_hw_reg_write reg_write; /* 32 8 */
regmap_hw_reg_noinc_write reg_noinc_write; /* 40 8 */
regmap_hw_reg_update_bits reg_update_bits; /* 48 8 */
regmap_hw_read read; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
regmap_hw_reg_read reg_read; /* 64 8 */
regmap_hw_reg_noinc_read reg_noinc_read; /* 72 8 */
regmap_hw_free_context free_context; /* 80 8 */
regmap_hw_async_alloc async_alloc; /* 88 8 */
u8 read_flag_mask; /* 96 1 */
/* XXX 3 bytes hole, try to pack */
enum regmap_endian reg_format_endian_default; /* 100 4 */
enum regmap_endian val_format_endian_default; /* 104 4 */
/* XXX 4 bytes hole, try to pack */
size_t max_raw_read; /* 112 8 */
size_t max_raw_write; /* 120 8 */
/* size: 128, cachelines: 2, members: 18 */
/* sum members: 115, holes: 3, sum holes: 13 */
};
---
include/linux/regmap.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Tue, 14 Feb 2023 09:40:14 +0100, Christophe JAILLET wrote:
> Group some bool variables to reduce hole and avoid padding.
> On x86_64, this shrinks the size from 136 to 128 bytes.
>
> As an example:
>
> $ size drivers/base/regmap/regmap-fsi.o (Before)
> text data bss dec hex filename
> 4837 136 0 4973 136d drivers/base/regmap/regmap-fsi.o
>
> [...]
Applied to
broonie/regmap.git for-next
Thanks!
[1/1] regmap: Reorder fields in 'struct regmap_bus' to save some memory
commit: 7464145862d606cf9835f24080341a397cbc0669
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
On Tue, Feb 14, 2023 at 09:40:14AM +0100, Christophe JAILLET wrote:
> Group some bool variables to reduce hole and avoid padding.
> On x86_64, this shrinks the size from 136 to 128 bytes.
>
> As an example:
>
> $ size drivers/base/regmap/regmap-fsi.o (Before)
> text data bss dec hex filename
> 4837 136 0 4973 136d drivers/base/regmap/regmap-fsi.o
>
> $ size drivers/base/regmap/regmap-fsi.o (After)
> text data bss dec hex filename
> 4701 136 0 4837 12e5 drivers/base/regmap/regmap-fsi.o
FYI: we have scripts/bloat-o-meter for this.
@@ -520,6 +520,7 @@ typedef void (*regmap_hw_free_context)(void *context);
* to perform locking. This field is ignored if custom lock/unlock
* functions are used (see fields lock/unlock of
* struct regmap_config).
+ * @free_on_exit: kfree this on exit of regmap
* @write: Write operation.
* @gather_write: Write operation with split register/value, return -ENOTSUPP
* if not implemented on a given device.
@@ -548,10 +549,10 @@ typedef void (*regmap_hw_free_context)(void *context);
* DEFAULT, BIG is assumed.
* @max_raw_read: Max raw read size that can be used on the bus.
* @max_raw_write: Max raw write size that can be used on the bus.
- * @free_on_exit: kfree this on exit of regmap
*/
struct regmap_bus {
bool fast_io;
+ bool free_on_exit;
regmap_hw_write write;
regmap_hw_gather_write gather_write;
regmap_hw_async_write async_write;
@@ -568,7 +569,6 @@ struct regmap_bus {
enum regmap_endian val_format_endian_default;
size_t max_raw_read;
size_t max_raw_write;
- bool free_on_exit;
};
/*