<?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_2022F_Lecture_20</id>
	<title>Operating Systems 2022F Lecture 20 - 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_2022F_Lecture_20"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_20&amp;action=history"/>
	<updated>2026-05-13T01:06:49Z</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_2022F_Lecture_20&amp;diff=24172&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on November 29, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec20-20221129.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec20-20221129.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&gt;Zoom meeting-&gt;Cloud Recordings tab)  ==Notes==  &lt;pre&gt; Lecture 20 ----------  4 more classes, including today! F...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_20&amp;diff=24172&amp;oldid=prev"/>
		<updated>2022-11-30T02:28:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on November 29, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec20-20221129.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec20-20221129.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&amp;gt;Cloud Recordings tab)  ==Notes==  &amp;lt;pre&amp;gt; Lecture 20 ----------  4 more classes, including today! F...&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;
Video from the lecture given on November 29, 2022 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec20-20221129.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec20-20221129.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&amp;gt;Cloud Recordings tab)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 20&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
4 more classes, including today!&lt;br /&gt;
Final exam is on Dec 21, 7 PM&lt;br /&gt;
&lt;br /&gt;
To help you with Assignment 4, you should know how to, in C:&lt;br /&gt;
 - return multiple values from a function&lt;br /&gt;
 - build up a string from multiple calls to snprintf&lt;br /&gt;
&lt;br /&gt;
Returning multiple values&lt;br /&gt;
 - have the caller pass in a pointer to a struct or an array&lt;br /&gt;
 - function updates the struct or array&lt;br /&gt;
&lt;br /&gt;
Why do it this way?&lt;br /&gt;
 - this way the caller is handling memory management for the data&lt;br /&gt;
 - because remember the easiest way to allocate data in C is on the&lt;br /&gt;
   stack, but the stack goes away when a function returns&lt;br /&gt;
     - so use the caller&amp;#039;s stack! (local variables)&lt;br /&gt;
&lt;br /&gt;
Definitely DO NOT use static data to pass data between functions, because&lt;br /&gt;
then your functions cannot be called in parallel (non-reentrant), which is a HUGE no-no in kernel dev&lt;br /&gt;
&lt;br /&gt;
When working on A4, if you have trouble inserting a module:&lt;br /&gt;
 - make sure other class modules have been removed first&lt;br /&gt;
 - if that doesn&amp;#039;t work, reboot then try again&lt;br /&gt;
