ThomsonTang / techbook.thomsontang.com

output the card notes from technical books.
0 stars 0 forks source link

Computer Systems: A Programmer's Perspective #1

Open ThomsonTang opened 7 years ago

ThomsonTang commented 7 years ago

书名卡

ThomsonTang commented 7 years ago

术语卡

术语卡

ThomsonTang commented 7 years ago

术语卡:Virtual Memory

Virtual Memory is an elegant interaction of hardware exceptions, hardware address translation, main memory, disk files, and kernel software that provides each process with a large, uniform, and private address space.

印象

VM provides three important capabilities:

Physical and  Virtual Addressing

Used in “simple” systems like embedded micro-controllers in devices like cars, elevators, and digital picture frames.

vm-virtual-addressing

  • Used in all modern servers, desktops, and laptops
  • One of the great ideas in computer science
  • Address translation: the task of converting a virtual address to a physical one. Dedicated hardware on the CPU chip called the memory management unit(MMU) translates virtual addresses on the fly, using a look-up table stored in main memory whose contents are managed by the operating system.

Address Spaces

  • Clean distinction between data (bytes) and their attributes (address)
  • Each object can now have multiple addresses
  • Every byte in main memory: one physical address, one (or more) virtual address

Why Virtual Memory?

ThomsonTang commented 7 years ago

VM as a Tool for Caching

image

Three disjoint subsets of virtual pages:

DRAM Cache Organization

the bottom line is that the organization of the DRAM cache is driven entirely by the enormous cost of misses.(归根结底,DRAM缓存的组织结构完全是由巨大的不命中开销驱动的)

  • DRAM cache organization driven by the enormous miss penalty:
  • DRAM is about 10x slower than SRAM(the L1, L2 and L3 cache)
  • Disk is about 10,000x slower than DRAM

Page tables

As with any cache, the VM system must have some way to determine if a virtual page is cached somewhere in DRAM. These capabilities are provided by a combination of operating system software, address translation hardware in the MMU(memory management unit), and a data structure stored in physical memory known as a page table that maps virtual pages to physical pages.
A page table is an array of page table entries(PTEs) that maps virtual pages to physical pages.

image

The indications of each PTE which consists of a valid bit and an n-bit address field:

Page Hits

Page hit: reference to VM word that is in physical memory (DRAM cache hit).

image

Page Faults

In virtual memory parlance, a DRAM cache miss is known as a page fault.

Page fault: reference to VM word that is not in physical memory (DRAM cache miss).

image

Locality to the Rescue Again !

ThomsonTang commented 7 years ago

VM as a Tool for Memory Management

Virtual memory was still a useful mechanism because it greatly simplified memory management and provided a natural way to protected memory. In fact, operating system provide a separate page table, and thus a separate virtual address space, for each process.

In particular, VM simplifies linking and loading, the sharing of code and data, and allocating memory to applications.

Key idea: each process has its own virtual address space

image

Memory allocation

Sharing code and data among processes

Simplifying Linking and Loading

image