Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Memory addressing: Physical vs. Logical Swapping & Contiguous allocation Paging Segmentation
Types of Addresses
Symbolic addresses
e.g., variable names
Absolute addresses
Code that must run at a specific position in computer memory Specific addresses generated, e.g., by compiler
Relocatable addresses
Can be bound to specific addresses, after compile time
Address Spaces
Logical (a.k.a. virtual)
Addresses manipulated by a program Define the logical address space
Physical
Addresses of physical hardware memory
During execution
We may want to move a program, during execution, from one region of memory to another Addresses will have to be re-bound
Dynamic
Loading: routine not loaded until called
Not operating system dependent
Overlays
A program is divided by the programmer into multiple components or overlays load overlay code/data to use it; need overlay driver
Swapping
A running process needs to be in main memory (RAM) A process in other states (e.g., blocked, waiting) may be saved out to disc
E.g., if it will be waiting a relatively long time, and RAM memory is scarce
Swap out/swap in
Relocatable code is useful If program uses absolute addresses, need to swap back into same memory area Swapping is slow!
Use separate, fast discs Pending I/O must be saved in O/S buffers for a swapped process
Paging
Non-contiguous memory allocation Memory divided into physical frames
fixed size blocks, e.g., 1024 bytes
Fragmentation
External
Free blocks of memory too small to be used Compaction can be used; need relocatable code
Internal
Allocating partitions larger than requested; unused space in partition for a process (more typ. with fixed sized partitions)
Example
Memory frame0 frame1 page0 page1 page2 frame2 frame3 frame4 frame5 (base 10 addresses) What physical addresses correspond to logical address 0, 1024, 3000 (assuming 1024 page size)? Program (process)
Address Structure
Usually the page/frame size is a power of two E.g., 1024, 2048, 4096 This gives memory addresses two parts
Top bits page number Bottom bits page offset
Example
1024 page size 16 bit address Offset is lower 10 bits (2^10 = 1024) Top 6 bits for page number
Page Table
Each process with an address space needs to have a page table
Maintained by operating system (kernel space)
Page table maps from logical page numbers to frame numbers One strategy
Each page table contains the full set of possible entries Size: 2^(number of bits in the address for page number) E.g., 1024 byte page, 16 bit address; 6 bit page number 2^6 entries in each page table = 64 entries
Question: What is the size of a processes page table for a 4096 page size, and 32 bit addresses?
Fragmentation
External
With paging, the external fragmentation problem is solved Every frame of memory can be used
Internal
Average of frame of memory per process lost Because, in general, a process will not have a size in bytes that is evenly divisible by the page size
On a TLB hit, rapidly obtain frame for page On a TLB miss, have to do two memory accesses
But put key, value pair into TLB
Segmentation
Paging divides memory into equal sized units (pages, frames) Segmentation divides memory into different sized units, depending on program parts E.g., stack, data area, code area