&lt;br /&gt;
Remember that write doesn&amp;#039;t use null-terminated strings, it just writes whatever it is given.&lt;br /&gt;
&lt;br /&gt;
Memory map report (virtual -&amp;gt; physical)&lt;br /&gt;
argv:       0x00007ffc1ba2e3a8 -&amp;gt; 0x00000000167c63a8&lt;br /&gt;
argv[0]:    0x00007ffc1ba2f6c1 -&amp;gt; 0x000000001dd496c1&lt;br /&gt;
envp:       0x00007ffc1ba2e3b8 -&amp;gt; 0x00000000167c63b8&lt;br /&gt;
envp[0]:    0x00007ffc1ba2f6d0 -&amp;gt; 0x000000001dd496d0&lt;br /&gt;
lmsg:       0x0000563a7c11304e -&amp;gt; 0x000000002149f04e&lt;br /&gt;
&amp;amp;lmsg:      0x00007ffc1ba2e158 -&amp;gt; 0x00000000167c6158&lt;br /&gt;
gmsg:       0x0000563a7c113111 -&amp;gt; 0x000000002149f111&lt;br /&gt;
&amp;amp;gmsg:      0x0000563a7c115010 -&amp;gt; 0x0000000028c2d010&lt;br /&gt;
&amp;amp;buf:       0x00007ffc1ba2e160 -&amp;gt; 0x00000000167c6160&lt;br /&gt;
buf[00]:    0x0000563a7d3d16b0 -&amp;gt; 0x000000000c1786b0&lt;br /&gt;
buf[01]:    0x0000563a7d3d26c0 -&amp;gt; 0x000000001dcc16c0&lt;br /&gt;
buf[02]:    0x0000563a7d3d36d0 -&amp;gt; 0x0000000015afc6d0&lt;br /&gt;
buf[03]:    0x0000563a7d3d46e0 -&amp;gt; 0x0000000029ffe6e0&lt;br /&gt;
buf[04]:    0x0000563a7d3d56f0 -&amp;gt; 0x00000000283396f0&lt;br /&gt;
buf[05]:    0x0000563a7d3d6700 -&amp;gt; 0x00000000049ef700&lt;br /&gt;
buf[06]:    0x0000563a7d3d7710 -&amp;gt; 0x0000000023b24710&lt;br /&gt;
buf[07]:    0x0000563a7d3d8720 -&amp;gt; 0x000000001e0e4720&lt;br /&gt;
buf[08]:    0x0000563a7d3d9730 -&amp;gt; 0x0000000007bee730&lt;br /&gt;
buf[09]:    0x0000563a7d3da740 -&amp;gt; 0x000000000c3db740&lt;br /&gt;
buf[10]:    0x0000563a7d3db750 -&amp;gt; 0x00000000071ee750&lt;br /&gt;
buf[11]:    0x0000563a7d3dc760 -&amp;gt; 0x000000000e2e2760&lt;br /&gt;
buf[12]:    0x0000563a7d3dd770 -&amp;gt; 0x000000000b9e4770&lt;br /&gt;
buf[13]:    0x0000563a7d3de780 -&amp;gt; 0x0000000028361780&lt;br /&gt;
buf[14]:    0x0000563a7d3df790 -&amp;gt; 0x0000000008199790&lt;br /&gt;
buf[15]:    0x0000563a7d3e07a0 -&amp;gt; 0x000000001d9d27a0&lt;br /&gt;
buf[16]:    0x0000563a7d3e17b0 -&amp;gt; 0x00000000116477b0&lt;br /&gt;
buf[17]:    0x0000563a7d3e27c0 -&amp;gt; 0x00000000258b27c0&lt;br /&gt;
buf[18]:    0x0000563a7d3e37d0 -&amp;gt; 0x00000000255357d0&lt;br /&gt;
buf[19]:    0x0000563a7d3e47e0 -&amp;gt; 0x000000001b0d07e0&lt;br /&gt;
buf[20]:    0x0000563a7d3e57f0 -&amp;gt; 0x000000001e2557f0&lt;br /&gt;
buf[21]:    0x0000563a7d3e6800 -&amp;gt; 0x00000000074b2800&lt;br /&gt;
buf[22]:    0x0000563a7d3e7810 -&amp;gt; 0x000000000d914810&lt;br /&gt;
buf[23]:    0x0000563a7d3e8820 -&amp;gt; 0x000000001dd40820&lt;br /&gt;
buf[24]:    0x0000563a7d3e9830 -&amp;gt; 0x0000000029eec830&lt;br /&gt;
buf[25]:    0x0000563a7d3ea840 -&amp;gt; 0x00000000356a3840&lt;br /&gt;
buf[26]:    0x0000563a7d3eb850 -&amp;gt; 0x000000002834e850&lt;br /&gt;
buf[27]:    0x0000563a7d3ec860 -&amp;gt; 0x00000000054c6860&lt;br /&gt;
buf[28]:    0x0000563a7d3ed870 -&amp;gt; 0x0000000004286870&lt;br /&gt;
buf[29]:    0x0000563a7d3ee880 -&amp;gt; 0x00000000298af880&lt;br /&gt;
buf + 0:    0x00007ffc1ba2e160 -&amp;gt; 0x00000000167c6160&lt;br /&gt;
buf + 1:    0x00007ffc1ba2e161 -&amp;gt; 0x00000000167c6161&lt;br /&gt;
buf + 2:    0x00007ffc1ba2e162 -&amp;gt; 0x00000000167c6162&lt;br /&gt;
buf + 3:    0x00007ffc1ba2e163 -&amp;gt; 0x00000000167c6163&lt;br /&gt;
buf + 4:    0x00007ffc1ba2e164 -&amp;gt; 0x00000000167c6164&lt;br /&gt;
buf + 5:    0x00007ffc1ba2e165 -&amp;gt; 0x00000000167c6165&lt;br /&gt;
buf + 6:    0x00007ffc1ba2e166 -&amp;gt; 0x00000000167c6166&lt;br /&gt;
buf + 7:    0x00007ffc1ba2e167 -&amp;gt; 0x00000000167c6167&lt;br /&gt;
buf + 8:    0x00007ffc1ba2e168 -&amp;gt; 0x00000000167c6168&lt;br /&gt;
buf + 9:    0x00007ffc1ba2e169 -&amp;gt; 0x00000000167c6169&lt;br /&gt;
buf + 10:    0x00007ffc1ba2e16a -&amp;gt; 0x00000000167c616a&lt;br /&gt;
buf + 11:    0x00007ffc1ba2e16b -&amp;gt; 0x00000000167c616b&lt;br /&gt;
buf + 12:    0x00007ffc1ba2e16c -&amp;gt; 0x00000000167c616c&lt;br /&gt;
buf + 13:    0x00007ffc1ba2e16d -&amp;gt; 0x00000000167c616d&lt;br /&gt;
buf + 14:    0x00007ffc1ba2e16e -&amp;gt; 0x00000000167c616e&lt;br /&gt;
buf + 15:    0x00007ffc1ba2e16f -&amp;gt; 0x00000000167c616f&lt;br /&gt;
buf + 16:    0x00007ffc1ba2e170 -&amp;gt; 0x00000000167c6170&lt;br /&gt;
buf + 17:    0x00007ffc1ba2e171 -&amp;gt; 0x00000000167c6171&lt;br /&gt;
buf + 18:    0x00007ffc1ba2e172 -&amp;gt; 0x00000000167c6172&lt;br /&gt;
buf + 19:    0x00007ffc1ba2e173 -&amp;gt; 0x00000000167c6173&lt;br /&gt;
buf + 20:    0x00007ffc1ba2e174 -&amp;gt; 0x00000000167c6174&lt;br /&gt;
buf + 21:    0x00007ffc1ba2e175 -&amp;gt; 0x00000000167c6175&lt;br /&gt;
buf + 22:    0x00007ffc1ba2e176 -&amp;gt; 0x00000000167c6176&lt;br /&gt;
buf + 23:    0x00007ffc1ba2e177 -&amp;gt; 0x00000000167c6177&lt;br /&gt;
buf + 24:    0x00007ffc1ba2e178 -&amp;gt; 0x00000000167c6178&lt;br /&gt;
buf + 25:    0x00007ffc1ba2e179 -&amp;gt; 0x00000000167c6179&lt;br /&gt;
buf + 26:    0x00007ffc1ba2e17a -&amp;gt; 0x00000000167c617a&lt;br /&gt;
buf + 27:    0x00007ffc1ba2e17b -&amp;gt; 0x00000000167c617b&lt;br /&gt;
buf + 28:    0x00007ffc1ba2e17c -&amp;gt; 0x00000000167c617c&lt;br /&gt;
buf + 29:    0x00007ffc1ba2e17d -&amp;gt; 0x00000000167c617d&lt;br /&gt;
main:       0x0000563a7c112130 -&amp;gt; 0x000000001d3cd130&lt;br /&gt;
puts:       0x00007fa84e0c1ed0 -&amp;gt; 0x0000000119169ed0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Why are the last three digits the same between the physical and virtual address (basically always)?&lt;br /&gt;
 - because addresses are divided into a &amp;quot;page/frame number&amp;quot; and an &amp;quot;offset&amp;quot;&lt;br /&gt;
   - page number: prefix of a virtual address&lt;br /&gt;
   - frame number: prefix of a physical address&lt;br /&gt;
 - we mapp a page number to a frame number (upper bits)&lt;br /&gt;
   and then add on the offset (lower bits, 12 bits if 4k pages)&lt;br /&gt;
