<?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_2019F_Lecture_19</id>
	<title>Operating Systems 2019F Lecture 19 - 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_2019F_Lecture_19"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019F_Lecture_19&amp;action=history"/>
	<updated>2026-06-03T00:41: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_2019F_Lecture_19&amp;diff=22541&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The video from the lecture given on November 16, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec19-20191115.m4v is now availabl...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019F_Lecture_19&amp;diff=22541&amp;oldid=prev"/>
		<updated>2020-03-20T02:09:38Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The video from the lecture given on November 16, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec19-20191115.m4v 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 16, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec19-20191115.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 19&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
 - remember module&lt;br /&gt;
 - virtual memory (again)&lt;br /&gt;
 - /dev/describe (if time)&lt;br /&gt;
&lt;br /&gt;
Key functions: alloc_pages, page_address&lt;br /&gt;
&lt;br /&gt;
Remember that the kernel allocates memory in pages (fixed-sized chunks of memory), normally 4K or 8K in size (although you can have 2M pages or larger).&lt;br /&gt;
&lt;br /&gt;
These pages are allocated as *physical* pages.&lt;br /&gt;
 - there is only one physical address space shared by everything on a system&lt;br /&gt;
&lt;br /&gt;
This is a pain because physical addresses are shared across all processes&lt;br /&gt;
Each process (and the kernel) wants its own range of contiguous addresses&lt;br /&gt;
 - virtual addresses allow everyone to have their own view of memory&lt;br /&gt;
 - allows pages put all over the place to be connected together, so processes&lt;br /&gt;
   see no gaps&lt;br /&gt;
&lt;br /&gt;
So each process has its own virtual-&amp;gt;physical address mapping, as does the kernel (one for the kernel)&lt;br /&gt;
 - these mappings are called page tables&lt;br /&gt;
&lt;br /&gt;
alloc_pages()&lt;br /&gt;
 - returns pages contiguous in physical memory&lt;br /&gt;
 - first argument is the priority (e.g., GFP_KERNEL)&lt;br /&gt;
 - second argument is the &amp;quot;order&amp;quot; of the allocation x&lt;br /&gt;
     order x = 2^x pages to allocate&lt;br /&gt;
   so order=0 means allocate one page&lt;br /&gt;
      order=4 means allocate 16 pages (2^4)&lt;br /&gt;
&lt;br /&gt;
 - you allocate pages this way in order to reduce fragmentation&lt;br /&gt;
   - note each order is twice as much as the one previous, so you can get&lt;br /&gt;
     2 x-1 order allocations out of 1 x order allocation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The resident memory (RES) of a process is generally much smaller than the total virtual memory (VIRT) of a process.  This is because:&lt;br /&gt;
 - some pages may be swapped out to disk (data structures that aren&amp;#039;t being accessed)&lt;br /&gt;
 - some pages may still be on disk (part of the executable)&lt;br /&gt;
 - memory that hasn&amp;#039;t been allocated&lt;br /&gt;
   - the Linux kernel is lazy about memory allocation&lt;br /&gt;
&lt;br /&gt;
If you allocate 1G of memory for a process, that doesn&amp;#039;t mean it gets&lt;br /&gt;
1G of physical memory.  You&amp;#039;ll only get that memory when you use it, and if the kernel can get away with not allocating it to your process, it won&amp;#039;t!&lt;br /&gt;
&lt;br /&gt;
One downside of this is memory can get overcommited.&lt;br /&gt;
 - just like a credit card, you can &amp;quot;spend&amp;quot; too much&lt;br /&gt;
 - and if the bill collector comes by, you may go bankrupt&lt;br /&gt;
&lt;br /&gt;
working set = part of program needed to &amp;quot;make progess&amp;quot;&lt;br /&gt;
 - all of the working set must be in RAM (physical memory) for program to run at full speed&lt;br /&gt;
 - if you can&amp;#039;t fit the working set of all running processes in RAM, system&lt;br /&gt;
   will slow down, potentially dramatically&lt;br /&gt;
 - on mobile devices, there is no swap, so it will just terminate processes&lt;br /&gt;
   when memory gets tight&lt;br /&gt;
&lt;br /&gt;
What sort of algorithm do you use to decide what pages stay in memory? On what basis?&lt;br /&gt;
&lt;br /&gt;
Ideally, you want to just keep the pages around that are needed for the future.&lt;br /&gt;
But, that would require you knowing the future.&lt;br /&gt;
&lt;br /&gt;
So normally we assume the past is like the future, and so we want to throw out pages that were the least recently used (LRU)&lt;br /&gt;
&lt;br /&gt;
But pure LRU is expensive, because it requires storing a timestamp for every page that is updated on every page access.&lt;br /&gt;
&lt;br /&gt;
We replace that timestamp with a bit.&lt;br /&gt;
&lt;br /&gt;
page replacement is normally done using a clock algorithm&lt;br /&gt;
  - a &amp;quot;hand&amp;quot; sweeps through all of memory, setting the access bit to 0&lt;br /&gt;
  - the access bit is set to 1 when a page is accessed&lt;br /&gt;
  - so, if a page has a 1, it has been used sometime since the last &amp;quot;sweep&amp;quot;&lt;br /&gt;
  - if the sweeps happen every 1 second, then we know page access times down to&lt;br /&gt;
    one second&lt;br /&gt;
  - in other words, we&amp;#039;re roughly simulating a clock&lt;br /&gt;
&lt;br /&gt;
So page replacement algorithms then just look for the pages with a 0 bit and chooses one of them to throw out.&lt;br /&gt;
&lt;br /&gt;
But, also have to take into account pages that have been modified (the dirty bit)&lt;br /&gt;
&lt;br /&gt;
Pages of an executable are read-only and have a backup on disk (in the executable)&lt;br /&gt;
Pages of data structures are read/write and have no backup unless written to swap.&lt;br /&gt;
&lt;br /&gt;
 - so, prefer to throw out executable pages rather than data pages&lt;br /&gt;
 - write data pages to swap if we have to so they can also be kicked out&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>