YouTube2Text

[CS61C FA20] Lecture 29.5 - Virtual Memory I: Page Faults — Transcript

by CS 61C Departmental · 1,831 words · 319 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:11hello
  3. 0:12and welcome back to our virtual memory
  4. 0:14and operating system support module
  5. 0:16we introduced a system the page memory
  6. 0:19system
  7. 0:20and seen how our pages
  8. 0:23work they can reside either in dram
  9. 0:26or on the disk and we have a page table
  10. 0:30that tells us whether the pages have
  11. 0:32been allocated
  12. 0:33and whether they are in dram or on the
  13. 0:36disk
  14. 0:38we're going to take a little bit more
  15. 0:41detail look into how does the system
  16. 0:43actually work but before
  17. 0:45that let's recap some things and
  18. 0:49you know remove any confusions that we
  19. 0:50might have caused
  20. 0:52first let's make sure that you
  21. 0:55understand
  22. 0:56what are these blocks and pages and
  23. 0:58understand that there are
  24. 0:59generally just different ways of
  25. 1:01measuring how many
  26. 1:02bytes are we working with like in the
  27. 1:05metric system where we use kilos and
  28. 1:07millis
  29. 1:08to tell us how much of grams are we
  30. 1:12dealing with in weight here we are using
  31. 1:16different metrics for some amount of
  32. 1:18bytes that we
  33. 1:19are moving around so in general
  34. 1:22in caches we deal with individual blocks
  35. 1:25and blocks are
  36. 1:26you know 64 bytes in most modern systems
  37. 1:30some of them may be 128. um
  38. 1:33the the thing uh also to make sure here
  39. 1:36is don't confuse this block
  40. 1:38with the size of a block that sometimes
  41. 1:41is referred to in storage in ssds
  42. 1:45and disks cache
  43. 1:49blocks are 64 bytes in our case
  44. 1:53in virtual memory we generally deal with
  45. 1:55pages
  46. 1:56and pages in our case are for kiwi
  47. 2:00and in most other modern systems they're
  48. 2:02also
  49. 2:044kb so um don't confuse bytes words
  50. 2:09blocks and pages they're just different
  51. 2:11ways
  52. 2:11of measuring the amount of data that we
  53. 2:15have in the memory
  54. 2:16let's take a look at a quick example
  55. 2:18let's say that we have a really really
  56. 2:19simple computer it just has a you know
  57. 2:21tiny amount of dram
  58. 2:23the total 16 kb
  59. 2:26the 16 kb will be organized into four
  60. 2:30pages for each page is uh 4 kb
  61. 2:33in a simple virtual memory system they
  62. 2:36would have
  63. 2:37it will have 128 byte blocks
  64. 2:40for caches and four byte words
  65. 2:43for loads and stores so
  66. 2:47our memory system here would have 16
  67. 2:51kiwi uh those 16 kb would be organized
  68. 2:55into four
  69. 2:564 kb pages each page
  70. 2:59would have 32 blocks each
  71. 3:04block would have 32
  72. 3:07words each word would have four bytes
  73. 3:11so to recap all of that we can think of
  74. 3:13the entire memory
  75. 3:14as four pages 128 blocks
  76. 3:184096 words or 16
  77. 3:22384 bytes we can think of a page
  78. 3:25as having 32 blocks or 1024 words
  79. 3:30and finally each block can have 32 words
  80. 3:34or 128
  81. 3:38bytes
  82. 3:41the other analogy that we would like to
  83. 3:44recall now since we have seen how does
  84. 3:45the page memory system work
  85. 3:47is the library analogy um
  86. 3:51we generally in our heads we keep
  87. 3:53library
  88. 3:54we keep book titles so all what we
  89. 3:57remember is a book title we don't
  90. 3:58remember the
  91. 3:59library or congress call number so when
  92. 4:02we
  93. 4:03refer to a book we refer to it by
  94. 4:06the bytes title but going
  95. 4:10to the library straight for the
  96. 4:13bookshelves
  97. 4:14to try to find that book is usually not
  98. 4:17going to
  99. 4:18you know
  100. 4:19[Music]
  101. 4:23yield the reasonable result we may not
  102. 4:25find the book just going straight for
  103. 4:27the stacks
  104. 4:30books are organized in different ways
  105. 4:32and generally we would have to go
  106. 4:34for the card catalog like the page table
  107. 4:37uh
  108. 4:38what is in our virtual memory
  109. 4:40equivalence
  110. 4:41that maps the titles to the
  111. 4:44library or congress call numbers on
  112. 4:48that card entry that is in our catalog
  113. 4:53we would find out a valid bit whether
  114. 4:56the
  115. 4:57book exists in this library system
  116. 5:00and where is it is it in the main memory
  117. 5:03or is it on the disk
  118. 5:04meaning some external storage or some
  119. 5:06other library some other facility
  120. 5:09finally there may be a reservation bit
  121. 5:11on that
  122. 5:13entry that tells us you know for how
  123. 5:15long we can check out that book and can
  124. 5:17we check it out at all
  125. 5:20another important thing here that should
  126. 5:22be brought up is when the library
  127. 5:24brings a new book to its collection it
  128. 5:26doesn't just go and
  129. 5:27shove it onto on the library stacks
  130. 5:30every time a new book is brought
  131. 5:32a new page is brought in our virtual
  132. 5:34memory system we need to create a
  133. 5:36catalog page for it we need to
  134. 5:38create create a catalog card for it and
  135. 5:42place it in in the collection
  136. 5:46all right so back to our page memory
  137. 5:49system
  138. 5:50in our page memory system what we have
  139. 5:52seen is that
  140. 5:53each process works with its own
  141. 5:57page table a page table has multiple
  142. 6:00entries that are pointing
  143. 6:01to the pages that may reside in dram
  144. 6:04or on the disk now
  145. 6:07in addition to these references to the
  146. 6:10dram or the disk
  147. 6:12there are some of the status bits that
  148. 6:14are associated with each page table
  149. 6:16entry
  150. 6:16we have seen that we need to have a
  151. 6:18valid whether the page
  152. 6:20is allocated you know whether it exists
  153. 6:24but also we are seeing that there is a
  154. 6:25need for another one we need to know
  155. 6:27whether that page is
  156. 6:28in dram or is on the disk
  157. 6:32this is just conceptual what we'll find
  158. 6:34out is
  159. 6:35that virtual memory systems are specific
  160. 6:39to the isa
  161. 6:40and have uh you know a bit longer
  162. 6:43uh you know number or larger number of
  163. 6:46these control bits
  164. 6:47that are telling us you know what is uh
  165. 6:51what's the status of of each page table
  166. 6:53entry we'll see some of those
  167. 6:55a bit later but conceptually we need to
  168. 6:58know whether the page is valid
  169. 6:59and whether it resides in dram or it's
  170. 7:02on the disk
  171. 7:04now there is an important mechanism
  172. 7:08that gets invoked every time we would
  173. 7:11like
  174. 7:11to perform this translation would like
  175. 7:14we see a virtual address
  176. 7:16and then we would like to find out we
  177. 7:19would like to get our data
  178. 7:20we need to find out whether we want to
  179. 7:22get it from the drum or the disk
  180. 7:24or we actually need to create a new page
  181. 7:27table entry
  182. 7:28so on each memory reference
  183. 7:31loads and stores we are going to check
  184. 7:35the page table entry
  185. 7:36if it is valid we are going to proceed
  186. 7:40with checking where is that page if it
  187. 7:44is in dram
  188. 7:44that's great we're just going to go
  189. 7:46ahead and rewrite the data
  190. 7:50if it is on a disk that may be a lengthy
  191. 7:53procedure
  192. 7:54of getting that data into the dram
  193. 7:58so we have to going to allocate a new
  194. 8:00page in dram if there is
  195. 8:01rom that's great if there is no room in
  196. 8:04if all
  197. 8:04of the the dram has been allocated there
  198. 8:07is no free space in dram
  199. 8:09we would have to evict a page from dram
  200. 8:12uh store this evicted page to disk so
  201. 8:15move
  202. 8:15that page from that that is being
  203. 8:18evicted and that's usually the one that
  204. 8:20was
  205. 8:20least recently used would be moving to
  206. 8:23the disk
  207. 8:24it would read the page from the disk
  208. 8:25into the memory and then proceed with
  209. 8:27reading and writing the data
  210. 8:31in other case if the page is
  211. 8:34page table entry is not valid we
  212. 8:38that means that we haven't referenced
  213. 8:39that data before
  214. 8:41so we are going to allocate a new page
  215. 8:42in dram uh if you're out of memory we're
  216. 8:45going to do like we did before we're
  217. 8:46going to edit the page
  218. 8:47and move it to to disk and then read and
  219. 8:51write data
  220. 8:52to the newly created page indira
  221. 8:55in these two cases if the data is not on
  222. 8:58disk
  223. 9:00or not valid we
  224. 9:03need an os intervention os needs to
  225. 9:06handle all of that and it does it run
  226. 9:09mechanism
  227. 9:10of a page fault
  228. 9:14what is a page fault well page fault
  229. 9:18is a special exception
  230. 9:22that is invoked when
  231. 9:25we are handling one of these two
  232. 9:26conditions
  233. 9:28so it is handled by the same mechanism
  234. 9:31that we have seen before that we have
  235. 9:33outlined before of mechanism
  236. 9:36of handling the exceptions
  237. 9:39[Music]
  238. 9:41it does all the page table updates and
  239. 9:44initiates transfer from the dram to disk
  240. 9:46and this this to dram
  241. 9:47and updates the status bits
  242. 9:51this is something that is done by the os
  243. 9:54in the supervisor mode now
  244. 9:58if this procedure involves moving
  245. 10:02the data to and from to the disk
  246. 10:04essentially a swap of a page
  247. 10:06with uh with a disk it will often
  248. 10:10generally perform the context switch
  249. 10:11because that's a lengthy procedure that
  250. 10:13means that this process needs something
  251. 10:15from pluto or mars and it's going to
  252. 10:18take a while
  253. 10:19so processor going to be idle
  254. 10:22for tens of milliseconds it's a perfect
  255. 10:25time to
  256. 10:26initiate a context switch and have some
  257. 10:28other process
  258. 10:29use the processor while the data is
  259. 10:32coming in
  260. 10:35then following the page fault the
  261. 10:37instruction is re-executed remember
  262. 10:39when we raise the exec exception we
  263. 10:42are cancelling that instruction that is
  264. 10:45being in flight loader store
  265. 10:47it has no hope of you know finishing
  266. 10:50then if the data is not
  267. 10:52valid so it will wait for the data to
  268. 10:56be valid in the memory and complete the
  269. 10:59instruction a few
  270. 11:03other things even though our virtual
  271. 11:05memory system appears to be huge it is
  272. 11:07not
  273. 11:07infinite so if you try to allocate
  274. 11:10something that is
  275. 11:10just really really big like try to
  276. 11:13allocate
  277. 11:14an array that is thousand twenty four
  278. 11:16times twenty thousand twenty four times
  279. 11:18thousand twenty four times the word
  280. 11:20length
  281. 11:21um we may run out of memory we're gonna
  282. 11:23get this kind of an
  283. 11:25exception fail to allocate 131
  284. 11:28terabytes we are out of memory
  285. 11:31so if we don't have that much memory or
  286. 11:33that much
  287. 11:34and that much list together we are
  288. 11:37we can do it we can complete this
  289. 11:40um another point here that we would like
  290. 11:43you know that is fairly straightforward
  291. 11:45but we just want to make sure that
  292. 11:47it is clear unlike caches where we had
  293. 11:50different policies how do we want to
  294. 11:53write data back to the
  295. 11:56memory from the cache we
  296. 12:00you know discuss the right through or
  297. 12:02write back policies
  298. 12:04when we are dealing from
  299. 12:07data transfers updates to the disk
  300. 12:10we really have only one option the cost
  301. 12:13of mov of writing data back to a disk is
  302. 12:16so huge
  303. 12:17that the only option that we can do is
  304. 12:20right back
  305. 12:20right through is uh you know really not
  306. 12:24an option because it's going to be
  307. 12:25really really slow so we
  308. 12:27the only policy here is going to be
  309. 12:29right back on the least recently used
  310. 12:32page
  311. 12:33so um you know write policies in virtual
  312. 12:36memory systems are significantly simpler
  313. 12:38than what we encounter
  314. 12:40in caches
  315. 12:44i think it's a good time now to pause we
  316. 12:46are going to continue
  317. 12:47with some other interesting
  318. 12:50aspects of the virtual memory after
  319. 12:54the break

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 29.5 - Virtual Memory I: Page Faults by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,831 words across 319 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.