Skip to content

Refine simplefs_sb_info to align with cacheline - #71

Merged
jserv merged 1 commit into
sysprog21:masterfrom
RoyWFHuang:Feature/Refine_Src
Apr 14, 2025
Merged

jserv merged 1 commit into
sysprog21:masterfrom
RoyWFHuang:Feature/Refine_Src

Conversation

@RoyWFHuang

Copy link
Copy Markdown
Collaborator

The ifree_bitmap and ibfree_bitmap fields are frequently used together. To enhance performance, we reorganized the structure layout to align with 64-byte cache lines.

Using pahole to detect

struct simplefs_sb_info {
	uint32_t                   magic;                /*     0     4 */
	uint32_t                   nr_blocks;            /*     4     4 */
	uint32_t                   nr_inodes;            /*     8     4 */
	uint32_t                   nr_istore_blocks;     /*    12     4 */
	uint32_t                   nr_ifree_blocks;      /*    16     4 */
	uint32_t                   nr_bfree_blocks;      /*    20     4 */
	uint32_t                   nr_free_inodes;       /*    24     4 */
	uint32_t                   nr_free_blocks;       /*    28     4 */
	journal_t *                journal;              /*    32     8 */
	struct block_device *      s_journal_bdev;       /*    40     8 */
	struct file *              s_journal_bdev_file;  /*    48     8 */
	long unsigned int *        ifree_bitmap;         /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	long unsigned int *        bfree_bitmap;         /*    64     8 */

	/* size: 72, cachelines: 2, members: 13 */
	/* last cacheline: 8 bytes */
};

the ifree and bfree are in different cache line so I move it.
After modification

struct simplefs_sb_info {
	uint32_t                   magic;                /*     0     4 */
	uint32_t                   nr_blocks;            /*     4     4 */
	uint32_t                   nr_inodes;            /*     8     4 */
	uint32_t                   nr_istore_blocks;     /*    12     4 */
	uint32_t                   nr_ifree_blocks;      /*    16     4 */
	uint32_t                   nr_bfree_blocks;      /*    20     4 */
	uint32_t                   nr_free_inodes;       /*    24     4 */
	uint32_t                   nr_free_blocks;       /*    28     4 */
	long unsigned int *        ifree_bitmap;         /*    32     8 */
	long unsigned int *        bfree_bitmap;         /*    40     8 */
	journal_t *                journal;              /*    48     8 */
	struct block_device *      s_journal_bdev;       /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	struct file *              s_journal_bdev_file;  /*    64     8 */

	/* size: 72, cachelines: 2, members: 13 */
	/* last cacheline: 8 bytes */
};

The ifree_bitmap and ibfree_bitmap fields are frequently used together.
To enhance performance, we reorganized the structure layout to align
with 64-byte cache lines.
@jserv
jserv merged commit 68a6cb7 into sysprog21:master Apr 14, 2025
@jserv

jserv commented Apr 14, 2025

Copy link
Copy Markdown
Collaborator

Thank @RoyWFHuang for contributing!

@RoyWFHuang
RoyWFHuang deleted the Feature/Refine_Src branch May 24, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants