FACTOID # 107: At least 9 out 10 Nigerians attend church regularly. Only 4 out of 10 Americans claim to do so.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Memory locality

Memory Locality is a term in computer science used to denote the temporal or spatial proximity of memory access.


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, it is to a programmer's advantage to use memory while it is cached in the upper levels of the memory hierarchy and to avoid bringing other data into the upper levels of the hierarchy while displacing data that will be used shortly in the future. This is an ideal, and sometimes cannot be achieved.


Memory Hierarchy (access times are approximations for the purpose of discussion. Actual values and actual numbers of levels in the hierarchy may vary):

  • CPU registers (8-32 registers), -- immediate access (0-1 cpu cycles)
  • L1 and L2 caches (128K-1MB), -- slightly slower access (10 cpu cycles)
  • Main memory (RAM) (128MB-2GB), -- slow access (100 cpu cycles)
  • Disk (Swap memory and file system), (1GB-1TB) -- very slow (1000-10,000 cycles)
  • 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.


A common example is matrix multiplication:

 for i in 0..n for j in 0..m for k in 0..p C[i][j] = C[i][j] + A[i][k] * B[k][j]; 

When dealing with large matrices, this algorithm tends to shuffle data around too much. Since memory is pulled up the hierarch in consecutive address blocks, in the C language it would be advantageous to refer to several memory addresses that share the same row (spatial locality). By keeping the row number fixed, the second element changes more rapidly. In C and C++, this means the memory addresses are used more consecutively. One can see that since j affects the column reference of both matrices C and B, it should be iterated in the innermost loop (this will fix the row iterators, i and k, while j move across each column in the row). This will not change the mathematical result, but it improves efficiency. By switching the looping order for j and k, the speedup in large matrix multiplications becomes dramatic. (In this case, 'large' means, approximately, more than 100,000 elements in each matrix, or enough addressable memory such that the matrices will not fit in L1 and L2 caches)


Temporal locality can also be improved in the above example by using a technique called blocking. The larger matrix can be divided into evenly sized sub-matrices, so that the smaller blocks can be referenced (multiplied) several times while in memory.

 for (ii = 0; ii < SIZE; ii += BL_SIZE) for (kk = 0; kk < SIZE; kk += BL_SIZE) for (jj = 0; jj < SIZE; jj += BL_SIZE) for (i = ii; i < ii + BL_SIZE; i++) for (k = kk; k < kk + BL_SIZE; k++) for (j = jj; j < jj + BL_SIZE; j++) C[i][j] = C[i][j] + A[i][k] * B[k][j]; 


(Diagrams needed for visualizations)


The temporal locality of the above solution is provided because a block can be used several times before moving on, so that it is moved in and out of memory less often. Spatial locality is improved because elements with consecutive memory addresses tend to be pulled up the memory hierarchy together.


  Results from FactBites:
 
Garbage Collection Techniques to Enhance Memory Locality in Java Programs (1710 words)
Dynamic memory allocation and GC often have negative effects on the placement of data in memory, and, therefore, the memory locality properties.
On modern systems, memories are organized in a hierarchy, from the top of the pyramid, the small and fast memory, to the bottom, the larger and slower memories, i.e.
As memory allocation and GC are critical to memory management and the locality, we think this research would be of valuable significance in improving system performance for Java programs (and possibly other object oriented languages).
CmpSci 535 Lecture 9 (6611 words)
The memory hierarchy is viable because programs tend to exhibit a property known as locality.
The hit ratio is an important measure of the performance of a memory level and is the probability that a reference is to a value already in a given level of the hierarchy.
Memory accesses can be pipelined so that the rate of data transfer is maintained, but when loads or stores occur in isolation and there are no independent operations to fill the resulting delay, then the CPU sees a memory wait state and is effectively slowed down by the mapping.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.