Effective memory management in embedded systems reduce running time and power consumption. Memory allocation is complicated by limited capacity and number of memory banks, as well as potential runtime conflicts. We approached the optimization of memory allocation problem through exact solution using ILP and Tabu Search heauristic method. Inputs from DIMACs instances were tested and the results show significant performance difference between the two approaches
A mathematical model and a heuristic memory allocation problem
1. 1
Memory Allocation Problem Using Tabu Search
Metaheuristics and ILP
Enkhjin Bayarsaikhan, Farnoosh Farokhmanesh, Diego Montero
CANO (Master CANS - FIB)
UPC Barcelona, Spain
Abstract
Effective memory management in embedded systems reduce running time and power consumption. Memory
allocation is complicated by limited capacity and number of memory banks, as well as potential runtime conflicts.
We approached the optimization of memory allocation problem through exact solution using ILP and Tabu Search
heauristics method. Inputs from DIMACs instances[1] were tested and the results show significant performance
difference between the two approaches.
I. I NTRODUCTION
Memory management optimization is closely related to minimizing the power consumption in embedded
systems. Given a limited number of memory cache available, in a data and computationally intensive
performance, it is critical to ensure the maximum amount of data available in memory, and minimum
time spent loading and offloading data from external storage. In the era where desktop computers are
being replaced by laptops, smart-phones and tablet computers, reducing power consumption at runtime in
embedded systems is important. In this paper, we tackle the optimization of memory management problem
using Integer Linear Programming (ILP) in CPLEX, and Tabu Search (TS) metaheairustics technique. The
main purpose of this paper is analyse the performance comparison of ILP and TS in the optimization of
realistic memory management problem.
Memory allocation with limited number of memory banks is similar to a classic combinatorial optimiza-
tion problem called k-weighted graph coloring [2]. Furthermore, one of the suggested metaheuristics for
solving the graph coloring problem is TS. Therefore, we’ve used a version of TS called tabucol to find the
heuristical optimization of the given memory allocation problem. The input data were publicly available
DIMACs instances that are enriched with multiple constraints and costs to match the inputs presented in
[3]. From the experimentations using these instances in both ILP and TS, the observed difference was
that ILP performed excellent in smaller datasets with small number of conflicts, whereas TS performed
significantly better for larger instances.
The structure of this paper is as follows, Section II contains a detailed discussion of background and
related works, Section III discusses the experimental setup, Section IV discusses the ILP implementation,
Section V covers the metaheuristics implementation, Section VI contains the output comparison and
Section VII with critical discussions, and finally the paper concludes with project review and suggestions
from our group.
II. BACKGROUND AND R ELATED WORKS
The topic of this project was presented in [3], which introduces solving memory allocation problem in
embedded systems using exact approach and multiple metaheuristic methods. Due to the correspondence
in class contents and scope, we chose to implement Tabu search heuristic method in our project, and
compared its execution and performance against the integer solution. The following sections introduce the
memory allocation problem in more detail, how it is solved using the graph coloring approach, and the
heuristics method we chose to implement.
2. 2
A. Memory Allocation in Embedded Systems
The relationship between memory management and power consumption of electronic systems is in-
troduced in [4], where the authors observed that during a heavy computation period, inefficient memory
management demands higher power consumption by the embedded system. Another way to minimize the
power consumption of computer system is to minimize the runtime of any application, which also means
minimizing the time it takes for loading operations and accessing to memory. Therefore, optimizing the
memory management in embedded systems reduces power consumption of the system, and enhances the
product usage.
To solve the aforementioned memory management problem, several assumptions must be made. The first
assumption is that, absence of an operating system. Since each operating systems have different memory
management methods, the focus of this paper is to optimize the memory management of applications
written in lower level language, such as C code. Therefore the problem, on which this project focuses,
is minimizing the total time accessing the data structures and loading them to appropriate registers to
perform the operations listed in C code.
Also, in addition to the limited capacity internal memory banks, the presence of an external memory with
unlimited capacity is assumed. The data structures take time to be accessed from internal memory banks,
and a parameter p times longer to be accessed from the external memory. When two data structures are
called in a same operation, they must be accessed simultaneously if they are located in different memory
banks. If they are located in a same memory bank, they must be accessed sequentially, hence creating a
conflict in the optimization. As mentioned in [3], there are four different conflict statuses between such
two data structures:
• two data structures could be mapped to different memory banks, thus creating no conflicts.
• two data structures could be located in same internal memory bank, and need to be accessed
sequentially. In this case, there would be a conflict cost, d.
• one of the data structures, ak , could be mapped to an external memory bank, while the other data
structure, bk , is mapped to an internal memory bank. The conflict arises when both data structures
are accesses simultaneously, and ak would be mapped with extra cost factor, p. Thus, the total cost
in this case would be pd.
• two data structures could be both mapped to external memory, hence the cost would be 2pd.
Conflicts costs, as well as the access times from internal memory and external memory, are analogous
to power consumption. With these realistic assumptions, the power consumption of an embedded system
could be now optimized via the memory allocation problem.
B. Graph Coloring Problem using Tabu Search
Memory allocation with constraint on the number of memory banks is equivalent to k-weighted graph
coloring problem [2]. K-weighted graph coloring problem consists of coloring the vertices of a graph with
undirected edges, with k number of colors, such that the number of edges with vertices of same color
would be minimized. In comparison to memory allocation problem, the data structures are represented by
nodes or vertices, the memory banks are represented by colors. The conflicts are represented by edges. The
difference between graph coloring problem and the given memory allocation problem is the capacity of
memory banks, the access times of data structures, and cost of conflicts. Therefore, it is safe to assume that
k-weighted graph coloring problem is a simpler version of memory allocation problem with constraints
in number of memory banks.
Tabu search procedure, suggested by [5] to solve graph coloring problem, is described as moving
iteratively towards the optimum value of a function, employing a special feature, to avoid being trapped
in a local optima. The special feature is called a Tabu List, which contains a certain number of moves that
have been covered before, thus they are forbidden as the name suggests. The idea is to generate an initial
feasible solution, S, and generate a set of neighbourhoods, N(S), of feasible solutions. From N(S), the
current best neighbour, S*, is chosen in one iteration. The trick here is to choose S* that does not belong
3. 3
to values in the Tabu List. For the graph coloring problem, the initial solution is generated randomly. The
implementation of tabu search metaheuristic in more detail in Section V.
III. E XPERIMENTAL S ETUP
The given problem was solved using two techniques: by using Integer Linear Programming (ILP) ,
and by implementing Tabu Search metaheuristic. The use of these two methods in memory management
problem was discussed in [3]. The ILP was implemented in CPLEX optimization software, acquired
through the academic license from IBM. The execution of each problem instances were done in the UPC
lab computers in Building B5. The Tabu search metaheuristic was implemented in C code, in one of our
group members’ personal computer, running Ubuntu OS. The metaheurisctic implementation is based on
the TabuCol[5] approach implementation taken from [6].
Furthermore, the input data were chosen from DIMACs graph coloring instances, as mentioned in [3],
that are publicly availbale at [1]. The original DIMACs instances contain number of edges and nodes
for a graph coloring problem, and are analogous to number of conflicts and number of data structures,
respectively. These instances were enriched with randomly generated values for the number of memory
banks, the p factor for loading from the external memory, the access times of data structures, as well as
the conflict costs. The data structure sizes and memory bank capacities were set to be constant for all
instances, as they are in [3].
IV. ILP I MPLEMENTATION
The ILP model used for memory allocation problem was presented in [3], and it was implemented using
the IBM CPLEX optimizer. This section focuses on the interpretation of the ILP model, and discussion
about CPLEX performance in optimizing the ILP.
A. ILP Model
The sets and parameters in ILP model are as follows:
• There are n number of data structures, indexed i.
• There are m number of memory banks, indexed j. The external memory is indicated as m+1.
• There are o number of conflicts, indexed k.
• The capacity of memory bank j is denoted by cj .
• The size of each data structure i is denoted by si .
• The access cost of data structure i is denoted by ei .
• The cost of conflict k is denoted as dk .
The variables in ILP model are as follows:
• A binary matrix X of size (n×m), with elements xi ,j . Each element, xi ,j , is either 1 when data
structure i is mapped to memory bank j, or 0 when otherwise.
1, if data structure i is mapped to memory bank j ∀i ∈ {1, . . . , n}, ∀j ∈ {1, . . . , m + 1}
xi,j =
0, otherwise
• A vector Y with nonnegative variables yk associated with conflicting relationships between two data
structures. The variable yk takes on a value of 0, when there are no conflicts between two data
structures, 1 when both data structures are mapped to a same internal memory, p when one is
mapped to internal and the other is mapped to an external memory, and 2p when both data structures
are mapped to external memories. In short, the value of yk could be 0, 1, p, or 2p.
The purpose of memory allocation problem is to minizie the power consumption by efficiently managing
the memory, as discussed earlier. Thus, it is analogous to minimizing the cost associated with any conflicts,
and cost of access time of each data structures in internal and in external memory banks. This objective
of our problem, modeled in equation (1), is to minimize the total cost of conflicts, the cost to access
each data structures in all internal memory, and the cost to access data structures allocated in the external
4. 4
memory. The equation (2) enforces that each data structure is mapped to a single memory bank, or the
external memory. The equation (3) enforces that the total size of data structures mapped to a memory
bank j does not exceed its capacity. The inequalities (4) to (7) ensures the appropriate values of variable
yk for conflict k. Inequality (4) declares that when two data structures, ak and bk , are mapped to a same
internal memory bank j, the value of variable yk is not zero. Inequalities (5) and (6) prevents the value of
variable yk from being less than p when one data structure is mapped to internal and the other is mapped
to external memory. Similarly, the inequality (7) ensures the appropriate value of yk for the last conflict
case. The expressions in (8) and (9) ensure the binary nature of xi ,j , and nonnegative nature of yk .
o n m n
Min yk dk + (ei xi,j ) + p (ei xi,m+1 ) (1)
k=1 i=1 j=1 i=1
m+1
xi,j = 1, ∀i ∈ {1, . . . , n} (2)
j=1
n
xi,j si ≤ cj , ∀j ∈ {1, . . . , m} (3)
i=1
xak ,j + xbk ,j ≤ 1 + yk , ∀j ∈ {1, . . . , m}, ∀k ∈ {1, . . . , o} (4)
1
xak ,j + xbk ,m+1 ≤ 1 + yk , ∀j ∈ {1, . . . , m}, ∀k ∈ {1, . . . , o} (5)
p
1
xak ,m+1 + xbk ,j ≤ 1 + yk , ∀j ∈ {1, . . . , m}, ∀k ∈ {1, . . . , o} (6)
p
1
xak ,m+1 + xbk ,m+1 ≤ 1 + yk , ∀k ∈ {1, . . . , o} (7)
2p
xi,j ∈ {0, 1}, ∀(i, j) ∈ {1, . . . , n} × {1, . . . , m} (8)
yk ≥ 0, ∀k ∈ {1, . . . , o} (9)
B. Optimization using CPLEX
The optimization process in CPLEX could be described as minimizing the gap between generated
objective function projection and current solution projection. In other words, the optimum solution of
an ILP problem is found when this gap reaches to zero, and current solution projection intersects the
objective function projection. CPLEX optimizer utilizes the Branch&Cut technique, such as described in
the course lectures, to reduce the feasible solution pool into smaller sections, and finds integer values
from the reduced sections. The current minimum integer solution is called the incumbent value.
The results of our CPLEX implementation is presented in the columns 7 and 8 of Table 1. The bolded
texts indicate the guaranteed optimum solutions obtained by CPLEX and unbolded texts indicate incumbent
values obtained for the specified time frame. The magnitude of each input instances could be described
by the n,m,o values, and the problem instances could classified by the number of constraints and variables
generated by the ILP. It is noticeable that ILP optimizer performs well for smaller problem instances.
The optimum values were guaranteed and execution time fell under 1 second. In larger problem instances
ILP failed to ensure the optimization of the current incumbent. The execution time was in the range of
hundreds of seconds, and the change in execution time between smaller and larger instances is significant.
5. 5
TABLE I
C OMPARISON OF P ERFORMANCE AND E XECUTION T IME B ETWEEN ILP AND TS
V. M ETAHEURISTICS I MPLEMENTATION - TABU S EARCH
In this section, we describe the implementation of the Metaheuristic used for addressing this problem.
Besides, we briefly describe the TabuCol algorithm which was used to solve the problem.
Our metaheuristic works in two phases. The first one is looking for a Random Initial Solution, then the
Tabu Search is executed based on the initial solution.
A. Random Initial Solution
Algorithm 1 presents the procedure to find an initial feasible solution taking into account the capacity
constrains of the memory banks. The algorithm’s inputs are a graph G = (V, E) and a number of bank
memories (colors). The outputs are a feasible solution X ∗ and the cost of that solution f ∗ .
Algorithm 1 Random Initial Solution
Require: Graph G(V,E), k ←number of colors
Initialization:
Capacity used: uj ← 0, ∀j ∈ {1, . . . , m + 1}
Allocation: x∗ ← 0, ∀i ∈ {1, . . . , n}, ∀j ∈ {1, . . . , m + 1}
i,j
f∗ ← 0
Assignment:
for i = 1 → n do
repeat
Generate j at random in {1 . . . , m + 1}
until uj + sj ≤ cj
x∗ ← 1
i,j
uj ← uj + si
Compute gi,j , the cost generated from allocation the data i to memory bank j
f ∗ ← f ∗ + gi,j
end for
return [X ∗ , f ∗ ]
B. Tabu Search TS - TabuCol
Tabu search is a metaheuristic that relies on a single local search procedure: it iteratively moves from
the current solution to another one in its neighborhood. Generally, local search procedures stop when a
local optimum is found, then it becomes necessary to escape from the local optimum to explore other
regions of the search space. Besides, the local search is repeated a max number of iterations.
6. 6
We introduce tabu search in Algorithm 2 which is based on TabuCol, an algorithm for graph coloring
introduced in [5]. The algorithm takes an initial solution X as input and looks for a X’s neighbor best
solution until the cost of the new solution is better than the previous. However, if there is no a better
solution, the algorithm iterates a fixed number of iterations which are controlled by the parameter maxIter.
Algorithm 3 defines the how to find the neighbor’s solutions of solution X. A pair (i, j) means that data
structure i is in memory bank j. A move is a trio (i, h, j), this means that data structure i, which is
currently in memory bank h is going to be moved to memory bank j. As a consequence, if the move
(i, h, j) is performed, then the pair (i, h) is appended to the tabu list T. Thus, the tabu list contains the
pairs that have been performed in the recent past and those movements remain in T a certain period
(number of iterations).
Algorithm 2 TabuCol Memory Allocation
Require: Graph G(V,E), k ←number of colors, Initial Solution X
Initialization:
Initiate T (TabuList)
iter←0
f ∗ ← f (X)
while iter ≤ maxIter and f (X) > 0 do
generate neighbours Xi of X with move X → Xi ∈ T or f (Xi ) < f ∗
/
Let X be the best neighbour generated
Update tabu list T (introduce move X → X )
X←X
f ∗ ← f (X )
iter ← iter + 1
end while
return [X ∗ , f ∗ ]
Algorithm 3 Finding a Neighborhood
Require: Solution X
Find non tabu min cost move (i, h, j), such that h = j and uj + si ≤ cj
Check move on Tabulist T
if move is not in T: Build the new solution X as follows then
X ←X
xj,h ← 0
xi,j ← 1
uj ← ui + sj
uh ← uh − sj
end if
return [X , (i, h, j)]
VI. O UTPUT C OMPARISON
The graphs illustrated in Figure 1 shows the solution comparison of ILP and TS for smaller instances,
and the execution time differences. The red columns represent results from TS, and blue columns represent
CPLEX. For the first four cases, although TS was able to provide the optimum values, its execution time
was longer than CPLEX. In the instance of queen6 6, the TS metaheauristics took much longer time than
CPLEX and provided a poor solution.
7. 7
Fig. 1. Comparison of Tabu Search and ILP for Smaller Instances
Fig. 2. Comparison of Execution Time by Tabu Search and ILP
Figure 2 shows the execution time comparison of TS and ILP, as the number of variables in a problem
instance increases. The blue columns represent the exact time in seconds that TS was able to provide
feasible solution. The red columns represent the time in seconds that ILP was run, during which all
instances were able to find incumbent feasible solutions. It is easy to observe that although CPLEX showed
better performance in smaller problem instances, TS performed significantly better in larger problem
instances.
Fig. 3. Comparison of Solutions Obtained by Tabu Search and ILP
The graphs illustrated in Figure 3 show the solution comparison obtained by both ILP and TS, as the
number of variables in problem instances increase. The red columns in first graph represent the incumbent
values from CPLEX. The second graph in Figure 3 shows the percent differences between solutions from
TS and ILP. For larger instances, the solutions provided by TS is within 20% range of those provided
8. 8
by ILP. In smaller instances, TS was able to perform as well as ILP, with one exception. This exception
case may be due to the fact that TS highly depends on the initial solution, as mentioned in Section V.
VII. D ISCUSSIONS
There are certain issues that must be taken into consideration when comparing the performances of TS
metaheauristic and ILP optimization. Firstly, it must be noted that the input data are DIMACs instances
enriched with random values, such as size and access times of data structures, memory capacities, and
conflict costs. Real life input data may result in different execution times, and better feasible solution
pools. Secondly, the implemented metaheauristic is solely Tabu Search method. The resulting optimum
values highly depend on the initial solution, hence in Figure 3 we were able to observe 60% difference
in optimum values acquired from ILP and TS. It was mentioned during our presentation to increase the
number of initial solutions for each TS run to improve the results from the metaheuristic. Also, it is
common to implement TS with other metaheauristics to improve its performance.
VIII. C ONCLUSIONS
Optimum memory management in embedded systems is related to shorter runtimes of applications and
reduced power consumption. The memory allocation problem is equivalent to k-weighted graph coloring
problem, which is a classic combinatorial optimization problem known to be solved by Tabu Search
heauristics technique, among other metaheauristics. In this paper, we approached the memory allocation
problem with exact optimization using ILP, and with Tabu Search metaheuristic method. Enriched graph
coloring instances from DIMACs were chosen to be executed by the two methods, and the output results
were compared. The performance comparison showed that ILP performs well for smaller instances, while
performing much worse as the magnitude of problem instances grew. In contrast, Tabu Search metaheuristic
performed consistently as the problem size scales up.
R EFERENCES
[1] “Graph coloring instances.” http://mat.gsia.cmu.edu/COLOR/instances.html.
[2] M. Soto, “Optimization methods for the memory allocation problems in embedded systems,” 2011.
[3] A. R. M. Soto and M. Sevaux, “A mathematical model and a metaheuristic approach for a memory allocation problem,” Springer Science
and Business Media, 2011.
[4] L. N. S. Wuytack, F. Catthoor and H. Man, “Power exploration for data dominated video applications,” in International Symposium on
Low Power Electronics and Design, pp. 359–364, 1996.
[5] A. Hertz and D. de Werra, “Using tabu search techniques for graph coloring,” Springer-Verlag Computing, no. 39, pp. 345–351, 1987.
[6] M. Pagliari, “Heuristic tools: Tabucol, SA, variable neighborhood Search(VNS).” http://www.adaptivebox.net/CILib/code/gcpcodes link.
html.