Docsity

Understanding Linux Memory Management: Segmentation, Paging, and Virtual Memory, Slides of Computer Applications

Partial preview of the text

Download Understanding Linux Memory Management: Segmentation, Paging, and Virtual Memory and more Slides Computer Applications in PDF only on Docsity!

Linux Memory Issues

An introduction to some low-level and some high-level memory management concepts

Some Architecture History

  • 8080 (late-1970s) 16-bit address (64-KB)
  • 8086 (early-1980s) 20-bit address (1-MB)
  • 80286 (mid-’80s) 24-bit address (16-MB)
  • 80386 (late-’80s) 32-bit address (4-GB)
  • 80686 (late-’90s) 36-bit address (64-GB)
  • Core2 (mid-2000s) 40-bit address (1-TB)

Linux must accommodate legacy

  • Legacy elements: hardware and firmware
  • CPU: reset-address and interrupt vectors
  • ROM-BIOS: data area and boot location
  • Display Controllers: VRAM & video BIOS
  • Support chipsets: 15MB ‘Memory Window’
  • DMA: 24-bit memory-address bus
  • SMP: combined Local and I/O APICs

Other CPU Architectures

  • Besides IA-32, Linux runs on other CPUs

(e.g., PowerPC, MC68000, IBM360, Sparc)

  • So must accommodate their differences
    • Memory-Mapped I/O
    • Wider address-buses
    • Non-Uniform Memory Access (NUMA)

Zones divided into Pages

  • 80x86 supports 4-KB page-frames
  • Linux uses an array of ‘page descriptors’
  • Array of page descriptors: ‘mem_map[]’
  • physical memory is ‘mapped’ by CPU

How 80x86 Addresses RAM

  • Two-stages: ‘segmentation’ plus ‘paging’:
    • First: logical address  linear address
    • Then: linear address  physical address
  • CPU employs special caches:
    • Segment-registers contain ‘hidden’ fields
    • Paging uses ‘Translation Lookaside Buffer’

Segment Descriptor Format

Base[ 15..0 ] Limit[ 15..0 ]

Base[ 31..24 ] (^) [19..16 ]Limit Base[ 23..16 ]

31 0

Linear to Physical

table-index^ linear address offset^ physical address-space

CR

dir-index

page^ page frame directory

page table

Example: Page-Size Extensions

  • 80586 can map either 4KB or 4MB pages
  • With 4MB pages: middle table is omitted
  • Entire 4GB address-space is subdivided

into 1024 4MB-pages

Demo-module: ‘cr3.c’ creates a pseudo-file showing the values in CR3 and in CR

Linear to Physical

linear address offset physical address-space

CR

dir-index

page frame

page directory

4-MB page-frames

Visualizing Memory

  • Our ‘pgdir.c’ module creates a pseudo-file that lets users see a visual depiction of the CPU’s current ‘map’ of ‘virtual memory’
  • Virtual address-space (4-GB)
    • subdivided into 4MB pages (1024 pels)
    • Text characters: 16 rows by 64 columns

Virtual Memory Visualization

  • Shows which addresses are ‘mapped’
  • Display granularity is 4MB
  • Data is gotten from task’s page-directory
  • Page-Directory location is in register CR
  • Legend:

‘-’ = frame not mapped ‘3’ = r/w by supervisor ‘7’ = r/w by user

struct mm_struct

  • It describes the task’s ‘memory map’
  • Where’s the code, the data, the stack?
  • Where are the ‘shared libraries’?
  • What are attributes of each memory area?
  • How many distinct memory areas?
  • Where is the task’s ‘page directory’?

Demo: ‘mm.c’

  • It creates a pseudo-file: ‘/proc/mm’
  • Allows users to see values stored in some of the ‘mm_struct’ object’s important fields