Why did Linux use the AVL tree earlier and then prefer the red-black tree?
In fact, this is the result of the pragmatism of the red and black tree, and this essay remains a metaphysical point of view. Red and black trees can be exported directly from 2-3 trees, we can no longer mention the red and black trees, but only 2-3 trees, because the operation of the 2-3 tree is too simple. In addition, the operation and characteristics of any red-black tree can be mapped to 2-3 trees. The comparison between the red and black and AVL trees is therefore a comparison of 2-3 and AVL trees.
What's the difference between the two? The balance of the 2-3 tree is perfectly balanced, but the number of branches can be 3, while the AVL tree almost points to a perfectly balanced standard binary tree, which allows only the height difference of the subtree to be up to 1. So it seems that 2-3 trees more balanced than AVL tree, but 2-3 trees converted to two tree, that is, the red and black trees, it can no longer maintain the perfect balance, because the three fork node to be split out a red node, so that the subtree height plus 1, so it seems that the red and black trees in strict sense no AVL tree balance!
The AVL tree maintains its "close balance" every time the insert is deleted, while the red-black tree requires no disturbance to the black node, which, in 2-3 trees, is the standard feature that sacrifices the two-fork tree to maintain the balance of the three-prong tree. Visible, red black tree Insert/delete cost is much smaller than the AVL tree, for query overhead, theoretically, more balanced AVL tree is better than red black tree (because for 2-3 trees, you need to compare 2 times), but, the red black tree twice times the height of the unbalanced state is a small probability event! So for normal situations, you can assume that the query cost of the AVL tree and the red-black tree is the same, in short, the red-black tree is better than the AVL tree in general.
The AVL tree is ideal, and the data structures in the Linux kernel, especially the virtual memory management module, especially the task pair columns of the CFS scheduler, are frequently inserted and deleted, so the red-black tree is chosen instead of the AVL tree.
Linux kernel to red-black tree and AVL tree