Memory Management Flashcards
Why is memory management relevant to to Operating System?
OS responsible for loading programs into memory, physical addresses are HW dependent.
What is the purpose of memory protection?
Processes share physical memory, need to restrict access to prevent errors and improper access.
What types of variables are there?
Locally declared (part of stored program), loaded into memory by OS
Dynamically allocated, Malloc - process asks for some memory.
What is a logical address?
Memory address generated by the CPU and is in the virtual address space.
what is a physical address?
Memory address generated by the Memory Management Unit (MMU)
Passed to memory hardware and is in the physical address space.
What is address binding?
Mapping symbolic address to physical addresses.
What are the attributes of compiled code?
Contains Physical memory addresses
Inflexible, have to re-compile to move process.
What happens at load time?
Compiler generates relative addresses (re-locatable code)
Process must occupy contiguous region of memory.
What do load time and compile time both result in?
Identical logical and physical memory addresses. (not used)
What is run-time binding?
Yields different logical and physical addresses.
Logical addresses dynamically mapped to physical addresses
What are the advantages of run-time binding?
It’s felxible, process can occupy non-contigous regions of physical memory and can be moved in memory during execution.
What are the disadvantages of run-time binding?
Runtime overheads means HW support required, MMU carries out the mapping.
What is static linking?
Linker combines object code of application modules with object code containing system library routines.
What are the disadvantages of static linking?
Wastes space as each program has a copy of system library
If a library routine is changed program must be re-linked.
What is dynamic linking?
Linker generates executable with stub (code specifying how to locate routine) for each library routine
Stub overwritten with address of routine on first execution. (subsequent execution incurs no overhead)
What are the advantages of dynamic linking?
All executing programs use same copy.
If library routine is changed, new version will be used next time program is run.
What types of allocation are there?
- Single contiguous
- Partitioned
- Paging
- Segmentation
What is single contiguous memory allocation?
Everything goes to one process
What is partitioned memory allocation
Contiguous partition for each program.
HW support for memory protection.
How does segmentation find a memory address
Segment address + offset address
How is memory protected?
Dynamic binding and checking, relocatable regions and resizable contiguous memory space.
How does the OS allow variable size regions of memory?
OS holds a free list.
Search for memory hole large enough for new process assign the memory space and remove the address from the free list.
On termination, region is returned to the free list.
How does virtual memory work?
Logical address space of process, each logical address is bound to a physical address dynamically.
Split into 4kb blocks known as pages.
How is a linux process’s virtual memory structured?
Split into segments:
Code segment
Data segment
BSS (block started by symbol)
Stack Segment
What’s the difference between Mmap and malloc
MMAP: Sys call, asks OS for additional memory and updates page table and protection bits
Malloc is a lib functions, may call mmap or gives a pointer to existing memory. Also does book keeping.
What does the Malloc Data Structure consist of and enable?
Records block size and allocated/free status. Enables coalescing of adjacent free blocks.
Coalascing: Join together two free blocks of memory.