📂
build a OS
  • Learn OS with me
  • OS Interfaces
    • OS interfaces
    • I/O and File descriptors
    • Process and Memory
    • Pipes
    • File
  • OS Organization
    • OS Organization
    • Challenge yourself
  • Memory Management
    • XV6 Virtual Memory
    • Page Table
      • Part 1: How to translate address
      • Part 2: Create an Address Space
      • Part 3: How Page Table is used
      • Part 4: Page Fault and Swap
      • Part 5: How to operate on page tables
    • xv6 buddy allocator
      • How to display physical memory
    • Memory Management Walk Through
  • Traps and Interrupts
    • Trap Home Page
      • 系统调用的核心原理
    • What is trapframe
    • What is trampoline
    • Traps from kernel space
    • How fork() works
    • How system calls get into/out of the kernel
    • How exec() works
  • Scheduling
    • XV6 CPU Scheduling
    • How unix pipes work?
    • How does wait(), exit(), kill() work?
  • File System
    • Overview and Disk Layout
    • Buffer Cache
    • Design Inode Layer
    • Inode Content
    • Block Allocator
    • Design a log system for crash recovery
    • Directory Layer
    • Path names
    • File Descriptor Layer
    • FS System Calls
    • XV6 VS Real World
    • Make Xv6 File disk management system
    • Write FS simulator in python
    • How Redirect Shell command works
  • Concurrency
    • Spinlock
    • How linux select work
    • Hardware Support Locking
    • Exercise: Implement atomic counter
    • Locking in Xv6
    • Concurrency in Xv6
    • Exercise: Socket Programming with Event loop
  • Labs
    • Lab 1 Xv6 and Unix utilities
    • Lab 2 Shell
    • Lab 3 Buddy Allocator
    • Lab 4 Lazy
    • Lab 5 Copy-on-Write Fork for xv6
    • Lab 6 RISC-V assembly
    • Lab 6 Uthread: switching between threads
    • Lab 6 Alarm
    • Lab 7 Lock
    • Lab 8 File System: Large Files
    • Lab 8 File System: Symbolic links
    • Lab 9 mmap
    • Lab 10 Networking Part 1
    • Lab 10 Networking Part 2
  • Hardware, Device, Assembly
    • RISC-V assembly
    • Assembly: Access and Store information in Memory
    • Start xv6 and the first process
    • Why first user process loads another program?
    • What does kernel.ld do in XV6?
    • XV6 Device Driver
Powered by GitBook
On this page
  • How Page Table is used?
  • Terms:
  • Questions:
  • Solution:
  • Ask yourself

Was this helpful?

  1. Memory Management
  2. Page Table

Part 3: How Page Table is used

PreviousPart 2: Create an Address SpaceNextPart 4: Page Fault and Swap

Last updated 5 years ago

Was this helpful?

How Page Table is used?

Terms:

  • Physical memory allocation: Use buddy allocation algorithm to alloc/free memory.

  • Kernel has own page table.

  • Each process also has its own page table.

  • Hardware MMU translates VM to PM, and each CPU processor has a satp register to save root page-table page.

Questions:

How do we make sure process page tables and kernel’s page table not pointing to the same physical memory address? Are they all use satp to find address?

Solution:

  • Each process, and kernel all have its own Page Table.

  • Switching between user process or to/from kernel needs to set satp register to the address of the root page-table page.

  • By using MMU, translate the virtual memory to physical memory address. (See page tables Part 1 for details)

  • Note: satp register stores one root page table only.

User space to kernel space needs switching process page table to kernel page table.

Context switch between process save/restore registers. It is handled by the kernel, so the page table is switched among processes.

Example: Timer interrupt on P1. Page table is switched from P1’s to kernel’s. Then the CPU scheduler finds another P2 to run. P2 page table is reset when returning from kernel space to P2 user space.

Ask yourself

1. How MMU work

2. Kernel page table, direct mapping

3. How to turn on page? By storing address of root page-table page to satp register

4. Create process kernel stack, used for saving context

5. Process has own page table

6. Buddy allocator is alloc/free physical address

7. How buddy allocator works?

8. All allocation/free physical memory in os is done by buddy allocator.

9. How to print page table? 3 nested level.

10. How to do lazy page allocation in user space?