ArticleslgStudy

computer science

Cache placement policies

Cache placement policies is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Cache placement policies rather than just read about it. In short: Cache placement policies are policies that determine where a particular memory block can be placed when it goes into a CPU cache. A block of memory cannot necessarily be placed at an arbitrary location in the cache; it may be restricted to a particular cache line or a set of cache lines by the cache's placement policy.

Cache placement policies — main illustration
Cache placement policies — illustration

Key takeaways

  • Cache placement policies belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Cache placement policies to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Cache placement policies from memory before moving on to harder problems.

Reference excerpt

Cache placement policies are policies that determine where a particular memory block can be placed when it goes into a CPU cache. A block of memory cannot necessarily be placed at an arbitrary location in the cache; it may be restricted to a particular cache line or a set of cache lines by the cache's placement policy. There are three different policies available for placement of a memory block in the cache: direct-mapped, fully associative, and set-associative. Originally this space of cache organizations was described using the term "congruence mapping".

Direct-mapped cache In a direct-mapped cache structure, the cache is organized into multiple sets with a single cache line per set. Based on the address of the memory block, it can only occupy a single cache line. The cache can be framed as a n × 1 column matrix.

To place a block in the cache The set is determined by the index bits derived from the address of the memory block. The memory block is placed in the set identified and the tag is stored in the tag field associated with the set. If the cache line is previously occupied, then the new data replaces the memory block in the cache.

To search a word in the cache The set is identified by the index bits of the address. The tag bits derived from the memory block address are compared with the tag bits associated with the set. If the tag matches, then there is a cache hit and the cache block is returned to the processor. Else there is a cache miss and the memory block is fetched from the lower memory (main memory, disk).

Advantages This placement policy is power efficient as it avoids the search through all the cache lines. The placement policy and the replacement policy is simple. Simple and low-cost hardware can be used, as only one tag needs to be checked at a time.

Disadvantage It has lower cache hit rate, as there is only one cache line available in a set. Every time a new memory is referenced to the same set, the cache line is replaced, which causes conflict miss.

Example

Consider a main memory of 16 kilobytes, which is organized as 4-byte blocks, and a direct-mapped cache of 256 bytes with a block size of 4 bytes. Because the main memory is 16kB, we need a minimum of 14 bits to uniquely represent a memory address. Since each cache block is of size 4 bytes, the total number of sets in the cache is 256/4, which equals 64 sets. The incoming address to the cache is divided into bits for Offset, Index and Tag.

Offset corresponds to the bits used to determine the byte to be accessed from the cache line. Because the cache lines are 4 bytes long, there are 2 offset bits. Index corresponds to bits used to determine the set of the Cache. There are 64 sets in the cache, and because 2^6 = 64, there are 6 index bits. Tag corresponds to the remaining bits. This means there are 14 – (6+2) = 6 tag bits, which are stored in tag field to match the address on cache request. Below are memory addresses and an explanation of which cache line they map to:

Address 0x0000 (tag - 0b00_0000, index – 0b00_0000, offset – 0b00) corresponds to block 0 of the memory and maps to the set 0 of the cache. Address 0x0004 (tag - 0b00_0000, index – 0b00_0001, offset – 0b00) corresponds to block 1 of the memory and maps to the set 1 of the cache. Address 0x00FF (tag – 0b00_0000, index – 0b11_1111, offset – 0b11) corresponds to block 63 of the memory and maps to the set 63 of the cache. Address 0x0100 (tag – 0b00_0001, index – 0b00_0000, offset – 0b00) corresponds to block 64 of the memory and maps to the set 0 of the cache.

Fully associative cache In a fully associative cache, the cache is organized into a single cache set with multiple cache lines. A memory block can occupy any of the cache lines. The cache organization can be framed as 1 × m row matrix.

To place a block in the cache The cache line is selected based on the valid bit associated with it. If the valid bit is 0, the new memory block can be placed in the cache line, else it has to be placed in another cache line with valid bit 0. If the cache is completely occupied then a block is evicted and the memory block is placed in that cache line. The eviction of memory block from the cache is decided by the replacement policy.

To search a word in the cache The Tag field of the memory address is compared with tag bits associated with all the cache lines. If it matches, the block is present in the cache and is a cache hit. If it does not match, then it is a cache miss and has to be fetched from the lower memory. Based on the Offset, a byte is selected and returned to the processor.

Advantages Fully associative cache structure provides us the flexibility of placing memory block in any of the cache lines and hence full utilization of the cache. The placement policy provides better cache hit rate. It offers the flexibility of utilizing a wide variety of replacement algorithms if a cache miss occurs

Disadvantages The placement policy is power hungry as the comparison circuitry has to run over the entire cache to locate a block. The most expensive of all methods, due to the high cost of associative-comparison hardware.

Example Consider a main memory of 16 kilobytes, which is organized as 4-byte blocks, and a fully associative cache of 256 bytes and a block size of 4 bytes. Because the main memory is 16kB, we need a minimum of 14 bits to uniquely represent a memory address. The total number of sets in the cache is 1, and the set contains 256/4=64 cache lines, as the cache block is of size 4 bytes. The incoming address to the cache is divided into bits for offset and tag.

Offset corresponds to the bits used to determine the byte to be accessed from the cache line. In the example, there are 2 offset bits, which are used to address the 4 bytes of the cache line Tag corresponds to the remaining bits. This means there are 14 – (2) = 12 tag bits, which are stored in tag field to match the address on cache request. Since any block of memory can be mapped to any cache line, the memory block can occupy one of the cache lines based on the replacement policy.

… excerpt ends here. Continue reading the full article.

Illustrations

Cache placement policies: Fully associative cache
Fully associative cache
Cache placement policies: Set-Associative Cache
Set-Associative Cache

Worked examples

Example 1 — a first encounter with Cache placement policies

Start with the simplest possible case. Write down what Cache placement policies claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Cache placement policies before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Cache placement policies ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Cache placement policies

In research
Cache placement policies appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Cache placement policies in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Cache placement policies is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cache (computing), so understanding it makes those chapters shorter.
In everyday life
Look for Cache placement policies outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Cache placement policies” →

How to study Cache placement policies in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Cache placement policies means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Cache placement policies out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Cache placement policies in simple terms?

Cache placement policies are policies that determine where a particular memory block can be placed when it goes into a CPU cache. A block of memory cannot necessarily be placed at an arbitrary location in the cache; it may be restricted to a particular cache line or a set of cache lines by the cach…

Why does Cache placement policies matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Cache placement policies?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Cache placement policies.

Tags

  • Cache (computing)

Keep exploring