13

I'm a little confused by the meaning of "Aliasing" between CPU-cache and Physical address. First I found It's definition on Wikipedia :

However, VIVT suffers from aliasing problems, where several different virtual addresses may refer to the same physical address. Another problem is homonyms, where the same virtual address maps to several different physical addresses.

but after a while I saw a different definition on a presentation(ppt) of DAC'05: "Energy-Efficient Physically Tagged Caches for Embedded Processors with Virtual Memory"

Cache aliasing and synonyms:

Alias: Same virtual address from different contexts mapped to different physical addresses Synonym: Different virtual address mapped to the same physical address (data sharing)

As I'm not a native speaker, I don't know which is correct, though I feel the Wiki's definition is correct.

Edit:

Concept of "aliasing" in CPU cache usually means "synonym", on the contrary is "homonym". In a more generic level, "aliasing" is "confusing" or "chaos" or something like that. So In my opinion, "aliasing" exactly means the mapping of (X->Y) is "not bijective", where

"X" = the subset of physical addresses units which has been cached. (each element is a line of byte)

"Y" = the set of valid cache lines. (elements a also "line")

wuxb
  • 2,572
  • 1
  • 21
  • 30

2 Answers2

14

You'd need to learn about Virtual Memory first, but basically it's this:

  • The memory addresses your program uses aren't the physical addresses that the RAM uses; they're virtual addresses mapped to physical addresses by the CPU.

  • Multiple virtual addressses can point to the same physical address.

That means that you can have two copies of the same data in separate parts of the cache without knowing it... and they wouldn't be updated correctly, so you'd get wrong results.


Edit:

Exerpt of reference:

Cache aliasing occurs when multiple mappings to a physical page of memory have conflicting caching states, such as cached and uncached. Due to these conflicting states, data in that physical page may become corrupted when the processor's cache is flushed. If that page is being used for DMA by a driver, this can lead to hardware stability problems and system lockups.


For those who are still unconvinced:

On ARMv4 and ARMv5 processors, cache is organized as a virtual-indexed, virtual-tagged (VIVT) cache in which both the index and the tag are based on the virtual address. The main advantage of this method is that cache lookups are faster because the translation look-aside buffer (TLB) is not involved in matching cache lines for a virtual address. However, this caching method does require more frequent cache flushing because of cache aliasing, in which the same physical address can be mapped to multiple virtual addresses.

Community
  • 1
  • 1
user541686
  • 205,094
  • 128
  • 528
  • 886
  • I don't see how this answers the question at all. OP wants to know if aliasing means "the same virtual addrs (in different contexts) are mapped to different physical locations" or "multiple virtual addrs are mapped to a single physical location". I suspect the answer is "both", but don't have a reference for it. – John L May 10 '11 at 08:26
  • 2
    Can you explain to me which of above two definition is wrong? – wuxb May 10 '11 at 08:26
  • @John, @Wu: I believe Wikipedia's correct. Aliasing is a problem with the correctness of a single program, and explanation 2 doesn't make sense for that. – user541686 May 10 '11 at 08:29
  • to John: since "Homonym" and "Synonym" cannot be homonym and synonym, I think only one can be correct. – wuxb May 10 '11 at 08:29
  • @Wu, @John: See my source. :) – user541686 May 10 '11 at 08:30
  • @Mehrdad: your updated ref is a description of a BUG, It says that on "multiple mappings to a physical page of memory have conflicting caching states" circumstances, A "cache aliasing" occurred. I think it means "cache state aliasing" not the "cache address aliasing". also It's not a description not a definition. :) – wuxb May 10 '11 at 08:42
  • @Wu: I've never heard of "cache state aliasing" or "cache address aliasing"; *all* of the sources here agree that it's just called "cache aliasing", and the NVIDIA paper confirms what it means. *Why* they wrote the paper doesn't affect the validity of what it says. :P – user541686 May 10 '11 at 08:46
  • for "cache state aliasing" it means multiple cache line in a "page" has different state. so you cannot tell if the page is hit or not hit, it's a mix state. we can call it "confusing state".. "cache address aliasing" means a physical address has multiple virtual-addresses and more than one of them are cached. It is different meanings. – wuxb May 10 '11 at 08:53
  • @Mehrdad: I argee to "the same physical address can be mapped to multiple virtual addresses " in your second update. :) while nVIDIA's works it's another question. – wuxb May 10 '11 at 08:57
  • @Wu: This is the first time I'm hearing of the difference; do you have a reference? – user541686 May 10 '11 at 08:58
  • @Mehrdad : that is my explanation, not a formal definition. Think: does "page" really matters in caching? – wuxb May 10 '11 at 09:06
  • @Wu: I'm not exactly understanding what you mean by "cache state aliasing" (not sure how it relates to anything here), but AFAIK what we're all talking about is "cache [address] aliasing". – user541686 May 10 '11 at 09:08
  • @Mehrdad: thanks for the edits, answer is much improved now. Here's yet another usage of "cache aliasing" http://docs.hp.com/en/B3906-90005/ch07s09.html, referring to a situation where different virtual addresses occupy the same cache line (physical location is irrelevant). I would still maintain that even "cache aliasing" has different meanings in different contexts, such as which arch is under consideration. – John L May 10 '11 at 10:04
  • @Mehrdad: Well, All of us are not confused by "cache [address] aliasing". :) – wuxb May 10 '11 at 10:24
  • Guys, aliasing in virtual spaces is not related to caches at a first order. Lets not confuse the two. Aliasing is often intentional and exists when for several reasons, one is to have pages shared among multiple processes, e.g., dll or .so shared objects in Windows and Linux respectively. – Aater Suleman May 10 '11 at 15:58
  • : Aiasing in cache is a totally different issue. Whether or not aliasing in Virtual space leads to two copies of the line in a cache depends on how your cache is indexed. If your cache is Virtually-indexed (as in ARM) then you have that problem. Caches can be physically indexed and the problem goes away which is why Intel does it that way). This is a very long discussion on how all this is designed. – Aater Suleman May 10 '11 at 16:03
