From ae744f81273c7633a3839384e4fac587dcae52f3 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Thu, 27 Aug 2015 00:21:27 +0900 Subject: [PATCH] sys/vfs/hammer: Add and fix comments on * inode's node cache * btree node split * volume header --- sys/vfs/hammer/hammer.h | 10 +++++++++- sys/vfs/hammer/hammer_btree.c | 24 ++++++++++++++++++++++-- sys/vfs/hammer/hammer_vnops.c | 4 ++-- sys/vfs/hammer/hammer_volume.c | 3 +-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/sys/vfs/hammer/hammer.h b/sys/vfs/hammer/hammer.h index 8f658b5cd3..5f0a71de7a 100644 --- a/sys/vfs/hammer/hammer.h +++ b/sys/vfs/hammer/hammer.h @@ -383,7 +383,15 @@ struct hammer_inode { struct hammer_inode_data ino_data; /* in-memory cache */ struct hammer_rec_rb_tree rec_tree; /* in-memory cache */ int rec_generation; - struct hammer_node_cache cache[4]; /* search initiate cache */ + + /* + * search initiate cache + * cache[0] - this inode + * cache[1] - related data, the content depends on situations + * cache[2] - for dip to cache ip to shortcut B-Tree search + * cache[3] - related data copied from dip to a new ip's cache[1] + */ + struct hammer_node_cache cache[4]; /* * When a demark is created to synchronize an inode to diff --git a/sys/vfs/hammer/hammer_btree.c b/sys/vfs/hammer/hammer_btree.c index 2bd233aaa9..43c9fc3656 100644 --- a/sys/vfs/hammer/hammer_btree.c +++ b/sys/vfs/hammer/hammer_btree.c @@ -1199,11 +1199,16 @@ btree_search(hammer_cursor_t cursor, int flags) } /* - * These cases occur when the parent's idea of the boundary + * The first two cases (i == 0 or i == node->count + 1) + * occur when the parent's idea of the boundary * is wider then the child's idea of the boundary, and * require special handling. If not inserting we can * terminate the search early for these cases but the * child's boundaries cannot be unconditionally modified. + * + * The last case (neither of the above) fits in child's + * idea of the boundary, so we can simply push down the + * cursor. */ if (i == 0) { /* @@ -1644,7 +1649,7 @@ btree_split_internal(hammer_cursor_t cursor) ondisk = node->ondisk; elm = &ondisk->elms[split]; bcopy(elm, &new_node->ondisk->elms[0], - (ondisk->count - split + 1) * esize); + (ondisk->count - split + 1) * esize); /* +1 for boundary */ new_node->ondisk->count = ondisk->count - split; new_node->ondisk->parent = parent->node_offset; new_node->ondisk->type = HAMMER_BTREE_TYPE_INTERNAL; @@ -1673,6 +1678,10 @@ btree_split_internal(hammer_cursor_t cursor) parent_elm = &ondisk->elms[parent_index+1]; bcopy(parent_elm, parent_elm + 1, (ondisk->count - parent_index) * esize); + + /* + * Why not use hammer_make_separator() here ? + */ parent_elm->internal.base = elm->base; /* separator P */ parent_elm->internal.base.btype = new_node->ondisk->type; parent_elm->internal.subtree_offset = new_node->node_offset; @@ -1924,6 +1933,12 @@ btree_split_leaf(hammer_cursor_t cursor) bcopy(parent_elm, parent_elm + 1, (ondisk->count - parent_index) * esize); + /* + * elm[-1] is the right-most elm in the original node. + * elm[0] equals the left-most elm at index=0 in the new node. + * parent_elm[-1] and parent_elm point to original and new node. + * Update the parent_elm base to meet >elm[-1] and <=elm[0]. + */ hammer_make_separator(&elm[-1].base, &elm[0].base, &parent_elm->base); parent_elm->internal.base.btype = new_leaf->ondisk->type; parent_elm->internal.subtree_offset = new_leaf->node_offset; @@ -2546,6 +2561,11 @@ hammer_btree_mirror_propagate(hammer_cursor_t cursor, hammer_tid_t mirror_tid) return(error); } +/* + * Return a pointer to node's parent. If there is no error, + * *parent_index is set to an index of parent's elm that points + * to this node. + */ hammer_node_t hammer_btree_get_parent(hammer_transaction_t trans, hammer_node_t node, int *parent_indexp, int *errorp, int try_exclusive) diff --git a/sys/vfs/hammer/hammer_vnops.c b/sys/vfs/hammer/hammer_vnops.c index 96379490f7..39031b5808 100644 --- a/sys/vfs/hammer/hammer_vnops.c +++ b/sys/vfs/hammer/hammer_vnops.c @@ -2976,8 +2976,8 @@ done: * Cache the b-tree node for the last data read in cache[1]. * * If we hit the file EOF then also cache the node in the - * governing director's cache[3], it will be used to initialize - * the inode's cache[1] for any inodes looked up via the directory. + * governing directory's cache[3], it will be used to initialize + * the new inode's cache[1] for any inodes looked up via the directory. * * This doesn't reduce disk accesses since the B-Tree chain is * likely cached, but it does reduce cpu overhead when looking diff --git a/sys/vfs/hammer/hammer_volume.c b/sys/vfs/hammer/hammer_volume.c index 0bb5e9536b..926ab8e48f 100644 --- a/sys/vfs/hammer/hammer_volume.c +++ b/sys/vfs/hammer/hammer_volume.c @@ -659,8 +659,7 @@ hammer_format_volume_header(struct hammer_mount *hmp, vol_alloc += mem_area_size; /* - * The remaining area is the zone 2 buffer allocation area. These - * buffers + * The remaining area is the zone 2 buffer allocation area. */ ondisk->vol_buf_beg = vol_alloc; ondisk->vol_buf_end = vol_size & ~(int64_t)HAMMER_BUFMASK; -- 2.41.0