lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

index.md (2286B)


      1 +++
      2 title = 'The Memory Address Space'
      3 +++
      4 # The Memory Address Space
      5 introduce abstraction of address space - every program runs in its own address space
      6 
      7 - base register operates dynamic relocation, controls where address space starts
      8 - limit register decides maximum address in physical memory that you can access
      9 
     10 how memory works with many programs:
     11 
     12 - processes compete for memory partitions
     13 - but how do you know the size of partitions? use dynamic partitions and swapping
     14 
     15     ![screenshot.png](3c804f4ae4f360f7be9a2b2d47f73b67.png)
     16 
     17     - problem: swapping may lead to memory fragmentation (when you have a many separate small chunks of free memory)
     18         - solution: memory compaction
     19     - problem - need to allow extra room for process growth
     20         - how much extra room? memory usage vs out-of-memory (OOM) risk
     21         - what do when OOM (out of mana/memory)?
     22             - kill process
     23             - relocate process
     24             - swap out
     25 
     26 memory management
     27 
     28 - which part of memory is allocated?
     29     - divide memory in blocks (e.g. each block is 4 bytes)
     30     - keep track of them using:
     31         - bitmap
     32             - divide memory in blocks. every bit in bitmap corresponds to a byte in memory. bit is 1 when the memory is allocated, 0 when it's free.
     33             - in bitmap, allocation is super fast. but to find free memory, you need to slowly scan for a hole.
     34         - linked list of unallocated memory
     35             - allocation is slow af, so is deallocation
     36             - holes sorted by address for fast coalescing
     37 - how do you allocate?
     38     - first fit: take first fitting hole (MINIX 3). simplest option.
     39     - next fit: take next fitting hole. slower than first fit in practice.
     40     - best fit: take best fitting hole. prone to fragmentation.
     41     - worst fit: take worst fitting hole. poor performance in practice.
     42     - quick fit: keep holes of different sizes. poor coalescing performance.
     43     - buddy allocation scheme: improve quick fit's coalescing performance (Linux uses this).
     44         - originally - area of 64 "chunks" (a unit chunk is whatever you want, on UNIX it's 4 kb)
     45         - maintain *n* lists, one per size class
     46         - you split on powers of 2 until you get the right size
     47         - how do you find your buddies? shout eyyyyy buddy