memory abstraction

Work in Progress

Summary

Memory abstraction methods

MethodCore IdeaBlocksFragmentationAdvantagesDisadvantages
physicalphysical memory addressesdynamic-- simple
- no overhead
- clashing load/store
- no protection
address relocationlogical addresses + relocation registerdynamic-- programs can be loaded anywhere
- improves flexibility
- limited protection
- still assumes contiguous allocation
base + limitlogical address + base register, checked against limit for protectiondynamic-- memory protection- additional compute and check
fixed partitioningprocess occupies one fixed partitionfixedinternal- easy to implement
- fast access
- partition need to contain large processes, some space is wasted
dynamic partitioningprocess occupies one partition of the exact size neededdynamicexternal- removes internal fragmentation
- flexible
- need size info in OS
- difficult memory allocation over time
buddy blocksmemory split into power-of-two sized blocksdynamic (2ⁿ)both- efficient allocation/deallocation
- reduces fragmentation
- small blocks are not cost effective

Disjoint memory schemes

MethodCore IdeaBlocksFragmentation TypeAdvantagesDisadvantages
pagingmemory split into fixed-size pages/frames, process divided into pagesfixedinternal- simple allocation- page table overhead, extra memory access (unless cached via TLB)
segmentationmemory divided into logical segmentsdynamicexternal- segments are contiguous
- can be protected/shared independently
- more complex allocation
segmentation + pagingcombines segmentation and pagingfixed, dynmic numberboth- reduces fragmentation
- dynamic growth
- high overhead (multiple lookups)

Concept

RAM

  • array of bytes with unique physical addresses
  • contiguous region - interval of consecutive addresses

Data

  • transient - valid for limited time
  • persistent - valid for the duration of the program
  • both types can grow or shrink during execution

Role of the OS

  1. allocate memory space to a new process
  2. manage memory space for process
  3. protect memory space of processes from each other
  4. provide syscalls for processes to access memory
  5. manage memory for internal use within the process

Physical addressing

  • processes load and store from physical addresses
  • direct addressing
  • hard to run multiple processes
    • load and stores may clash
    • hard to protect memory space

Relative addressing

Logical address

  • physical addressing is bad
  • each process has a self-containted logical memory space
  • OS manages the mapping from logical to physical memory

Address relocation

  • when loading the process into memory
  • add an offset to all memory references for a particular process
  • slow -> need to calculate everything
  • hard to distinguish memory refernce from other instructions

Base + Limit registers

  • base register -> points to the start of the space allocated to the process
  • limit register -> size of the space allocated to the process
  • at compile time, memory references are compiled as an offset from the base register
  • need to compute physical = base + offset and check offset < limit for every access