linux/Documentation/prio_tree.txt
<<
val.32/spa v .32/form v .32a val.3 href="../linux+v3.6/Documenta > /prio_tree.txt"> val.32img src="../.sta >c/gfx/right.png" alt=">>"> v2/spa v v2spa class="lxr_search"> val ="+search" method="post" onsubmit="return do_search(this);"> val.32input typ> hidden" nam> navtarget" tion> "> val.32input typ> text" nam> search" id search"> val.32butt/optyp> submit">Search val.3Prefsv .32/a> v2/spa val.3 32/div val.3 32form ac > ="ajax+*" method="post" onsubmit="return false;"> v2input typ> hidden" nam> ajax_lookup" id ajax_lookup" tion> "> al.3 32/form v al.3 32div class="headingbott/m">
L1">3 312/a>The prio_tree.c code indexes vmas using 3 different indexes: L2">3 322/a> * heap_index = vm_pgoff + vm_size_in_pages : end_vm_pgoff L3">3 332/a> * radix_index = vm_pgoff : start_vm_pgoff L4">3 342/a> * size_index = vm_size_in_pages L5">3 352/a> L6">3 362/a>A regular radix-priority-search-tree indexes vmas using only heap_index and L7">3 372/a>radix_index. The condi > s for indexing are: L8">3 382/a> * ->heap_index >= ->left->heap_index && L9">3 392/a> ->heap_index >= ->right->heap_index L10">3 .6.2a> * if (->heap_index == ->left->heap_index) L11">3 112/a> then ->radix_index < ->left->radix_index; L12">3 12.2a> * if (->heap_index == ->right->heap_index) L13">3 132/a> then ->radix_index < ->right->radix_index; L14">3 142/a> * nodes are hashed to left or right subtree using radix_index L15">3 152/a> similar to a pure binary radix tree. L16">3 162/a> L17">3 172/a>A regular radix-priority-search-tree helps to store and query L18">3 182/a>intertios (vmas). However, a regular radix-priority-search-tree is only L19">3 192/a>suitable for storing vmas with different radix indices (vm_pgoff). L20">3 202/a> L21">3 212/a>Therefore, the prio_tree.c extends the regular radix-priority-search-tree L22">3 22.2a>to handle many vmas with the sam> vm_pgoff. Such vmas are handled in L23">3 232/a>2 different ways: 1) All vmas with the sam> radix _and_ heap indices are L24">3 242/a>linked using vm_set.list, 2) if there are many vmas with the sam> radix L25">3 252/a>index, but different heap indices and if the regular radix-priority-search L26">3 262/a>tree cannot index them all, we build an overflow-sub-tree that indexes such L27">3 272/a>vmas using heap and size indices instead of heap and radix indices. For L28">3 282/a>example, in the figure below som> vmas with vm_pgoff = 0 (zero) are L29">3 292/a>indexed by regular radix-priority-search-tree whereas others are pushed L30">3 302/a>into an overflow-subtree. Note that all vmas in an overflow-sub-tree have L31">3 312/a>the sam> vm_pgoff (radix_index) and if necessary we build different L32">3 32.2a>overflow-sub-trees to handle each possible radix_index. For example, L33">3 332/a>in figure we have 3 overflow-sub-trees corresponding to radix indices L34">3 342/a>0, 2, and 4. L35">3 352/a> L36">3 362/a>In the final tree the first few (prio_tree_root->index_bits) levels L37">3 372/a>are indexed using heap and radix indices whereas the overflow-sub-trees below L38">3 382/a>those levels (i.e. levels prio_tree_root->index_bits + 1 and higher) are L39">3 392/a>indexed using heap and size indices. In overflow-sub-trees the size_index L40">3 402/a>is used for hashing the nodes to appropriate places. L41">3 412/a> L42">3 42.2a>Now, an example prio_tree: L43">3 432/a> L44">3 442/a> vmas are represented [radix_index, size_index, heap_index] L45">3 452/a> i.e., [start_vm_pgoff, vm_size_in_pages, end_vm_pgoff] L46">3 462/a> L47">3 472/a>level prio_tree_root->index_bits = 3 L48">3 482/a>----- L49">3 492/a> _ L50">3 56.2a> 0 [0,7,7] | L51">3 512/a> / \ | L52">3 522/a> ------------------ ------------ | Regular L53">3 532/a> / \ | radix priority L54">3 542/a> 1 [1,6,7] [4,3,7] | search tree L55">3 552/a> / \ / \ | L56">3 562/a> ------- ----- ------ ----- | heap-and-radix L57">3 572/a> / \ / \ | indexed L58">3 582/a> 2 [0,6,6] [2,5,7] [5,2,7] [6,1,7] | L59">3 592/a> / \ / \ / \ / \ | L60">3 66.2a> 3 [0,5,5] [1,5,6] [2,4,6] [3,4,7] [4,2,6] [5,1,6] [6,0,6] [7,0,7] | L61">3 612/a> / / / _ L62">3 622/a> / / / _ L63">3 632/a> 4 [0,4,4] [2,3,5] [4,1,5] | L64">3 642/a> / / / | L65">3 652/a> 5 [0,3,3] [2,2,4] [4,0,4] | Overflow-sub-trees L66">3 662/a> / / | L67">3 672/a> 6 [0,2,2] [2,1,3] | heap-and-size L68">3 682/a> / / | indexed L69">3 692/a> 7 [0,1,1] [2,0,2] | L70">3 702/a> / | L71">3 712/a> 8 [0,0,0] | L72">3 722/a> _ L73">3 732/a> L74">3 74.2a>Note that we use prio_tree_root->index_bits to >mize the height L75">3 752/a>of the heap-and-radix indexed tree. Since prio_tree_root->index_bits is L76">3 762/a>set according to the maximum end_vm_pgoff mapped, we are sure that all L77">3 772/a>bits (in vm_pgoff) above prio_tree_root->index_bits are 0 (zero). Therefore, L78">3 782/a>we only use the first prio_tree_root->index_bits as radix_index. L79">3 792/a>Whenever index_bits is increased in prio_tree_expand, we shuffle the tree L80">3 80.2a>to make sure that the first prio_tree_root->index_bits levels of the tree L81">3 812/a>is indexed properly using heap and radix indices. L82">3 822/a> L83">3 832/a>We do not >mize the height of overflow-sub-trees using index_bits. L84">3 842/a>The reason is: there can be many such overflow-sub-trees and all of L85">3 852/a>them have to be suffled whenever the index_bits increases. This may involve L86">3 862/a>walking the whole prio_tree in prio_tree_insert->prio_tree_expand code L87">3 872/a>path which is not desirable. Hence, we do not >mize the height of the L88">3 882/a>heap-and-size indexed overflow-sub-trees using prio_tree->index_bits. L89">3 892/a>Instead the overflow sub-trees are indexed using full BITS_PER_LONG bits L90">3 902/a>of size_index. This may lead to skewed sub-trees because most of the L91">3 912/a>higher significant bits of the size_index are likely to be 0 (zero). In L92">3 922/a>the example above, all 3 overflow-sub-trees are skewed. This may marginally L93">3 932/a>affect the performance. However, processes rarely map many vmas with the L94">3 942/a>sam> start_vm_pgoff but different end_vm_pgoffs. Therefore, we normally L95">3 952/a>do not require overflow-sub-trees to index all vmas. L96">3 962/a> L97">3 972/a>From the above discuss L98">3 982/a>a prio_tree can be prio_tree_root->index_bits + BITS_PER_LONG. L99">3 992/a>However, in most of the comm/opcases we do not need overflow-sub-trees, L100">31002/a>so the tree height in the comm/opcases will be prio_tree_root->index_bits. L101">31012/a> L102">31022/a>It is fair to ment / / /prio_tree.9pvmas. /d L86" class="lio_tree.s. / / <" nat'am>rickam> do" id L88it'a / L17"06prio_/a>A regular radix-priority-search-tree helps0 to store0 and query > ori32/a> LXR softw.txtbyio_tregular rahttp://sourc> Lge.netseaojta s/lxr">LXR xt#Lunityta > /d lio>3 eriprior62/erid Lbyiegular ramailto:lxr@">.no">lxr@">.nota >. a6cba7eb59c7arch-tr0">f0nder"> lxr.">.no ntadL7">_tr> /pregular rahttp://www.redp101-"&geao.no">Redp101 L&geao ASta > /eaovid > e.tL>line id /a> 72/" clanam> s="v L38s6" cl1995. a6cba7e9b/body7eb/htmlv