<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019W_Lecture_14</id>
	<title>Operating Systems 2019W Lecture 14 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019W_Lecture_14"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_14&amp;action=history"/>
	<updated>2026-04-05T17:00:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_14&amp;diff=22222&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The lecture given on March 6, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec14-20190306.m4v is now available].  ==Notes==  &lt;pr...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019W_Lecture_14&amp;diff=22222&amp;oldid=prev"/>
		<updated>2019-03-06T22:29:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The lecture given on March 6, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec14-20190306.m4v is now available].  ==Notes==  &amp;lt;pr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The lecture given on March 6, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec14-20190306.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 14&lt;br /&gt;
----------&lt;br /&gt;
Virtual memory!&lt;br /&gt;
&lt;br /&gt;
every process has its own virtual address space&lt;br /&gt;
&lt;br /&gt;
on every memory access, each virtual address is translated into a physical address&lt;br /&gt;
&lt;br /&gt;
The kernel must keep track of these per-process virtual-&amp;gt;physical address mappings&lt;br /&gt;
&lt;br /&gt;
Theoretically, you could have a table mapping each virtual address to each physical address&lt;br /&gt;
&lt;br /&gt;
Mappings on a per-byte basis would be *way* too inefficient&lt;br /&gt;
&lt;br /&gt;
process memory is divided into fixed-sized pages&lt;br /&gt;
 - normally 4K&lt;br /&gt;
 - but sometimes also really large (2M+) for special purposes&lt;br /&gt;
&lt;br /&gt;
Before pages, there were segments&lt;br /&gt;
&lt;br /&gt;
Segments have a base address and a bound (size)&lt;br /&gt;
 - variable length&lt;br /&gt;
 - typically had a semantic purpose (code, data, stack, etc)&lt;br /&gt;
&lt;br /&gt;
Segment terminology still used when discussing parts of an executable&lt;br /&gt;
 (e.g. parts of an ELF file)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You could relocate segments&lt;br /&gt;
 - all memory accesess could be relative to a &amp;quot;base&amp;quot; register&lt;br /&gt;
&lt;br /&gt;
But the world moved to a &amp;quot;flat&amp;quot; memory model (i.e. no segments)&lt;br /&gt;
 - segments can be confusing when they overlap&lt;br /&gt;
 - but the real problems is external fragmentation&lt;br /&gt;
&lt;br /&gt;
internal fragmentation&lt;br /&gt;
 - space lost when allocating using fixed-sized chunks (e.g., 4K at a time)&lt;br /&gt;
&lt;br /&gt;
external fragmentation&lt;br /&gt;
 - space divided into discontiguous chunks&lt;br /&gt;
 - cannot make larger contiguous allocations&lt;br /&gt;
 - happens when using variable-sized memory allocations&lt;br /&gt;
&lt;br /&gt;
XXX....XXXX...XXXX&lt;br /&gt;
&lt;br /&gt;
7 units available&lt;br /&gt;
4 is the largest contiguous piece&lt;br /&gt;
&lt;br /&gt;
what if an allocation for 6 comes in?&lt;br /&gt;
&lt;br /&gt;
Only way would be to compact memory - move things around until you got&lt;br /&gt;
a large enough contiguous block&lt;br /&gt;
&lt;br /&gt;
Virtual memory is a solution for the external fragmentation problem&lt;br /&gt;
 - virtual addresses can be contiguous even when physical addresses aren&amp;#039;t&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To make virtual memory work, we need a mapping of virtual to physical&lt;br /&gt;
addresses at a page-level resolution&lt;br /&gt;
&lt;br /&gt;
 4K =&amp;gt; 4K&lt;br /&gt;
&lt;br /&gt;
********&lt;br /&gt;
&lt;br /&gt;
Sidebar: the memory hierarchy&lt;br /&gt;
 - fastest: small &amp;amp; volatile&lt;br /&gt;
 - slowest: large &amp;amp; persistent&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
PROGRAMMER/COMPILER/HARDWARE MANAGED&lt;br /&gt;
 CPU registers&lt;br /&gt;
