Main Memory - Chapter 8

Protection - processes can only access addresses within its address space

If address is not within base and base + limit, then a trap is thrown.
(base register (also known as relocation register), limit register)
Address binding
Linker or loader will bind the source code address to an absolute address.
- Compile time - it is possible to specify an absolute address here, but you will have to recompile each time
- Load time - code must be relocatable, since start address is not known
- Execution time - binding maybe delayed if the program gets relocated
Logical vs Physical Addresses
Logical address - address referred to by the CPU, since it does not want to deal with the program addresses relocating
Physical address - address seen by the memory unit
The MMU maps the logical address to the physical address
Memory Management Unit
MMU - its job it to translate the logical address into a physical address
One possible way is to add a value for the length of the programs prior, to point to the start of the desired program, base register
Typically deals with execution time binding

Dynamic Loading
Only the parts that needed are loaded into memory
Static linking - when all libs and code are made into one bin file
Dynamic linking - linking is left until execution time, a stub refuses to the code that is needed, this allows for programs to share libraries
Contiguous Allocation (Method 1)
- OS is stored at a low memory
- User processes are in high memory
- Each process has its own slot in a single continuous memory
- MMU maps addresses using the base and limit register
This can allow for processes to move and change size
Variable-partition - the size gap a process needs
Hole - block of available memory

First-fit - put the process in the first hole
Best-fit - put the process in the smallest hole
Worst-fit - put the process in the largest hole
External Fragmentation - total memory exists, but its is not continuous
Internal Fragmentation - available block is larger that what is needed
Paging (method 2)
Allows for non contiguous memory
Frames - physical memory divided into frames
Pages - logical memory divided into pages
Page table - translates pages into frames
Page number - used to index the page table for the frame in memory
Page offset - used in-conjunction page number to define how far you want to look into the frame



Implementation of page tables
Page-table base register - pointer to start of the page table
Page-table length register - size of the table
two memory access - means you have to send address to the page table then to the physical memory
Translation look-aside buffer (TLBs) - basically caches pages that are being access regularly for a quick look up

Memory Protection
protection bits - specifies whether a a page is execute only, read only ...
valid/invalid bit - specifies whether a page is in the logical address space
Shared Pages
shared code - code that is shared between multiple processes
private code - each process does not share there libs
Page table structure
Multi-level/Hierarchical paging - where you have a table that points to another table, this means that the table being pointed to can be stored in virtual memory to free up space
Hashed paging - a hash is used to find the physical address, if multiple pages have the same address then a linked list is used
Inverted page table - stores the address for each page in memory, only searching inside of memory
Swapping
Backing store - disk stores pages that overflow the memory
Roll out, roll in - page is swapped for one in disk
There is a ready queue for pages that are ready on disk
Pages cannot be swapped if waiting