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:

    When once a certain class of people has been placed by the temporal and spiritual authorities outside the ranks of those whose life has value, then nothing comes more naturally to men than murder.
    Simone Weil (1909–1943)

    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)

    All water has a perfect memory and is forever trying to get back to where it was.
    Toni Morrison (b. 1931)