diff options
author | Christoph Hellwig <hch@lst.de> | 2017-11-09 12:11:43 -0500 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2017-11-09 17:08:54 -0500 |
commit | 3e27c418a7a13b8dbf33f6eb49b0e461f011bdcd (patch) | |
tree | 5fb2831166407a849836198bb3ab94ac4c003781 | |
parent | b9aee1d5fe58160a44556224b5479bd151a3e1a5 (diff) |
xfs: add comments documenting the rebalance algorithm
Reported-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r-- | fs/xfs/libxfs/xfs_iext_tree.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_iext_tree.c b/fs/xfs/libxfs/xfs_iext_tree.c index 3974989b0929..81e0480822d8 100644 --- a/fs/xfs/libxfs/xfs_iext_tree.c +++ b/fs/xfs/libxfs/xfs_iext_tree.c | |||
@@ -672,6 +672,11 @@ xfs_iext_rebalance_node( | |||
672 | struct xfs_iext_node *node, | 672 | struct xfs_iext_node *node, |
673 | int nr_entries) | 673 | int nr_entries) |
674 | { | 674 | { |
675 | /* | ||
676 | * If the neighbouring nodes are completely full, or have different | ||
677 | * parents, we might never be able to merge our node, and will only | ||
678 | * delete it once the number of entries hits zero. | ||
679 | */ | ||
675 | if (nr_entries == 0) | 680 | if (nr_entries == 0) |
676 | return node; | 681 | return node; |
677 | 682 | ||
@@ -693,6 +698,11 @@ xfs_iext_rebalance_node( | |||
693 | int nr_next = xfs_iext_node_nr_entries(next, 0), i; | 698 | int nr_next = xfs_iext_node_nr_entries(next, 0), i; |
694 | 699 | ||
695 | if (nr_entries + nr_next <= KEYS_PER_NODE) { | 700 | if (nr_entries + nr_next <= KEYS_PER_NODE) { |
701 | /* | ||
702 | * Merge the next node into this node so that we don't | ||
703 | * have to do an additional update of the keys in the | ||
704 | * higher levels. | ||
705 | */ | ||
696 | for (i = 0; i < nr_next; i++) { | 706 | for (i = 0; i < nr_next; i++) { |
697 | node->keys[nr_entries + i] = next->keys[i]; | 707 | node->keys[nr_entries + i] = next->keys[i]; |
698 | node->ptrs[nr_entries + i] = next->ptrs[i]; | 708 | node->ptrs[nr_entries + i] = next->ptrs[i]; |
@@ -741,6 +751,11 @@ again: | |||
741 | return; | 751 | return; |
742 | 752 | ||
743 | if (level < ifp->if_height) { | 753 | if (level < ifp->if_height) { |
754 | /* | ||
755 | * If we aren't at the root yet try to find a neighbour node to | ||
756 | * merge with (or delete the node if it is empty), and then | ||
757 | * recurse up to the next level. | ||
758 | */ | ||
744 | level++; | 759 | level++; |
745 | parent = xfs_iext_find_level(ifp, offset, level); | 760 | parent = xfs_iext_find_level(ifp, offset, level); |
746 | pos = xfs_iext_node_pos(parent, offset); | 761 | pos = xfs_iext_node_pos(parent, offset); |
@@ -755,6 +770,10 @@ again: | |||
755 | goto again; | 770 | goto again; |
756 | } | 771 | } |
757 | } else if (nr_entries == 1) { | 772 | } else if (nr_entries == 1) { |
773 | /* | ||
774 | * If we are at the root and only one entry is left we can just | ||
775 | * free this node and update the root pointer. | ||
776 | */ | ||
758 | ASSERT(node == ifp->if_u1.if_root); | 777 | ASSERT(node == ifp->if_u1.if_root); |
759 | ifp->if_u1.if_root = node->ptrs[0]; | 778 | ifp->if_u1.if_root = node->ptrs[0]; |
760 | ifp->if_height--; | 779 | ifp->if_height--; |
@@ -789,6 +808,11 @@ xfs_iext_rebalance_leaf( | |||
789 | int nr_next = xfs_iext_leaf_nr_entries(ifp, leaf->next, 0), i; | 808 | int nr_next = xfs_iext_leaf_nr_entries(ifp, leaf->next, 0), i; |
790 | 809 | ||
791 | if (fill + nr_next <= RECS_PER_LEAF) { | 810 | if (fill + nr_next <= RECS_PER_LEAF) { |
811 | /* | ||
812 | * Merge the next node into this node so that we don't | ||
813 | * have to do an additional update of the keys in the | ||
814 | * higher levels. | ||
815 | */ | ||
792 | for (i = 0; i < nr_next; i++) | 816 | for (i = 0; i < nr_next; i++) |
793 | leaf->recs[fill + i] = leaf->next->recs[i]; | 817 | leaf->recs[fill + i] = leaf->next->recs[i]; |
794 | 818 | ||