Memory Management I
Tom Kelliher, CS 311
Apr. 11, 2012
Introduction to Linux kernel modules.
- Address binding, loading, libraries, and overlays.
- Logical and physical address spaces.
- Swapping.
- Contiguous and non-contiguous allocation.
Memory management II.
- Address binding, loading, libraries, and overlays.
- Logical and physical address spaces.
- Swapping.
- Contiguous and non-contiguous allocation.
Assumption: several processes competing for memory. Questions to keep in
mind:
- How is memory allocated among processes?
- Sharing?
- Contiguous/non-contiguous allocation?
- Fixed- or variable-sized allocation chunks?
- Over-commitment. What happens?
- Sometimes, a program can't be loaded ``just anywhere'' in memory.
- When does a symbolic name become associated with a memory location?
- How is that location addressed? (Direct, indexed, indirect, etc.)
Address binding options and consequences
- Compile time. Absolute (direct) addressing used. Program must be loaded into memory at a fixed location. MS-DOS .COM
programs.
- Load time. Compiler/linker insert ``dummy'' references in code.
Loader knows load address at run time, finds and fixes-up dummy references.
- Addressing modes?
- Re-location? Must re-load to re-locate.
- Run time. Pc-relative or base addressing. Base register points to
load address.
- On-demand module loading -- ``lazy'' loading.
- Load only what's necessary.
- Static linking -- link at compile-time.
- Larger binaries -- wasted disk space.
- Must re-link source when updating libraries.
- Dynamic linking (shared libraries) -- link at run-time.
- Smaller binaries.
- Stubs: locating the library in memory or on disk.
- Automatic library updates to fix library faults in all
binaries. (With static must re-link all binaries.)
- Shared libraries. Major (new version #) and minor (same version
#) versions.
- DLLs in Wintel world. Broken programs.
Umm, my program is larger than physical memory. What do I do? Example:
two-pass assembler.
Logical = Virtual
Recall:
- Program (CPU) generates logical addresses.
- MMU converts them to physical addresses.
- Compile-time, load-time binding: physical address = logical address.
Simple MMU scheme:
Note: Program can utilize compile-time binding.
- Process must be entirely in memory to execute.
- If in ready Q, can swap-out to ``backing store.''
- If in I/O wait must ``lock'' in memory. Why?
- Must process be swapped-in to same memory space? Depends on loader
design.
- What needs to be swapped out, exactly? The entire partition? The
entire process space?
- Swapping in Unix occurs:
- The system page map has become too fragmented to allocate page
tables for some process.
- There are at least two runnable processes, the average amount of
free memory has been less than that desired (desfree) over the
last 5 and 30 seconds, and either the paging rate is excessive or the
short-term average free memory is less than minfree.
- A swapped-out process is ready to run and a process is found in
memory that has been sleeping for at least 20 seconds; or the
swapped-out process has been out for at least 10 seconds and the process
chosen for swapping out has been in memory at least 20 seconds.
Key: contiguous.
What are we leading up to, here?
- Only one process in memory at a time.
- Must swap to do a context switch. Speed?
- Unused Memory: internal fragmentation.
- Partitions usually of differing sizes.
- Job placement policy.
- Can swap jobs in and out of partitions.
- Internal fragmentation.
- Number of partitions varies.
- Partitions allocated according to process requirements.
- What if a process grows?
- Free list of unallocated holes.
- Placement policies:
- First fit. Best time.
- Best fit.
- Worst fit -- worst time, storage utilization.
- External fragmentation.
- Combining adjacent holes.
- Memory compaction -- must be using relocatable code. Minimizing
copying.
Thomas P. Kelliher
2012-04-10
Tom Kelliher