Main Memory (9) Flashcards
1
Q
Compiling Programs
A
2
Q
Memory Protection
A
- Required to ensure correct operation
- Making sure a process can access only memory location in its address space
-
base and limit registers come handy
- used to give each process a separate address space
-
base and limit registers come handy
3
Q
Address Binding
A
- First user process physical address always at 0000
- Addresses are mapped to different domains at different stages
- source code: symbolic addresses
- compiled code: address bind to relative addresses
- example: 14 bytes from the beginning of the program code
- linker or loader will bind relocatable addresses to absolute
- Addresses are mapped to different domains at different stages
- Where binding to real addresses can happen:
- compile time: if mem. loc is known apriori
- load time: must generate relocatable code if mem. location is not known
- execution time: binding delayed until run time if proc. can be moved around during exectuing
- need hw support for address maps
4
Q
Logical vs. Physical address space
A
- Logical generated by CPU: referredto as virtual address
- Physical address: seen by the memory unit
- Address binding schemes where Logical === Physical:
- compile-time
- load-time
- Address binding schemes where Logical !== Physical:
- execution-time
5
Q
MMU
A
- Memory management unit
- HW dev that maps virtual addresses to physical.
- Simple scheme
- relocation register := base register
- value of reloc. reg. is added to every address generated by a request by the process and sent to memory
- User program uses virtual addresses
- everything is done at execution-time, when reference is made
6
Q
Dynamic Loading
A
- A whole program doesn’t need to be in memory to be executed, a routine can be loaded when called
- To achieve this:
- routines kept on disk in a relocatable load format
- Main memory space is less used
- Good if there are large chunks of code that are needed to handle infrequnt cases
- OS don’t need to support it, can be implemented in program design.
- It can help though, by providing dynamic loading libraries
7
Q
Dynamic Linking
A
- Static Linking: system libs and program code are combined at the load stage
-
Dynamic Linking (aka Shared Libraries): linking is done at execution time
- The code as pointer to small piece of code that locates memory-resident library routines and replaces the pointer to itself with the address of the routine. (stub)
- OS checks if routine is in processes memory address
- if not, it adds to the address space of the proc.
- Dynamic linking is useful
- Versioning may be needed!
8
Q
Contiguos allocation
A
Main memory is split in two partitions:
- resident OS
- usually in low mem with IVT
- User processes in high memory
- Each process in single contiguos section of mem
- limit and base(relocation) registers used to confine user process
- MMU maps logical address dynamically
- Can allow for things like kernel code being transient and changing size.
9
Q
Variable Parition and Dynamic Storage-Alloc. Problem
A
- Number of process in main memory at a time is limited
- Variable parition sizes is necessary for efficiency
- Hole: block of not used memory
- OS tracks free and occupied partitions
- New process arrives: take mem. from hole
- Strategies:
- First-fit: first that fits
- Best-fit: the smallest one that fits
- Worst-fit: largest hole
- First-fit and best-fit are faster and use less storage
- Strategies:
- Processes exiting its parition.
10
Q
Fragmentation
A
- External: the sum of the free space is enough to satisfy request, but it’s not contiguos
- Can be reduced with compation
- possible only if relocation is dynamic and done at exec. time
- I/O is a problem
- Latch job in memory while it is doing I/O
- Do I/O only through OS buffers
- Can be reduced with compation
- Internal: allocated memory > requested memory -> wasted space
- First-fit analysis: N blocks allocated, N/2 lost to fragmentation
- Backing store has same frag. problems
11
Q
Paging
A
- A process can be allocated in a non contiguos address space
- Avoids external fragmentation
- Avoids the problem of memory chunks of different sizes
- Internal fragmentation stays
- Basically:
- Divide physical memory into fixed-sized blocks called frames (power of 2, between 512B and 16MB)
- Divide logical memory into blocks of the same size called pages
- Keep track of free frames
- We need N frames if a program need N pages
- Page table translates logical addresses to physical
12
Q
Paging Address Translation
A
- CPU generated addresses (logical) are divied in:
- Page number (p): used as an index into a page table to get base physical address
- Page offset (d): combined with the base physical address is the address of the object we want
Page size = 2^n
Logical address space = 2^m
size of p = m - n
d = n
13
Q
Paging: calculating internal frag.
A
- Page size = 2048B
- Process size = 72766B
- Required mem = 35 pages + 1086B
- Internal Frag. = Page size - 1086B
- Worst case Internal Frag = Page size - 1B
- Small size pages better?
- Mhmm, consider that every page needs to be tracked in the page table
- More pages -> more memory needed
14
Q
Page table implementation
A
- Page table is stored in main mem.
- Page table base register (PTBR) -> points to page table
- Page table length register (PTLR) -> is the size of the table
- Paging requires that at every data/instruciton access we do 2 memory accesses
- page table + data/instruction
- Mitigated by Translation look-aside buffers (TLBs) aka associative memory
15
Q
TLB
A
- Translation Look-Aside Buffer
- Some store address-space identifiers in each TLB entry - uniquely idenitfies processes to provide address-space protection
- others need to flush at every context switch
- Usally small (64 to 1024 entries)
- On a TLB miss, value is loaded into TLB for faster access next time
- Various replacement policies
- Some entries can be wired down to be permanent
Effective Access Time (EAT) = HitRatio * MemAccessTime + (1-HitRatio) * 2 * MemAccessTime