Skip to main content

Command Palette

Search for a command to run...

OS Design and Implementation: (Week 3) - Page tables

MIT 6.1810 Fall2025 Course - Week 3: Page tables

Updated
3 min read

Okay! Not only did I spend more than 3 weeks on it, but I also completed only 2 of the 3 labs about page tables. And yes, it was a tough chapter. Anything related to memory is tough, by the way.

In short, this chapter was about page tables and how the OS creates virtual memory for applications. In fact, the memory used by user applications or that we get when doing

int a = 25;
printf("%p", &a);

is virtual memory that the OS creates and maps to physical memory.
The OS doesn't allow user applications to interact directly with the RAM (this is too dangerous); instead,

  • It allocates the same address space of [0; 0x3fffffffff] for each process or application, which contains blocks of memory that are 4096 bits in size.

  • Then, it maps or associates each address of this virtual memory to a real address in the RAM using what we call a Page Table Entry.

There are many other aspects of Virtual Memory, such as access rights to addresses, page size, and the Translation Lookaside Buffer (which acts like an LRU cache for mapping virtual addresses to physical addresses)...

This technique allows the OS to control access to memory and check if a process has the right to read, execute, or write to a memory address, addressing a security concern.

Now, back to the course. It took me some time to understand what Virtual Memory is and how it works, and even more time to complete the labs, which were:

  1. Map a read-only page containing the PID into the process's virtual memory during creation. The user program then reads the PID directly from that memory address, avoiding the system call.

  2. To help visualize RISC-V page tables, write a function that prints the contents of a page table.

  3. Create megapages by setting valid and read bits in a level-1 PTE and pointing it to a 2MB-aligned physical address.

    This reduces page table size and TLB misses, significantly boosting performance for memory-intensive programs. (Not completed).

And yes, there is an approach called Superpages. Instead of allocating small memory sizes like 4096 bits, the OS allocates larger superpages, such as 2MB. However, it's not straightforward. There are some challenges with its implementation. And guess what? There are two papers to read about it (I swear 😭 It's not just something I imagined about the course):

So, what now? I'll leave it there and start Week 4: Trap and Syscall entry-exit. Maybe while reading and doing the labs, I can come back to the Superpages lab. I'm not required to understand everything right away 😂

By the way, here's my GitHub repo for the lab course: https://github.com/TawalMc/MIT-6.1810Fall2025-xv6