&lt;br /&gt;
HARDWARE MANAGED&lt;br /&gt;
 TLB&lt;br /&gt;
 CPU cache (L1) &amp;lt;- smallest, fastest&lt;br /&gt;
 CPU cache (L2)&lt;br /&gt;
 CPU cache (L3) &amp;lt;- often shared between cores&lt;br /&gt;
&lt;br /&gt;
OS MANAGED - Virtal memory&lt;br /&gt;
 DRAM&lt;br /&gt;
--------&lt;br /&gt;
XPoint?&lt;br /&gt;
&lt;br /&gt;
OS MANAGED - filesystems&lt;br /&gt;
 SSD/flash memory&lt;br /&gt;
 Spinning Hard drives&lt;br /&gt;
&lt;br /&gt;
APP MANAGED&lt;br /&gt;
 Tapes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
****************&lt;br /&gt;
&lt;br /&gt;
 4K Page (virtual memory) -&amp;gt; 4K frame (physical memory)&lt;br /&gt;
&lt;br /&gt;
This mapping will be used by the CPU, but managed by the OS&lt;br /&gt;
&lt;br /&gt;
*Page tables* do this mapping&lt;br /&gt;
 - but it is more a (very wide) tree, not a table&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
851F1   521  &amp;lt;- 32 bit virtual address&lt;br /&gt;
 ^       ^&lt;br /&gt;
page#   page offset&lt;br /&gt;
&lt;br /&gt;
I just need to translate the page # to a frame #&lt;br /&gt;
&lt;br /&gt;
use the frame # plus the page offset to get the physical address&lt;br /&gt;
&lt;br /&gt;
upper 20 bits: page number&lt;br /&gt;
lower 12 bits: page offset&lt;br /&gt;
&lt;br /&gt;
need a way to translate 20 bits (page #) to 20 bits (frame #)&lt;br /&gt;
&lt;br /&gt;
Could just use an array with 2^20 entries&lt;br /&gt;
&lt;br /&gt;
But most processes only need a small fraction of 2^20 entries&lt;br /&gt;
 - so we want a sparse data structure&lt;br /&gt;
&lt;br /&gt;
Remember we want to do all memory allocation in 4K chunks - even for the page table!&lt;br /&gt;
&lt;br /&gt;
How many mappings can I store in 4K?&lt;br /&gt;
&lt;br /&gt;
I can store 1024 (1K) 32-bit entries in 4K&lt;br /&gt;
&lt;br /&gt;
1024 = 2^10&lt;br /&gt;
&lt;br /&gt;
1st level page table: 1024 entries for 2nd-level page tables (PTEs)&lt;br /&gt;
&lt;br /&gt;
each 2nd level page table: 1024 entries for pages (PTEs)&lt;br /&gt;
&lt;br /&gt;
* We can have up to 1024 2nd level page tables, giving us 2^20 entries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But we&amp;#039;re missing something&lt;br /&gt;
 - how many memory accesses do we need to resolve one address?!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TLB: &amp;quot;translation lookaside buffer&amp;quot;&lt;br /&gt;
 - caches virtual-&amp;gt;physical mappings (PTEs)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Page table entries have frame #&amp;#039;s AND metadata&lt;br /&gt;
 - valid?&lt;br /&gt;
 - modified? (dirty)&lt;br /&gt;
 - accessed? (recently)  &amp;lt;--- NOT a time stamp&lt;br /&gt;
 - permission bits: rwx&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Does the CPU or OS manage TLB entries?&lt;br /&gt;
 - depends on the architecture&lt;br /&gt;
 - most nowadays have the CPU walk the page table&lt;br /&gt;
&lt;br /&gt;
How does mmap work in this?&lt;br /&gt;
&lt;br /&gt;
Lazy allocation&lt;br /&gt;
 - pages are allocated on demand&lt;br /&gt;
 - disk is read on demand&lt;br /&gt;
&lt;br /&gt;
Lazy allocation allows for aggressive file caching and memory overcommitment&lt;br /&gt;
 - improving performance in general but can lead to bad situations&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>