From 26a42669645589badff46d2f93c47c2feedb42ec Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 5 Jan 2017 17:44:49 -0800 Subject: [PATCH] Set manifest keys to precise segment keys We had changed the manifest keys to fully cover the space around the segments in the hopes that it'd let item reading easily find negative cached regions around items. But that makes compaction think that segments intersect with items when they really don't. We'd much rather avoid unnecessary compaction by having the manifest entries precisely reflect the keys in the segment. Item reading can do more work at run time to find the bounds of the key space that are around the edges of the segments it works with. Signed-off-by: Zach Brown --- utils/src/mkfs.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/utils/src/mkfs.c b/utils/src/mkfs.c index 26560194..555e193c 100644 --- a/utils/src/mkfs.c +++ b/utils/src/mkfs.c @@ -90,6 +90,7 @@ static u64 calc_ring_blocks(u64 segs) static int write_new_fs(char *path, int fd) { struct scoutfs_super_block *super; + struct scoutfs_inode_key root_ikey; struct scoutfs_inode_key *ikey; struct scoutfs_inode *inode; struct scoutfs_segment_block *sblk; @@ -105,7 +106,6 @@ static int write_new_fs(char *path, int fd) u64 ring_blocks; u64 total_segs; u64 first_segno; - __u8 *type; int ret; u64 i; @@ -167,6 +167,9 @@ static int write_new_fs(char *path, int fd) sblk->seq = cpu_to_le64(1); sblk->nr_items = cpu_to_le32(1); + root_ikey.type = SCOUTFS_INODE_KEY; + root_ikey.ino = cpu_to_be64(SCOUTFS_ROOT_INO); + ikey = (void *)&sblk->items[1]; inode = (void *)(ikey + 1); @@ -177,8 +180,7 @@ static int write_new_fs(char *path, int fd) item.val_len = sizeof(struct scoutfs_inode); store_item(sblk, 0, &item); - ikey->type = SCOUTFS_INODE_KEY; - ikey->ino = cpu_to_be64(SCOUTFS_ROOT_INO); + *ikey = root_ikey; inode->nlink = cpu_to_le32(2); inode->mode = cpu_to_le32(0755 | 0040000); @@ -200,17 +202,19 @@ static int write_new_fs(char *path, int fd) node = ring; node->off = cpu_to_le64((char *)node - (char *)ring); node->gen = cpu_to_le64(1); - node->bytes = cpu_to_le16(sizeof(struct scoutfs_manifest_entry) + 1); + node->bytes = cpu_to_le16(sizeof(struct scoutfs_manifest_entry) + + (2 * sizeof(struct scoutfs_inode_key))); pseudo_random_bytes(&node->prio, sizeof(node->prio)); ment = (void *)node->data; ment->segno = sblk->segno; ment->seq = cpu_to_le64(1); - ment->first_key_len = 0; - ment->last_key_len = cpu_to_le16(1); + ment->first_key_len = cpu_to_le16(sizeof(struct scoutfs_inode_key)); + ment->last_key_len = cpu_to_le16(sizeof(struct scoutfs_inode_key)); ment->level = 1; - type = (void *)ment->keys; - *type = SCOUTFS_MAX_UNUSED_KEY; + ikey = (void *)ment->keys; + ikey[0] = root_ikey; + ikey[1] = root_ikey; node->crc = crc_node(node);