7

@Wu yes you do need to understand virtual memory little to understand aliasing. Let me give you a few lines of explanation first:

Lets say I have a RAM (physical memory) of 1GB. I want to present my programmer with a view that I have 4GB memory then I use virtual memory. In virtual memory, the programmer thinks that he/she has 4GB and writes their program from that perspective. They do not need to know how much physical memory exists. The advantage is that program will run on computers with different amounts of RAM. Also, the program can run on a computer together with other programs (also consuming physical memory).

So here is how virtual memory is implement. I will give a simple 1-level virtual memory system (Intel has a 2/3-level system which just makes it complicated for explanation.

Our problem here is that the programmer has 4 Billion addresses and we only have 1 billion places to put those 4 billion addresses. So, addresses are from the virtual address space need to be mapped to physical address space. This is done using a simple index table called a Page Table. You access a Page Table with a virtual address and it gives you the physical address of that memory location.

Some details: Remember that physical space is only 1GB so the system only keeps the most recently accessed 1GB worth in physical memory and keeps the rest in system disk. When the program requests a particular address, we first check if it is already in physical memory. If so, it is returned to the program. If not, it brought from the disk and put into physical memory and then returned to the program. The latter is known as a Page Fault.

Coming back to aliasing in context of virtual memory: since there is mapping between virtual -> physical addresses, it is possible to make two virtual addresses to map to the same physical address. it is the same as saying that if I look at my page table for virtual address X and Y, I will get the same physical address in BOTH cases.

I show below a simple example of a 8 entry Page Table. Say there are 8 vitual addresses and only 3 physical addresses. The page table looks as follows:


     0:    1
     1:   On disk
     2:    2
     3:    1
     4:   On disk
     5:   On disk
     6:   On disk
     7:    0


This mean that if virtual address 4 is accessed, you will get a page fault. 
If virtual addresses 3 is accessed, you will get the physical address 1
In this case, virtual addresses 0 and 3 are aliasing to the same physical address 1 for both of them

NOTE: I used the terms physical and virtual addresses everywhere to simplify the concept. In a real system, the virtual-to-physical mapping is not on a per address basis . Instead, we map chunks of virtual space to physical space. Each chunk is called a Page (thats why the mapping table is called a page table) and the size of the chunk is a property of the ISA, e.g., Intel x86 has 4Kbyte pages.

Aater Suleman
  • 2,286
  • 18
  • 11
  • page table sure is. but in cache there cannot be more than 1 online, OS will make a context switch so the cache will be flushed and then be refilled(later enough) with another v-tag. – wuxb May 10 '11 at 17:17
  • Thats not true actually. OS doesn't need to do a flush on every context switch. Cache are often shared among different contexts, e.g., machines with support for SMT allow two processes to run concurrently on the same core which means a context switch doesn't require a cache line flush. Caches do need to be flushed when the page table changes, which is a result of a page fault. – Aater Suleman May 10 '11 at 17:23
  • do you argee that in my last reply "later enough" has the same meaning? Make it more clearly, OS will make a context switch so correct cache update will be ready to perform. – wuxb May 11 '11 at 04:51