2
$\begingroup$

I know how Translation Lookaside Buffers work, and i also know we use them to improve the performance of data/program access by storing the recent page numbers - frame numbers in a memory cache. The problem is that i can't understand why frequent memory locations are acccessed in a period of time? And what was the starting point of this idea:

"Since the same memory locations are accessed frequently, We can create a place to hold the frequent translations so that make everything happen faster."

Can someone please share the knowledge behind this concept? Thanks.

$\endgroup$
  • 1
    $\begingroup$ The same observation is also behind caches. It is not so surprising that memory accesses are clustered rather than random – just think of one of the algorithms you studied in algorithms class, say (in-place) sorting. $\endgroup$ – Yuval Filmus Jun 15 '17 at 19:40
  • $\begingroup$ The technical term is "locality of reference" and specifically temporal and spatial locality of reference. $\endgroup$ – Derek Elkins Jun 16 '17 at 1:22
1
$\begingroup$

A TLB is useful for the same reason any other cache is useful: because it's very common to access the same data multiple times in quick succession. Many algorithms use the same value more than once. For example, searching requires accessing the search pattern a lot of times. Sorting a list requires comparing the same element multiple times for any (comparison-based) algorithm.

The nature of the TLB amplifies this effect because it doesn't only kick in when accessing the same data, but more generally when accessing data in the same page. This happens even when each individual bit is only accessed once. For example, consider a simple array traversal, that accesses the array elements in order. Assume that elements are smaller than one page, say $k$ elements fit in a page. Then a single MMU lookup is needed for the first element in a page, and the next $k-1$ only require a TLB lookup.

$\endgroup$
  • $\begingroup$ Does array traversal use a single MMU lookup? Also, why did you considered k-1 items in the lookaside buffer? Since they haven't been read yet. $\endgroup$ – hexpheus Jun 15 '17 at 20:38
  • $\begingroup$ @aligholamee Suppose the array starts on a page boundary for simplicity. Let's take concrete figures: 8-byte elements, 4096-byte pages. Then the first 512 iterations access elements inside the same MMU page, then the next 512 iterations access elements inside the same MMU page, etc. So remembering the physical location of the MMU page saves 511 lookups out of every 512. $\endgroup$ – Gilles Jun 15 '17 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.