Least recently used algorithm to compute best memory layout