Part I Equivalent Transformation Techniques
6.3 Optimization Techniques
In this section, we present two optimization techniques,decision chainingandiso- morphic terminal nodes elimination. These two techniques reduce the amount of memory used in constructing all-match trees and henceforth speed up the construc- tion process.
6.3.1 Decision Chaining
The terminal nodes in an all-match tree may consume a substantial amount of mem- ory. Whenever a subtree in an all-match tree needs to be copied, a substantial amount of time maybe needed to copy terminal nodes, where each terminal node stores an array of rule indexes. Next, we present an optimization technique calleddecision chaining, which stabilized both the amount of memory needed for storing terminal nodes and the time needed for copying subtrees.
Decision chaining is based upon the observation that rules are always added to the end of each terminal node’s array. With this observation, we store the rules for each decision in a singly linked list. Furthermore, we order our lists in reverse order so that we can insert rules at the head of the list in constant time. Storing decisions in a singly linked list allows each terminal node to be copied in constant time since we only have to copy the head node of the list. With this optimization, we can reduce that total amount of memory used to store rules since rules can be shared among terminal nodes.
The pseudocode for the modi¿ed append subroutine, which is needed to preform this optimization, is shown in Algorithm 12. Figure 6.6 shows the process of con- structing an all-match tree with the optimization of decision chaining. Note thatr1
6.3 Optimization Techniques 65
gets reused in the second insertion, and this reuse is maintained for the life of the tree.
Input: A vertexv, a rule(F1∈S1)∧ ⋅⋅⋅ ∧(Fd∈Sd)→ ⟨dec⟩, a depthm, and a rule numberi.
Output:vincludes the rule(F1∈S1)∧ ⋅⋅⋅ ∧(Fd∈Sd)→ ⟨dec⟩in its all-match structure.
LetF(v) =FmandE(v) ={e1,⋅⋅⋅,ek};
1
ifm=d+1then 2
Addito the head ofv’s label list ;
3 return 4 end 5 else if(Sm−(I(e1)∪ ⋅⋅⋅ ∪I(ek)))∕=/0then 6
Add an outgoing edgeek+1with labelSm−(I(e1)∪ ⋅⋅⋅ ∪I(ek))tov;
7
Build a decision path from(Fm+1∈Sm+1)∧ ⋅⋅⋅ ∧(Fd∈Sd)→ ⟨dec⟩, and makeek+1 8
point to the¿rst node in this path ;
Addito the end of the label of the terminal node of this decision path ;
9 end 10 forj := 1 to kdo 11 ifI(ej)⊆Smthen 12
APPEND(ej’s target,(F1∈S1)∧ ⋅⋅⋅ ∧(Fd∈Sd)→ ⟨dec⟩,m+1,i);
13 end 14
Add one outgoing edgeetov, and labelewithI(ej)∩Sm;
15
Make a copy of the subgraph rooted at the target node ofej, and makeepoints to the
16
root of the copy ;
Replace the label ofejbyI(ej)−Sm;
17
APPEND(e’s target,(F1∈S1)∧ ⋅⋅⋅ ∧(Fd∈Sd)→ ⟨dec⟩,m+1,i);
18
return 19
end 20
Algorithm 12: APPEND with decision chaining
Decision chaining is compatible and complementary to lazy copying [Meiners et al(2007)Meiners, Liu, and Torng], another optimization technique that we use in constructing all-match trees. Lazy copying can reduce the number of subtrees that are copied during construction.
With decision chaining, we construct an all-match tree by inserting the rules in a classi¿er from the last to the¿rst. This all-match tree constructing method does not require modi¿cation to our redundancy removal algorithm. In addition, when compared to inserting rules from the¿rst to the last, this method can signi¿cantly improve the ef¿ciency of lazy copying and decision chaining. This advantage is il- lustrated in Figure 6.7, where Figure 6.7(a) shows the all-match tree constructed by inserting the rules in the classi¿er in Figure 6.1 from the¿rst to the last and Fig- ure 6.7(b) shows the all-match tree constructed by inserting the rules in the same classi¿er from the last to the¿rst. Note that in¿gure Figure 6.7(a) ruler4is repli- cated across all four terminal nodes and in¿gure Figure 6.7(b) ruler4is stored only in one terminal node. The intuition behind this optimization is that the rules that ap- pear later in a classi¿er tend to cover larger areas, and thus, they typically intersect with more rules than rules that appear towards the front of the classi¿er. Inserting a rule that intersects with a large number of rules that have been inserted before it will
66 6 All-Match Redundancy Removal
Fig. 6.6 Constructing an all-match tree with decision chaining
result in many subtree being copied. Therefore, inserting rules from back to front results in less subtree copying and more memory sharing.
6.3.2 Isomorphic Terminal Nodes Elimination
In constructing an all-match tree from a packet classi¿er, the intermediate trees may contain isomorphic nodes. Two nodesvandv′in an all-match tree areisomorphic
if and only ifvandv′ satisfy one of the following two conditions: (1) bothvand
v′are terminal nodes with identical labels; (2) bothvandv′are nonterminal nodes and there is a one-to-one correspondence between the outgoing edges ofvand the outgoing edges of v′ such that every pair of corresponding edges have identical labels and they both point to the same node.
Combining two isomorphic nodes into one node will clearly reduce memory us- age. However, the time and space required for detecting all isomorphic node after appending every rule may over weigh its bene¿t. Therefore, we propose to elimi- nate only isomorphic terminal nodes, rather than eliminating all isomorphic nodes, for two reasons. First, isomorphic terminal nodes can be detected much more ef¿- ciently than isomorphic nonterminal nodes. Second, isomorphic terminal nodes ap-