[PATCH 1/5] nvmet: Reorder fields in 'struct nvmet_sq'

From: Christophe JAILLET
Date: Mon May 01 2023 - 08:41:40 EST


Group some variables based on their sizes to reduce holes.
On x86_64, this shrinks the size of 'struct nvmet_sq' from 472 to 464
bytes when CONFIG_NVME_TARGET_AUTH is defined.

This structure is embedded into some other structures, so it helps reducing
their sizes as well.

Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
Using pahole

Before:
======
struct nvmet_sq {
struct nvmet_ctrl * ctrl; /* 0 8 */
struct percpu_ref ref; /* 8 16 */
u16 qid; /* 24 2 */
u16 size; /* 26 2 */
u32 sqhd; /* 28 4 */
bool sqhd_disabled; /* 32 1 */

/* XXX 7 bytes hole, try to pack */

struct delayed_work auth_expired_work; /* 40 184 */

/* XXX last struct has 4 bytes of padding */

/* --- cacheline 3 boundary (192 bytes) was 32 bytes ago --- */
bool authenticated; /* 224 1 */

/* XXX 1 byte hole, try to pack */

u16 dhchap_tid; /* 226 2 */
u16 dhchap_status; /* 228 2 */

/* XXX 2 bytes hole, try to pack */

int dhchap_step; /* 232 4 */

/* XXX 4 bytes hole, try to pack */

u8 * dhchap_c1; /* 240 8 */
u8 * dhchap_c2; /* 248 8 */
/* --- cacheline 4 boundary (256 bytes) --- */
u32 dhchap_s1; /* 256 4 */
u32 dhchap_s2; /* 260 4 */
u8 * dhchap_skey; /* 264 8 */
int dhchap_skey_len; /* 272 4 */

/* XXX 4 bytes hole, try to pack */

struct completion free_done; /* 280 96 */
/* --- cacheline 5 boundary (320 bytes) was 56 bytes ago --- */
struct completion confirm_done; /* 376 96 */

/* size: 472, cachelines: 8, members: 19 */
/* sum members: 454, holes: 5, sum holes: 18 */
/* paddings: 1, sum paddings: 4 */
/* last cacheline: 24 bytes */
};

After:
=====
struct nvmet_sq {
struct nvmet_ctrl * ctrl; /* 0 8 */
struct percpu_ref ref; /* 8 16 */
u16 qid; /* 24 2 */
u16 size; /* 26 2 */
u32 sqhd; /* 28 4 */
bool sqhd_disabled; /* 32 1 */
bool authenticated; /* 33 1 */

/* XXX 6 bytes hole, try to pack */

struct delayed_work auth_expired_work; /* 40 184 */

/* XXX last struct has 4 bytes of padding */

/* --- cacheline 3 boundary (192 bytes) was 32 bytes ago --- */
u16 dhchap_tid; /* 224 2 */
u16 dhchap_status; /* 226 2 */
int dhchap_step; /* 228 4 */
u8 * dhchap_c1; /* 232 8 */
u8 * dhchap_c2; /* 240 8 */
u32 dhchap_s1; /* 248 4 */
u32 dhchap_s2; /* 252 4 */
/* --- cacheline 4 boundary (256 bytes) --- */
u8 * dhchap_skey; /* 256 8 */
int dhchap_skey_len; /* 264 4 */

/* XXX 4 bytes hole, try to pack */

struct completion free_done; /* 272 96 */
/* --- cacheline 5 boundary (320 bytes) was 48 bytes ago --- */
struct completion confirm_done; /* 368 96 */

/* size: 464, cachelines: 8, members: 19 */
/* sum members: 454, holes: 2, sum holes: 10 */
/* paddings: 1, sum paddings: 4 */
/* last cacheline: 16 bytes */
};
---
drivers/nvme/target/nvmet.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index c50146085fb5..8cfd60f3b564 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -109,8 +109,8 @@ struct nvmet_sq {
u32 sqhd;
bool sqhd_disabled;
#ifdef CONFIG_NVME_TARGET_AUTH
- struct delayed_work auth_expired_work;
bool authenticated;
+ struct delayed_work auth_expired_work;
u16 dhchap_tid;
u16 dhchap_status;
int dhchap_step;
--
2.34.1