YouTube2Text

[CS61C FA20] Lecture 30.1 - Virtual Memory II: Hierarchical Page Tables — Transcript

by CS 61C Departmental · 1,694 words · 309 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:15and operating
  5. 0:16system module in the previous segments
  6. 0:19we have introduced our page memory
  7. 0:20system and introduced
  8. 0:22page tables as a way of managing
  9. 0:25that virtual memory system we also
  10. 0:27talked about the analogy
  11. 0:29of going to a library and instead of
  12. 0:32when we walk into a library instead of
  13. 0:34just going straight for the bookshelves
  14. 0:36trying to find
  15. 0:38a book that we want based on the title
  16. 0:40that we have jotted down
  17. 0:43we go to the catalog first if we
  18. 0:46went to straight to the stacks to the
  19. 0:50bookshelves
  20. 0:51it would take us a very long time to
  21. 0:53find our title we really don't know
  22. 0:55where to start
  23. 0:56we so we would have to search for a long
  24. 0:58time
  25. 0:59if you go for a catalog or a database on
  26. 1:02a computer
  27. 1:02you would by searching for the title
  28. 1:07that we care about you would
  29. 1:10immediately exactly get pointed to the
  30. 1:13to the location
  31. 1:16on the shelves where our book title
  32. 1:18would be
  33. 1:20so that is what got us to our page
  34. 1:23tables
  35. 1:24and page table entries but there are
  36. 1:26some
  37. 1:27really important differences in how does
  38. 1:30this get
  39. 1:30implemented in a compute system where
  40. 1:34the size of the memory matters that is
  41. 1:37allocated to these page tables so
  42. 1:40we started talking about the how big are
  43. 1:43these
  44. 1:43page tables so in our 32-bit uh
  45. 1:48system with the 32-bit virtual address
  46. 1:51we decided to go with four kb pages
  47. 1:54which is a common choice
  48. 1:56so we took our 32-bit address space and
  49. 1:59split it into the the portion
  50. 2:03that is going to give us a virtual
  51. 2:04address uh to the page
  52. 2:07which was 20 bits and a 12-bit offset
  53. 2:10that would allow us to address data
  54. 2:13within
  55. 2:14a 4kb page
  56. 2:17now these 20 bits um result
  57. 2:22in a single page table size that is
  58. 2:264 bytes times 2 to the 20
  59. 2:29entries which is 4 maybe
  60. 2:33so we are allocating to a single page
  61. 2:36size
  62. 2:36four megabytes of our memory that is way
  63. 2:39too much for the
  64. 2:40cache but it is totally acceptable
  65. 2:43for a for gibby dram
  66. 2:47in a modest laptop nowadays that's just
  67. 2:500.1 percent
  68. 2:52of its d-run capacity
  69. 2:55but modern operating systems can have
  70. 2:59hundreds of processes running
  71. 3:00concurrently so um total
  72. 3:04size for 256 processes which are
  73. 3:09can be supported by modern operating
  74. 3:11systems
  75. 3:12where each process would need a page
  76. 3:15table
  77. 3:16would be huge so
  78. 3:19if we take a look at that we would have
  79. 3:21256 processes
  80. 3:23times 4 bytes times 2 to the 20
  81. 3:26entries so that will be 256 times 4
  82. 3:30maybe which is 1 gibby
  83. 3:32one gigabyte out of or four gigabytes of
  84. 3:34the laptop memory would be
  85. 3:36gone to page tables that's a lot and
  86. 3:39that really restricts the amount of of
  87. 3:41of of memory that our
  88. 3:45processes can actually use for storing
  89. 3:48program and the data
  90. 3:51and that's not all most computers
  91. 3:54nowadays are 64 bits
  92. 3:56have 64-bit addresses and that would
  93. 4:00really result in in exploding
  94. 4:03um size for the
  95. 4:06page tables so we need a better way to
  96. 4:09manage these page tables
  97. 4:12and keep the the size of page tables
  98. 4:14more reasonable
  99. 4:16so there are a few options that we can
  100. 4:18consider the first one
  101. 4:19is to increase the page size so double
  102. 4:23the doubling the page table size from 4
  103. 4:25kb to 8 kb
  104. 4:27would cut the pt size in half
  105. 4:31but that would result in more wasted
  106. 4:34memory if we
  107. 4:34really if our program uses less than
  108. 4:388 kb chunks well that
  109. 4:41you know whatever it does not use would
  110. 4:42end up being wasted so there is a
  111. 4:44trade-off there
  112. 4:45more commonly we are going to see
  113. 4:47something that is called hierarchical
  114. 4:49page tables where one level of page
  115. 4:52tables will be
  116. 4:53addressing a larger chunk of memory and
  117. 4:55then the next level of page tables will
  118. 4:57be zooming in onto
  119. 4:59a smaller chunk of a memory and that
  120. 5:02is very
  121. 5:06works very well with many of the
  122. 5:07programs that we encounter these days
  123. 5:10most of the programs that we see use
  124. 5:13only a fraction
  125. 5:14of the memory remember our program has
  126. 5:17an area for the code
  127. 5:18for the static data and heap and the
  128. 5:21stack that
  129. 5:22are growing in the opposite directions
  130. 5:24so typically
  131. 5:26in our virtual memory we have
  132. 5:30this large empty donut hole in the
  133. 5:32middle very few programs are going to
  134. 5:34fully
  135. 5:35use that that um all the memory
  136. 5:39most of them are going to have this
  137. 5:40giant donut hole that is empty
  138. 5:42so the idea here is when we split our
  139. 5:45face tables
  140. 5:47uh page tables
  141. 5:50into multiple parts
  142. 5:54then the pointers from the first level
  143. 5:58page tables would be
  144. 6:01in most cases pointing to nothing to
  145. 6:04that empty space that does not need to
  146. 6:06be allocated
  147. 6:07some of them are going to be pointing to
  148. 6:09the valid places where we
  149. 6:11would find the stack and the heap and
  150. 6:13static data in the code
  151. 6:14but majority will be pointing
  152. 6:18to unuse paste and
  153. 6:21as a result we can save a lot of space
  154. 6:24um that we for our page tables
  155. 6:28and this is basically what is done in
  156. 6:31risk five
  157. 6:33so let's take a look at how does a
  158. 6:36hierarchical page table
  159. 6:38look like so our virtual address
  160. 6:41is going to be now split into three
  161. 6:43parts instead of two parts
  162. 6:46we are still going to have an offset and
  163. 6:47in this case we can if we
  164. 6:49are working with a four kb pages we are
  165. 6:51going to keep a 12-bit offset
  166. 6:53so we can index within the
  167. 6:57the page table and then instead of using
  168. 7:00one monolithic
  169. 7:02chunk of 20 bits to
  170. 7:06address page tables we can split it into
  171. 7:08two 10-bit
  172. 7:09parts so
  173. 7:13we would point to the root of the
  174. 7:15current page table
  175. 7:16and then we are going to have
  176. 7:211024 possible
  177. 7:23level one page tables that are each
  178. 7:26pointing 2024 times
  179. 7:29kb or 4
  180. 7:32mb chunks in the memory now they would
  181. 7:35be pointing
  182. 7:36to level 2 page tables where each one of
  183. 7:39them
  184. 7:40would be pointing to 4kb
  185. 7:44now the main catch here is that most of
  186. 7:48those a
  187. 7:49huge majority of these
  188. 7:52second level page tables will be
  189. 7:55pointing to nothing
  190. 7:56a small number of them will be pointing
  191. 7:58to the
  192. 8:00data that actually to the to the either
  193. 8:03dram or disk that
  194. 8:07contains real allocated memory
  195. 8:11and therefore we really can compress
  196. 8:14this
  197. 8:15dramatically the the the amount
  198. 8:18of space that we use for page tables is
  199. 8:21going to be dramatically
  200. 8:24lower than if we were to use a
  201. 8:27monolithic
  202. 8:2820-bit address for them
  203. 8:32now you are start you may start
  204. 8:36to worry about is
  205. 8:40this how are we going to store this huge
  206. 8:42data structure this looks like we're
  207. 8:44building a data structure
  208. 8:45generally it is not that big of a deal
  209. 8:49the key thing that we care to store
  210. 8:52about
  211. 8:53is this root of the current page table
  212. 8:56you know the pointer to the very first
  213. 9:01entry into the level one page table
  214. 9:04that is the only thing that sets
  215. 9:06everything up since
  216. 9:08the paging system is set in a very rigid
  217. 9:10way where we
  218. 9:12actually really allocated exact number
  219. 9:15of bits for
  220. 9:16the offset and each of the levels of the
  221. 9:19page table
  222. 9:20tables then just by
  223. 9:24knowing where to start sets up this
  224. 9:27whole three
  225. 9:31so in risk five there is a supervisor
  226. 9:34page table base register
  227. 9:36that points to that and that is all on a
  228. 9:39context
  229. 9:40context switch when we would like to
  230. 9:45switch in a new process all what we need
  231. 9:47to do
  232. 9:48is to restore the you know save the
  233. 9:51state of a previous
  234. 9:52process restore the state of a new
  235. 9:54process and by
  236. 9:55just pointing this sp
  237. 9:59tbr to where the new process
  238. 10:02the new process has its data structures
  239. 10:07makes it ready to go let's take a look
  240. 10:09at
  241. 10:10just an example of how does risk 5 do it
  242. 10:13in 32-bit space one thing to to mention
  243. 10:16here
  244. 10:17in you know 32-bit with 32-bit address
  245. 10:19spaces
  246. 10:20we usually see two-level hierarchical
  247. 10:22page tables
  248. 10:23when we go to 64-bit address spaces in
  249. 10:26order to
  250. 10:27exploit further the sparsity and not
  251. 10:29explode again
  252. 10:30the size of page tables will typically
  253. 10:32see four layers of hierarchy
  254. 10:34that's what risk 5 does in 64 bits
  255. 10:38and so does the x86 for example
  256. 10:42so in 32-bit version of risc-5 32-bit
  257. 10:46virtual addresses are specified and
  258. 10:4834-bits physical addresses are specified
  259. 10:52a 32-bit virtual address space is split
  260. 10:54into a 12-bit offset
  261. 10:55for 4 kb pages and
  262. 10:59two parts of virtual addresses that are
  263. 11:02each 10 bits wide so these virtual
  264. 11:06page numbers point to physical page
  265. 11:08numbers
  266. 11:09and there are
  267. 11:13page table entries that are 32 bits
  268. 11:16wide each they are going to contain our
  269. 11:20physical page numbers
  270. 11:26upper and lower and then there is a
  271. 11:28whole bunch of status bits that we have
  272. 11:30refreshed in passing of course we are
  273. 11:32not going to test you on something like
  274. 11:33that
  275. 11:34this how are you memorizing this but
  276. 11:37here is a bunch
  277. 11:38of bits that are essentially setting
  278. 11:40access control and also helping us
  279. 11:43with the replacement policies most
  280. 11:46notably there are
  281. 11:47read write and execute access bits
  282. 11:51that tells us whether we can read write
  283. 11:55read from that page write to that page
  284. 11:58or execute
  285. 11:58code from that page um
  286. 12:03and you know what is interesting here by
  287. 12:05convention
  288. 12:06if all of these are zero we cannot
  289. 12:08either
  290. 12:09read or write or execute
  291. 12:12a page that means that that page is
  292. 12:14pointing to the next level
  293. 12:16of the page table otherwise
  294. 12:19it's a leaf pt that's the page that we
  295. 12:22should be accessing
  296. 12:23so that's a convention how that
  297. 12:26implements this multi-level
  298. 12:29page hierarchy then the other bits
  299. 12:32basically are going to tell us whether
  300. 12:34the page is valid
  301. 12:35and has it been raised decently so we
  302. 12:38can
  303. 12:39use that data in our replacement policy
  304. 12:46well that's it about hierarchical page
  305. 12:48tables
  306. 12:49when we come back after a break we're
  307. 12:51going to talk about
  308. 12:53how do we accelerate this in hardware
  309. 12:56see you then

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 30.1 - Virtual Memory II: Hierarchical Page Tables by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,694 words across 309 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.