Skip to content

Refine simplefs_sb_info to align with cacheline #71

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

Merged
merged 1 commit into from
Apr 14, 2025

Conversation

RoyWFHuang
Copy link
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
2 checks passed
@jserv
Copy link
Collaborator

jserv commented Apr 14, 2025

Thank @RoyWFHuang for contributing!

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