<?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_2015F_Lecture_18</id>
	<title>Operating Systems 2015F Lecture 18 - 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_2015F_Lecture_18"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2015F_Lecture_18&amp;action=history"/>
	<updated>2026-04-22T13:25:15Z</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_2015F_Lecture_18&amp;diff=20388&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The video from the lecture given on November 13, 2015 [http://homeostasis.scs.carleton.ca/~soma/os-2015f/lectures/comp3000-2015f-lec18-13Nov2015.mp4 is now availabl...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2015F_Lecture_18&amp;diff=20388&amp;oldid=prev"/>
		<updated>2015-11-13T22:32:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The video from the lecture given on November 13, 2015 [http://homeostasis.scs.carleton.ca/~soma/os-2015f/lectures/comp3000-2015f-lec18-13Nov2015.mp4 is now availabl...&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 video from the lecture given on November 13, 2015 [http://homeostasis.scs.carleton.ca/~soma/os-2015f/lectures/comp3000-2015f-lec18-13Nov2015.mp4 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 18&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Virtual Memory&lt;br /&gt;
&lt;br /&gt;
swapping, er...paging&lt;br /&gt;
&lt;br /&gt;
Swapping technically means writing currently running program to disk and loading another one to run&lt;br /&gt;
&lt;br /&gt;
Paging means moving pages out of RAM and onto disk&lt;br /&gt;
&lt;br /&gt;
Question: why does linux use much more than the bare minimum of RAM?  What is it doing with all of that extra memory?&lt;br /&gt;
&lt;br /&gt;
Answer: very aggressive caching of disk contents&lt;br /&gt;
&lt;br /&gt;
Problem: But what if I need more RAM for programs?&lt;br /&gt;
&lt;br /&gt;
Need algorithms for moving pages between RAM and disk&lt;br /&gt;
&lt;br /&gt;
Types of page contents:&lt;br /&gt;
* Program data&lt;br /&gt;
* Program code&lt;br /&gt;
* File contents&lt;br /&gt;
&lt;br /&gt;
Note that program code is also (read only) file contents&lt;br /&gt;
&lt;br /&gt;
Really, you have:&lt;br /&gt;
1. File contents, read only&lt;br /&gt;
2. File contents, read write&lt;br /&gt;
3. Program data&lt;br /&gt;
&lt;br /&gt;
You need more RAM.  What do you kick out first?&lt;br /&gt;
 - not such an easy question!&lt;br /&gt;
&lt;br /&gt;
Kick out (evict) read only file contents first&lt;br /&gt;
Pro: we don&amp;#039;t have to write anything to disk!&lt;br /&gt;
Con: Hey, I was running that code!&lt;br /&gt;
&lt;br /&gt;
Evict read write file contents&lt;br /&gt;
Pro: hey they are supposed to go to disk anyway, go ahead and write it&lt;br /&gt;
Con: but we have to wait for it to be written first&lt;br /&gt;
&lt;br /&gt;
Evict program data...to swap&lt;br /&gt;
Pro: Hey, we didn&amp;#039;t need that data anyway&lt;br /&gt;
Con: Hey, we *did* need that data!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hardware helps with the decision on what pages can be kicked out&lt;br /&gt;
* accessed bit&lt;br /&gt;
* dirty bit&lt;br /&gt;
&lt;br /&gt;
Ideal eviction targets are pages with accessed bit clear and dirty bit clear (a clean, non-accessed page)&lt;br /&gt;
&lt;br /&gt;
Next eviction target is non-accessed dirty pages.  Save them to disk then evict&lt;br /&gt;
&lt;br /&gt;
After evict accessed but clean pages...but this is bad if done frequently (system is &amp;quot;thrashing&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Dirty pages are easy - just have a process constantly writing dirty pages to disk, thus &amp;quot;cleaning&amp;quot; them&lt;br /&gt;
  - sweeps through memory periodically looking for dirty pages&lt;br /&gt;
&lt;br /&gt;
Ideally what you&amp;#039;d want is a timestamp of last access for every page&lt;br /&gt;
&lt;br /&gt;
For accessed bits, periodically sweep through memory setting accessed bits to 0.  If it is 1, then you know the page has been accessed since the last sweep.&lt;br /&gt;
&lt;br /&gt;
These &amp;quot;sweep&amp;quot; type algorithms are called clock algorithms because you can think of the pages as positions on a very very big clock, with a hand moving from one to the next.&lt;br /&gt;
&lt;br /&gt;
Page replacement algorithms can get very complex because, in their ideal form, they predict the future.  Best approximation is a bunch of heuristics and adaptive mechanisms based on past behavior.&lt;br /&gt;
&lt;br /&gt;
But page replacement needs to be reasonable, especially on systems with no swap&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When a program asks for memory, how do you know if you have enough?  When do you say no?&lt;br /&gt;
&lt;br /&gt;
Conservative way: find pages for every byte requested, return yes only once you&amp;#039;ve allocated it all&lt;br /&gt;
&lt;br /&gt;
Linux kernel is not conservative at all&lt;br /&gt;
&lt;br /&gt;
Example: fork&lt;br /&gt;
 - logically, doubles RAM usage&lt;br /&gt;
 - at least, doubles program data RAM usage&lt;br /&gt;
 - but in practice it generally only causes a modest increase in RAM usage&lt;br /&gt;
&lt;br /&gt;
Example: malloc&lt;br /&gt;
 - are you really going to use all that memory at once?&lt;br /&gt;
&lt;br /&gt;
Linux kernel memory allocation is like banking&lt;br /&gt;
 - gives out loans at a drop of the hat, takes deposits...&lt;br /&gt;
 - assumes everyone won&amp;#039;t want their money at once&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>