Locality of Reference - Use of Spatial and Temporal Locality: Hierarchical Memory

Use of Spatial and Temporal Locality: Hierarchical Memory

Hierarchical memory is a hardware optimization that takes the benefits of spatial and temporal locality and can be used on several levels of the memory hierarchy. Paging obviously benefits from temporal and spatial locality. A cache is a simple example of exploiting temporal locality, because it is a specially designed faster but smaller memory area, generally used to keep recently referenced data and data near recently referenced data, which can lead to potential performance increases. Data in cache does not necessarily correspond to data that is spatially close in main memory; however, data elements are brought into cache one cache line at a time. This means that spatial locality is again important: if one element is referenced, a few neighboring elements will also be brought into cache. Finally, temporal locality plays a role on the lowest level, since results that are referenced very closely together can be kept in the machine registers. Programming languages such as C allow the programmer to suggest that certain variables are kept in registers.

Data locality is a typical memory reference feature of regular programs (though many irregular memory access patterns exist). It makes the hierarchical memory layout profitable. In computers, memory is divided up into a hierarchy in order to speed up data accesses. The lower levels of the memory hierarchy tend to be slower, but larger. Thus, a program will achieve greater performance if it uses memory while it is cached in the upper levels of the memory hierarchy and avoids bringing other data into the upper levels of the hierarchy that will displace data that will be used shortly in the future. This is an ideal, and sometimes cannot be achieved.

Typical memory hierarchy (access times and cache sizes are approximations of typical values used as of 2006 for the purpose of discussion; actual values and actual numbers of levels in the hierarchy vary):

  • CPU registers (8-128 registers) – immediate access
  • L1 CPU caches (32 KiB to 512 KiB) – fast access
  • L2 CPU caches (128 KiB to 24 MiB) – slightly slower access
  • Main physical memory (RAM) (256 MiB to 64 GiB) – slow access
  • Disk (file system) (100 GiB to 10 TiB) – very slow
  • Remote Memory (such as other computers or the Internet) (Practically unlimited) – speed varies

Modern machines tend to read blocks of lower memory into the next level of the memory hierarchy. If this displaces used memory, the operating system tries to predict which data will be accessed least (or latest) and move it down the memory hierarchy. Prediction algorithms tend to be simple to reduce hardware complexity, though they are becoming somewhat more complicated.

Read more about this topic:  Locality Of Reference

Famous quotes containing the words temporal, hierarchical and/or memory:

    Listen to any musical phrase or rhythm, and grasp it as a whole, and you thereupon have present in you the image, so to speak, of the divine knowledge of the temporal order.
    Josiah Royce (1855–1916)

    Authority is the spiritual dimension of power because it depends upon faith in a system of meaning that decrees the necessity of the hierarchical order and so provides for the unity of imperative control.
    Shoshana Zuboff (b. 1951)

    With the holders holding my hand nearing the call of the bird,
    Comrades mine and I in the midst, and their memory ever to keep, for the dead I loved so well,
    For the sweetest, wisest soul of all my days and
    lands—and this for his dear sake,
    Lilac and star and bird twined with the chant of my soul,
    There in the fragrant pines and the cedars dusk and dim.
    Walt Whitman (1819–1892)