A cache mapping process refers to the process of moving data from main memory to cache memory.
Cache hit
If there is a cache hit, word is fetched from cache memory to the CPU.
Cache miss
If there is a cache miss, word is searched in the memory, than its copied from main memory to the cache memory.
Mapping methods are:
- Associative mapping
- Direct mapping
- Self-associative mapping
1. Associative mapping
In associative mapping, word and its address is stored in the cache.
Working of associative mapping:
- CPU search address bit in the cache memory.
- If address is matched, than word is fetched to the CPU.
- IF address not matched in cache memory, than its searched in main memory.
- Than word with address is copied in to the cache memory.
- If cache is full than existing word with its address is removed to make space for the new word and its address.
2. Direct mapping
In direct mappping technique, the number of bit address send by CPU is divided into two parts, called
- tag field
- index field
Number of index field bits = bits required to address in cache.
If in a computer system, number of bits address sent by CPU is 12.
And, index field = 10 bits
than, tag field = 2 bits.
In a Direct mapping technique, cache memory store word and tag field.
Word will be stored in index field.
Working of direct mapping:
- When an address is sent by the CPU, the index part of the address is used to get a memory location in the cache.
- When an address is sent by the CPU, the index part of the address is used to get a memory location in the cache.
- If tag does not match, the word is searched in the main memory.
- When a word is copied from main memory to cache memory, the address in main memory is split into index and tag fields.
3. Set associative mapping
Drawback of direct mapping : Two words with same index but different tag cannot be stored into cache at the same time.
Set associative mapping is an improvement of this drawback.
In set associative mapping, each word of cache can store two or more words of main memory under the same index address.
Set associative mapping combines direct mapping with fully associative mapping by arrangement lines of a cache into sets.