Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: Reorg struct route_entry to have important bits first #15309

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

donaldsharp
Copy link
Member

The struct route_entry had items that were almost never used at the front of the data structure resulting in items that would be loaded first into memory that were never used. Let's reorg a tiny bit and put all the frequently used items in the first cache line. I'm sure people will notice .000000001 speedup

new layout:

sharpd@eva /w/h/s/frr1 (reorg_route_entry)> /home/sharpd/pahole/build/pahole --reorganize --show_reorg_steps -C route_entry zebra/.libs/zebra struct route_entry {
struct re_list_item next; /* 0 8 /
struct nhg_hash_entry * nhe; /
8 8 /
uint32_t nhe_id; /
16 4 /
uint32_t nhe_installed_id; /
20 4 /
int type; /
24 4 /
vrf_id_t vrf_id; /
28 4 /
uint32_t table; /
32 4 /
uint32_t metric; /
36 4 /
uint32_t mtu; /
40 4 /
uint32_t nexthop_mtu; /
44 4 /
uint32_t flags; /
48 4 /
uint32_t status; /
52 4 /
uint32_t dplane_sequence; /
56 4 /
uint16_t instance; /
60 2 /
uint8_t distance; /
62 1 */

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

/* --- cacheline 1 boundary (64 bytes) --- */
route_tag_t                tag;                  /*    64     4 */

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

time_t                     uptime;               /*    72     8 */
struct re_opaque *         opaque;               /*    80     8 */
struct nexthop_group       fib_ng;               /*    88    32 */
struct nexthop_group       fib_backup_ng;        /*   120    32 */

/* size: 152, cachelines: 3, members: 20 */
/* sum members: 147, holes: 2, sum holes: 5 */
/* last cacheline: 24 bytes */

};

The `struct route_entry` had items that were almost never used at
the front of the data structure resulting in items that would be
loaded first into memory that were never used.  Let's reorg a
tiny bit and put all the frequently used items in the first cache
line.  I'm sure people will notice .000000001 speedup

new layout:

sharpd@eva /w/h/s/frr1 (reorg_route_entry)> /home/sharpd/pahole/build/pahole --reorganize --show_reorg_steps -C route_entry zebra/.libs/zebra
struct route_entry {
	struct re_list_item        next;                 /*     0     8 */
	struct nhg_hash_entry *    nhe;                  /*     8     8 */
	uint32_t                   nhe_id;               /*    16     4 */
	uint32_t                   nhe_installed_id;     /*    20     4 */
	int                        type;                 /*    24     4 */
	vrf_id_t                   vrf_id;               /*    28     4 */
	uint32_t                   table;                /*    32     4 */
	uint32_t                   metric;               /*    36     4 */
	uint32_t                   mtu;                  /*    40     4 */
	uint32_t                   nexthop_mtu;          /*    44     4 */
	uint32_t                   flags;                /*    48     4 */
	uint32_t                   status;               /*    52     4 */
	uint32_t                   dplane_sequence;      /*    56     4 */
	uint16_t                   instance;             /*    60     2 */
	uint8_t                    distance;             /*    62     1 */

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

	/* --- cacheline 1 boundary (64 bytes) --- */
	route_tag_t                tag;                  /*    64     4 */

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

	time_t                     uptime;               /*    72     8 */
	struct re_opaque *         opaque;               /*    80     8 */
	struct nexthop_group       fib_ng;               /*    88    32 */
	struct nexthop_group       fib_backup_ng;        /*   120    32 */

	/* size: 152, cachelines: 3, members: 20 */
	/* sum members: 147, holes: 2, sum holes: 5 */
	/* last cacheline: 24 bytes */
};

Signed-off-by: Donald Sharp <[email protected]>
@frrbot frrbot bot added the zebra label Feb 5, 2024
@ton31337 ton31337 added this to the 10.0 milestone Feb 5, 2024
@ton31337 ton31337 merged commit 3204cc1 into FRRouting:master Feb 6, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants