Memory Management Flashcards
What are the two types of variables?
Locally Declared
- part of a stored program
- loaded into memory by the OS
Dynamically allocated
- process asks the OS for some memory (privileged)
- gets a pointer in its own address space
What are logical/virtual and physical addressing?
Logical/Virtual
- generated by the CPU
- what the program “sees” and uses
- bound to physical addresses
- in the virtual address space
Physical
- the actual location of data
- generated by the MMU (memory management unit)
- passed to memory hardware
Difference between compile time and load time binding?
compile time
- compiled code contains physical memory addresses
- inflexible - have to recompile to move proess
load time
- compiler generates re-locatable code (relative addresses)
- process must occupy contiguous memory to work
neither used by modern general purpose OSs
What is a run-time binding?
- run time binding yields different logical and physical addresses
- logical addresses are dynamically mapped to physical ones
- flexible, can occupy non-contiguous memory and can be moved during execution
- MMU carries out the mapping
difference between static and dynamic linking of programs?
- in static linking the linker combines object code of application modules with object code containing system library routines
- this wastes space as each program has a copy of the system library
- if a library routine is changed the program must be re-linked
- in dynamic linking the linker generates an executable with a stub (code specifying how to locate) for each library routine
- the stub is overwritten with the address of the routine on the first execution, subsequent execution incurs no overhead
- all executing programs use the same copy, this requires support from the OS
- if a routine is changed the new version is used next time the program is run
4 types of memory allocation?
Single Contiguous
- All the computer’s memory is available to the single application.
Partitioned
- memory is partitioned into contiguous blocks for each program
- programs have base and limit registers to protect memory
Paging
- dedicated MMU maps pages to frames
- managed in real time
- translates logical to physical
Segmentation
- processes are assigned segments
Describe contiguous memory allocation
processes are simply assigned contiguous memory on top of each other
Describe the function of the limit register
the limit register points to the limit of a program’s contiguous memory, and prevents the process from accessing memory beyond it and traps to the OS
what does the relocation register do?
acts as an offset from the logical address to the physical address
why use variable size regions over fixed size and how?
- fixed size are too restrictive and wasteful
- use a free list instead to search for memory hole large enough for the process and remove it from the list
- on termination the region is returned to the free list
difference between mmap and malloc
mmap is a syscall
- asks the os to allow us access to additional memory
- will update the page table and protection bits
malloc is a library func
- may call mmap if needed
- or just give a pointer to existing memory
- requires some bookeeping
what is a free list?
It operates by connecting unallocated regions of memory together in a linked list
To free a region, one would just link it to the free list. To allocate a region, one would simply remove a single region from the end of the free list and use it. If the regions are variable-sized, one may have to search for a region of large enough size, which can be expensive.