Skip to content

Commit 164748e

Browse files
committed
co
- cache miss - cache eviction - fully associative cache (only tag and offset) - set associative cache - cpu cache (calculate cpu cache) - direct mapped cache
1 parent 70c2471 commit 164748e

File tree

8 files changed

+66
-10
lines changed

8 files changed

+66
-10
lines changed

content/NUS/CS2100 Computer Organisation.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tags:
88
- computer_organisation
99
- boolean_algebra
1010
Creation Date: 2024-02-12, 18:18
11-
Last Date: 2024-11-09T11:18:29+08:00
11+
Last Date: 2024-11-09T17:29:51+08:00
1212
References:
1313
draft:
1414
description: Find notes and cheat sheets for NUS CS2100 on this website. Get help preparing for your final exam and answers to your questions.
@@ -199,4 +199,6 @@ title: cs2100 nus notes
199199
- [ ] [[Cache Miss]]
200200
- [ ] [[Cache Strategy]]
201201
- [ ] [[Direct Mapped Cache]]
202-
- [ ] [[Set Associative Cache]]
202+
- [ ] [[Set Associative Cache]]
203+
- [ ] [[Fully Associative Cache]]
204+
- [ ] [[Cache Eviction]]

content/OS/CPU/CPU Cache.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ Author Profile:
66
tags:
77
- OS
88
Creation Date: 2023-07-14T20:41:40+08:00
9-
Last Date: 2024-11-09T10:50:16+08:00
9+
Last Date: 2024-11-09T21:02:36+08:00
1010
References:
1111
---
1212
## Abstract
1313
---
1414
- A **small-sized** type of volatile computer memory that provides **high-speed data access** to a [[CPU]]. **10-100 times faster** than accessing accessing data from [[Main Memory]]. Built with [[Main Memory#SRAM]]
1515

16+
17+
>[!important] CPU Cache size calculation
18+
> [[Direct Mapped Cache]]: Cache size = (Number of cache blocks) × (Block size)
19+
>
20+
> [[Set Associative Cache]]: Cache size = (Number of sets) × (Associativity) × (Block size)
21+
>
22+
> [[Fully Associative Cache]]: Cache size = (Number of cache blocks) × (Block size)
23+
1624
>[!question] Differences between L1, L2, and L3 CPU Cache?
1725
> **L1 Cache** is known as **primary cache**, runs at the **same speed** as the **CPU**.
1826
>

content/OS/CPU/Cache Miss.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Author Profile:
66
tags:
77
- computer_organisation
88
Creation Date: 2024-11-06, 16:30
9-
Last Date: 2024-11-09T11:39:02+08:00
9+
Last Date: 2024-11-09T17:22:00+08:00
1010
References:
1111
draft:
1212
description:
@@ -16,6 +16,11 @@ description:
1616
- When the [[CPU]] requests data that is not found in the [[CPU Cache]]
1717
- It requires fetching the data from the slower [[Main Memory]], incurring a higher access time compared to a [[Cache Locality#Cache Hit]]
1818

19+
>[!important]
20+
> The total miss is the sum of [[#Compulsory Miss]], [[#Conflict Miss]] and [[#Capacity Miss]].
21+
>
22+
> Capacity miss is the **total miss excluding cold miss**, when **conflict miss is zero**. So capacity miss only happens on [[Fully Associative Cache]].
23+
1924
### Compulsory Miss
2025
- Also known as **cold start miss** or **first reference miss**
2126
- First time accessing the data
@@ -27,9 +32,16 @@ description:
2732
>[!important]
2833
> This can be reduced with [[Set Associative Cache]]. A [[Direct Mapped Cache]] of size $N$ has about the same miss rate as a [[Set Associative Cache|2-way set associative cache]] of size $N/2$.
2934
35+
>[!important]
36+
> For the same cache size, **conflict miss goes down** with **increasing associativity**. Conflict miss is $0$ for [[Fully Associative Cache]].
37+
38+
3039
### Capacity Miss
3140
- When data is discarded from [[CPU Cache]] as the cpu cache is running out of space
3241

42+
>[!important]
43+
> For the **same cache size**, capacity miss **remains the same irrespective of associativity**. **Capacity miss decreases** with **increasing cache size**.
44+
3345
## Cache Write Miss
3446
---
3547
- The data isn't in the [[CPU Cache]] when we want to write data back

content/OS/CPU/Direct Mapped Cache.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Author Profile:
66
tags:
77
- computer_organisation
88
Creation Date: 2024-11-09, 10:49
9-
Last Date: 2024-11-09T15:41:27+08:00
9+
Last Date: 2024-11-09T20:56:18+08:00
1010
References:
1111
draft:
1212
description:
@@ -17,6 +17,10 @@ description:
1717
+-----------------------------------------------------------+
1818
| 32-bit Address |
1919
+-----------------------+------------+----------+-----------+
20+
| Block | Offset |
21+
| Number | |
22+
| (28 bits) | (4 bits) |
23+
+-----------------------+------------+----------+-----------+
2024
| Cache | Cache | Word | Byte |
2125
| Tag | Index | Offset | Offset |
2226
| (18 bits) | (10 bits) | (2 bits) | (2 bits) |
@@ -32,5 +36,3 @@ description:
3236
> 1. We first use the **cache index to locate the cache line**
3337
> 2. We use the **valid bit** to check if the cache line contains data. If it does, and the **tag matches the given address**, we can select the word needed using the **word offset** with a help of a [[Multiplexer]]
3438
> 3. Otherwise, there is a cache miss.
35-
36-
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
Author:
3+
- Xinyang YU
4+
Author Profile:
5+
- https://linkedin.com/in/xinyang-yu
6+
tags:
7+
- computer_organisation
8+
Creation Date: 2024-11-09, 16:54
9+
Last Date: 2024-11-09T20:55:35+08:00
10+
References:
11+
draft:
12+
description:
13+
---
14+
## Abstract
15+
---
16+
![[fully_associative_cache_circuitry.png]]
17+
18+
- In a fully associative cache, a [[CPU Cache#Cache Line|cache line]] is not restricted by a cache index or cache set index and can be placed in any location. However, **memory access requires searching all cache lines**
19+
20+
>[!important]
21+
> This approach is **beneficial for very small caches**, as it eliminates [[Cache Miss#Conflict Miss|conflict misses]] by allowing data to reside anywhere within the cache, but it takes a lot more resources to locate the cache.
22+
23+
>[!important] Just consists of 2 parts
24+
> Since each cache line isn't restricted to a certain group of memory addresses, there is no cache set index or cache index. Therefore, the **block number is the same as the tag number for a fully associative cache**.

content/OS/CPU/Set Associative Cache.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Author Profile:
66
tags:
77
- computer_organisation
88
Creation Date: 2024-11-09, 10:52
9-
Last Date: 2024-11-09T15:55:20+08:00
9+
Last Date: 2024-11-09T20:51:44+08:00
1010
References:
1111
draft:
1212
description:
@@ -17,6 +17,10 @@ description:
1717
+-----------------------------------------------------------+
1818
| 32-bit Address |
1919
+-----------------------+------------+----------+-----------+
20+
| Block | Offset |
21+
| Number | |
22+
| (29 bits) | (3 bits) |
23+
+-----------------------+------------+----------+-----------+
2024
| Cache | Set | Word | Byte |
2125
| Tag | Index | Offset | Offset |
2226
| (28 bits) | (1 bits) | (1 bits) | (2 bits) |
107 KB
Loading

content/System Design/Cache/Cache Eviction.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Author Profile:
55
- https://linkedin.com/in/xinyang-yu
66
tags:
77
- system_design
8+
- computer_organisation
89
Creation Date: 2024-11-06, 17:17
9-
Last Date: 2024-11-06T17:18:26+08:00
10+
Last Date: 2024-11-09T17:44:21+08:00
1011
References:
1112
draft:
1213
description:
@@ -16,9 +17,12 @@ description:
1617
- Once the [[Cache Server]] is full, any requests to add items to the cache server might cause existing items to be **removed**
1718
- Can be handled gracefully with [[#Eviction Policy]]
1819

20+
>[!important] CPU Cache
21+
> In both [[Set Associative Cache|set-associative]] and [[Fully Associative Cache|fully associative caches]], an [[#Eviction Policy|eviction policy]] is necessary to determine which [[CPU Cache#Cache Line|cache line]] to replace when a new line needs to be loaded. This is because **multiple memory addresses can map to the same set of cache lines**. In contrast, a [[Direct Mapped Cache|direct-mapped cache]] has a **one-to-one mapping between memory addresses and cache lines**. Therefore, when a new line needs to be loaded, the existing line at that specific location is simply replaced.
22+
1923
### Eviction Policy
2024
- Strategies to handle [[Cache Eviction]]
21-
- One common strategy is [[LRU]]
25+
- One common strategy is [[LRU]] which takes advantage of [[Cache Locality#Temporal Locality]]
2226

2327
>[!important] Other common policies
2428
> **First in first out (FIFO)**

0 commit comments

Comments
 (0)