&lt;br /&gt;
on a 64 bit platform, a page + offset = 64 bits (so pointers are 64 bits)&lt;br /&gt;
 - but frame + offset can be smaller, as nobody has 2^64 RAM&lt;br /&gt;
   (so may only have 48 bit physical addresses)&lt;br /&gt;
   (must be expanded if we get more physical memory than can be&lt;br /&gt;
    addressed)&lt;br /&gt;
&lt;br /&gt;
A page table is a data structure for mapping page numbers to frame numbers&lt;br /&gt;
 - so we can figure out where a virtual address is in physical memory&lt;br /&gt;
&lt;br /&gt;
So for modern x86 systems&lt;br /&gt;
 - offset is 12 bits&lt;br /&gt;
 - each level of the page table maps 9 bit indexes&lt;br /&gt;
    - because 9 bits is 512, 512 * 8 = 4096, so fits in a 4k page!&lt;br /&gt;
      (8 is for 8 bytes, or 64 bits per pointer/page table entry)&lt;br /&gt;
&lt;br /&gt;
So resolving an address with a page table means&lt;br /&gt;
 - grab top node of page table, PGD, which is an array of 512 pointers (PTE&amp;#039;s)&lt;br /&gt;
 - take first 9 bits of address, use that as an index into PGD to get index to PUD&lt;br /&gt;
 - take next 9 bits of address, use that as an index into the PUD page to get&lt;br /&gt;
   the PMD&lt;br /&gt;
 - take next 9 bits of address, use that as an index into the PMD page to get&lt;br /&gt;
   the PTE&lt;br /&gt;
 - take next 9 bits to index into the PTE to get the page&lt;br /&gt;
 - use last 12 bits to index into the page to get the actual value of memory&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m not going to test you about the specific address resolution process&lt;br /&gt;
 - but I will want you to understand the role of page tables in resolving virtual to physical addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Page tables are sparse data structures&lt;br /&gt;
 - most of the tree isn&amp;#039;t there for most processes&lt;br /&gt;
 - 0&amp;#039;s in key places&lt;br /&gt;
&lt;br /&gt;
So when you do a malloc that calls mmap or sbrk&lt;br /&gt;
 - the kernel will be changing the process&amp;#039;s page table,&lt;br /&gt;
   adding in new entries to accomodate the added RAM&lt;br /&gt;
    - sometimes this will just be a couple of pages and the PTE&amp;#039;s needed&lt;br /&gt;
      to refer to them&lt;br /&gt;
    - but if you allocate 1G of RAM, you need a new chunk of the page&lt;br /&gt;
      table to be allocated to handle the mapping of all the physical&lt;br /&gt;
      pages needed for that RAM&lt;br /&gt;
&lt;br /&gt;
But then again, there are other cheats&lt;br /&gt;
 - what if two processes are sharing the same memory?&lt;br /&gt;
 - don&amp;#039;t copy, just have them both point to the same pages or even page table subtree!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>