vault backup: 2025-05-05 04:53:58

This commit is contained in:
Boyan 2025-05-05 04:53:58 +02:00
parent df6a389528
commit aa6547aa28
4 changed files with 130 additions and 19 deletions

View File

@ -11,29 +11,42 @@
"id": "46800597ab6eb156", "id": "46800597ab6eb156",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "markdown", "type": "image",
"state": { "state": {
"file": "Operating Systems/Memory Management.md", "file": "Operating Systems/assets/Pasted image 20250505042548.png"
"mode": "source",
"source": false
}, },
"icon": "lucide-file", "icon": "lucide-image",
"title": "Memory Management" "title": "Pasted image 20250505042548"
} }
}, },
{ {
"id": "33dc0f1ebcbf4c21", "id": "33dc0f1ebcbf4c21",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "release-notes", "type": "image",
"state": { "state": {
"currentVersion": "1.8.10" "file": "Operating Systems/assets/Pasted image 20250505042548.png"
}, },
"icon": "lucide-book-up", "icon": "lucide-image",
"title": "Release Notes 1.8.10" "title": "Pasted image 20250505042548"
}
},
{
"id": "565b9e04e8704d81",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "Operating Systems/Virtual Memory.md",
"mode": "source",
"source": false
},
"icon": "lucide-file",
"title": "Virtual Memory"
} }
} }
] ],
"currentTab": 2
} }
], ],
"direction": "vertical" "direction": "vertical"
@ -210,13 +223,17 @@
"omnisearch:Omnisearch": false "omnisearch:Omnisearch": false
} }
}, },
"active": "46800597ab6eb156", "active": "565b9e04e8704d81",
"lastOpenFiles": [ "lastOpenFiles": [
"Operating Systems/Overview.md",
"Operating Systems/Processes and Threads.md",
"Operating Systems/Scheduling.md", "Operating Systems/Scheduling.md",
"Operating Systems/Inter-Process Communication.md", "Operating Systems/Processes and Threads.md",
"Operating Systems/Memory Management.md", "Operating Systems/Memory Management.md",
"Operating Systems/Inter-Process Communication.md",
"Operating Systems/Virtual Memory.md",
"Operating Systems/assets/Pasted image 20250505042548.png",
"Operating Systems/assets/Pasted image 20250505042419.png",
"Operating Systems/assets/Pasted image 20250204103541.png",
"Operating Systems/Overview.md",
"Operating Systems/assets/Pasted image 20250502183523.png", "Operating Systems/assets/Pasted image 20250502183523.png",
"Operating Systems/assets/Pasted image 20250502183221.png", "Operating Systems/assets/Pasted image 20250502183221.png",
"Operating Systems/assets/Pasted image 20250502183310.png", "Operating Systems/assets/Pasted image 20250502183310.png",
@ -225,12 +242,9 @@
"Operating Systems/assets/Pasted image 20250502183002.png", "Operating Systems/assets/Pasted image 20250502183002.png",
"Operating Systems/assets/Pasted image 20250502182934.png", "Operating Systems/assets/Pasted image 20250502182934.png",
"README.md", "README.md",
"Pasted image 20250502182936.png",
"Untitled.canvas", "Untitled.canvas",
"Discrete Structures/Midterm/attempt 2.md", "Discrete Structures/Midterm/attempt 2.md",
"Discrete Structures/Mathematical Data Structures.md", "Discrete Structures/Mathematical Data Structures.md",
"Operating Systems/assets/image.png",
"Operating Systems/assets/Pasted image 20250502181012.png",
"unicef.org.md", "unicef.org.md",
"Linear Algebra/Matrices.md", "Linear Algebra/Matrices.md",
"Languages & Machines/Regular languages.md", "Languages & Machines/Regular languages.md",
@ -248,7 +262,6 @@
"Functional Programming/Recursion.md", "Functional Programming/Recursion.md",
"Functional Programming/Lists.md", "Functional Programming/Lists.md",
"Functional Programming/Eq and Num.md", "Functional Programming/Eq and Num.md",
"Functional Programming/Introduction to Functional Programming.md",
"Languages & Machines/assets", "Languages & Machines/assets",
"Languages & Machines", "Languages & Machines",
"Extracurricular/Misc/Proposed Routine Plan.canvas", "Extracurricular/Misc/Proposed Routine Plan.canvas",

View File

@ -0,0 +1,98 @@
---
type: theoretical
backlinks:
- "[[Memory Management]]"
---
Separating logical memory from physical memory.
- Allows **very large** virtual memory, when only a smaller physical memory is available
The **virtual address space** of a process refers to the logical view of how a process is stored
## Implementation
Maintain a copy of the process (including code,data heap and stack segments) in a special area of the HDD named **virtual memory**
> [!IMPORTANT]- Refresher - code, data, heap and stack segments
> ![](Pasted%20image%2020250505042419.png)
>[!NOTE]- Another refresher - stack vs. heap allocation
> ![](Pasted%20image%2020250505042548.png)
- Process is divided into pages
- If a page is referred to, it is brought into main memory (**DEMAND PAGING**)
## Page faults
When a page is referenced but not present in memory - a main memory access is required.
## Page replacement
The act of replacing a frame in memory with another one (which we need) from the main memory.
### Basic Page Replacement
Linear search for free frame, if none -> select victim page via **a page replacement algorithm** and do your thing!
## Typical pages
Contain:
- A P (or V for valid) bit -> page is in RAM (else page fault)
- M (dirty) bit - page in RAM modified
- R bit - referenced since last time R was cleared
## Beladys Anomaly
Increasing the number of page frames (or memory pages) allocated to a process can lead to an increase in the number of page faults, rather than a decrease.
## Frame-allocation algorithms
How many frames to give to each process
### Fixed
Each process receives the same number of frames -> **Equal Allocation**
### Proportional
Allocate according to size of process.
## Page-replacement algorithms
Which page to replace, optimizing for lowest page fault rate.
### FIFO
Read title.
### Least Recently Used (LRU)
Replace page that has not been used recently.
**Counter**:
- Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter.
- When a page is to be changed, find smallest value in counters.
**Stack**:
- Keep a stack of page numbers in a double link form[^1]
- On page reference - move to top
### LRU Approximation
Since LRU is slow as shit, we need an approximation.
We introduce a **Reference bit**:
- Each page has `R = 0` at first
- Whenever referenced `R = 1`
- Replace any page with `R = 0`
#### Second-chance (Clock)
Do the above. It's called a clock cuz it's like a `itertools.cycle()`. It holds the state of last accessed page (clock hand) and moves on from there on next iteration.
## The Working Set Model
We want to have the set of pages "in use" in RAM!
- Working set changes over time
- Usually approximated by the set of pages used by some amount of most recent references
## Thrashing
When a process is busy swapping pages.
Multiprogramming[^2] is high, CPU utilization[^3] is low.
### Solving it
Give the process(es) more memory by:
- Taking it from another process
- Swap out shit until demand is lower (scheduler)
## Prepaging
---
[^1]: Doubly-linked list where we can go `prev` and `next`
[^2]: Many processes wanting resources
[^3]: Shit actually happening

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB