Algorithms of replacement of the lines of mask
There exist various types of Mémoire hiding place, whose pleasing organization of the situations where a line of the main memory is map on a whole of lines of memory hiding place filled. It is thus necessary to choose the line of memory hiding place which will be replaced by the new line. This selection is carried out by the algorithms of replacement of lines of mask. The principle of operation of the majority of these algorithms rests on the Principe of locality. These algorithms are in general divided into two main categories:
- algorithms dependant on the use of the data: LRU, LFU, etc…
- algorithms independent of the use of the data: random, FIFO.
Optimal algorithm
This algorithm, formalized by L.A. Belady, uses the Mémoire hiding place in an optimal way: it replaces the line of Mémoire hiding place which will not be used for the greatest period of time. Consequently, this algorithm must know the future accesses in order to indicate the line with évincer. That is thus impossible to realize in a real system but constitutes nevertheless an excellent means in order to measure the effectiveness of an algorithm of replacement by providing a reference.
Usual algorithms
LRU (Least Recently Used)
This algorithm replaces the line used the least recently. The subjacent idea is to keep the data recently used, in accordance with the Principe of locality. All the accesses to the various lines of the memory hiding place are recorded; what explains why this algorithm is expensive in terms of operations of list processing. Moreover, this cost, which is a vital element of the embarked Systèmes in particular, exponentially increases with the number of ways of the memory hiding place.Several implementations of this algorithm are possible. One of them is rather simple and is based on the use of a triangular matrix NxN (where NR is the number of ways of the memory hiding place). When a line I is referred, the line I matrix is fixed at 1 and the column I to 0. The reached line the least recently is thus the line whose line is entirely equal to 0 and whose column is entirely equal to 1. This definition can appear strange but by line and column of the triangular Matrice, it is heard all the nonnull elements by definition of the matrix (i.e for which the number of line is lower than the number of column). This algorithm is carried out quickly and been rather easy to implement in hardware but its complexity grows quickly with the memory size hiding place. Thus, to have a limited number of ways seems preferable but a low number of ways is source of many conflicts… The solution is thus not obvious.
FIFO (First In First Out)
See also: First in, first out
As it has just been presented, the implementation of the algorithm LRU is complicated for a significant number of ways. An approximation of this algorithm was thus developed, it acts of an algorithm FIFO: the lines of the Mémoire hiding place are unobtrusive in the order where they arrived in the memory hiding place, thus using the Principe of locality in the simplest possible way. This simple design, which was worth one big hit in industry to him, is unfortunately obtained with the detriment of the effectiveness. Thus, according to Smith, the number of defects of mask obtained by this algorithm is between 12 and 20% more important than for the LRU.
The implementation hardware is rather simple because it requires only bits by whole of lines of memory hiding place. These bits make it possible to indicate the line with évincer. This meter is incremented with each defect of mask. If the meter is initialized to 0 during a cleaning of mask, the lines are thus évincées in the order where they were recorded in the mask. This relation of order is of course valid only for two lines of the same unit.
In spite of its simplicity, this algorithm presents the major disadvantage not to directly connect performance and memory size hiding place. Thus to increase the size of the mask can have a negative effect on the performance for certain sequences of access. This phenomenon is known under the name of Anomalie of Belady.
Random algorithm
The random algorithm is simplest: the évincée line is randomly selected. This method requires only few resources but its effectiveness is limited because it is not founded on the use of the data. That can be implemented in a rather simple way using shift registers with linear feedback. According to Al-Zoubi and Al, this algorithm is on average 22% less effective than LRU.This algorithm has an undeniable advantage on algorithm FIFO because its variations depend slightly on the size of the whole of the data, of the number of lines of mask…
LFU (Least Frequently Used)
Whereas LRU records the order of access of the various lines of memory hiding place, LFU as for him keeps trace of the frequency of access of these lines and replaces the least frequently used. The weak point of this algorithm is a pollution of the mask. Indeed, of the lines which were reached very frequently but which is not used any more in the future tend to remain in the memory hiding place. A usual solution is the addition of a policy of seniority: beyond of a certain time, the line is indicated like line to replace. Nevertheless, because of its complexity of implementation, this algorithm is used little in industry.
Approximations of algorithm LRU
Because of the complexity of implementation of the algorithm LRU, which influences in a negative way over average time of access to the memory hiding place, of the approximations of algorithm LRU were developed in order to mitigate these problems. The various algorithms presented in this section use all the fact that in the bottom of the list of access, the probability that the Processeur requires one of these lines is almost identical. Consequently, to indicate one of these lines for the ousting gives very close results. A partial order inside these units is thus sufficient.
All the figures drawn here respect following convention: the green corresponds to lines protected from the ousting and the yellow to the lines considered as LRU.
PLRUt (binary Decision tree)
The first approximation is founded on a binary tree of decision . It requires only N-1 bits by whole in an associative mask of NR ways. These various bits point the line considered as pseudo-LRU. The bits of the binary decision tree pointing on the hitée way are reversed to protect this line from the ousting. Let us take the example of a mask of 4 ways represented on the figure below. Each drawing corresponds to the result of the access report presented.The binary nature of this algorithm is also the weakness of the algorithm: the node in top of the binary tree contains only one information and cannot thus reflect sufficiently well the history of the various ways.
PLRUm
With each line of memory hiding place is assigned a bit. When a line is written, its bit is put at 1. If all the bits of a unit are equal to 1, all the bits except the last are re-initialized to zero. This algorithm is popular in many masks. According to Al-Zoubi and Al, these two pseudo-algorithms are very good approximations and PLRUm gives even better results that LRU on certain algorithms.
1-bit
It is probably simplest of the approximations of algorithm LRU and requires only one bit per unit. This bit shares the whole in two groups:- one which contains the MRU (Most Recently Used) not
- the other.
Improved LRU
Algorithms LRU and pseudo-LRU function well but are slightly effective at the time of access in burst: the data which are not reached that once occupy the memory hiding place and thus pollute the latter. Improved algorithms LRU try to solve this problem. These algorithms are thus very useful for the masks of disc or the copies of files. All the algorithms presented in this section use the same idea: partitionner the mask in two parts:
- one contains the data used one and only once,
- the other the data used at least twice.
2Q
The idea of this algorithm is to create two tails of size fixes in order to avoid the pollution of the memory hiding place. The first list, which contains the data reached only once, is managed like a list FIFO and the second like a list LRU. The first tail is also partitionnée in two under-tails A1in and A1out because the experimental results show that the optimal size of this tail strongly depends on the trace.According to John and Al, this algorithm gives better results that LRU, about 5-10%. The problem is that two tails owe beings managed as well as the migrations of the one with the other; what requires much hardware and consumes many cycles of clock and energy. These reasons explain why this algorithm does not appear in the embarked systems but is a solution used in the memories hiding places of disc.
LRU-K
This algorithm, proposed by O' Neil and Al, cuts out the memory hiding place in various groups which correspond to the lines which were reached recently between 1 and K time. The basic idea is the same one as that presented for the algorithm 2Q. A history of K last accesses of each line of the main memory must thus be maintained, which requires much logic and increases consumption notably. At the time of a defect of mask, the line to be replaced is selected by exploring these lists and by seeking the data which was not reached recently and whose K-ème access is the LRU of the list K. However, this algorithm is really justified only for the masks of important size.
See too
- Mémoire hiding place
| Random links: | Place de la Comédie | M35 (astronomy) | Roye-on-Matz | Jean d' Avila | Large bell of Bordeaux | Le_Général_entreprises_de_construction |