230 likes | 245 Views
CSI 400/500 Operating Systems Spring 2009. Lecture #8 – Memory Management February 23 rd through 25 th , 2009. Memory Hierarchy. Primary. Secondary. External. Primary Memory. Used by processors and running processes Includes: Registers – holds operation data for processor
E N D
CSI 400/500 Operating SystemsSpring 2009 Lecture #8 – Memory Management February 23rd through 25th, 2009
Memory Hierarchy Primary Secondary External
Primary Memory • Used by processors and running processes • Includes: • Registers – holds operation data for processor • Cache – holds immediate storage for process • RAM – processing address space
Secondary Memory • Memory not allocated to processors or tasks • Includes “virtual memory”, which is extended memory for tasks containing data not currently being used • Used to store data for extended periods of time • Examples: hard drive, disks, flash drives
External Memory • Storage device external to computer • Located on network, either local or wide • Examples: database server, web page
Memory Manager • Component of Operating System that handles allocation, loading, reading, writing, and clearing of primary and secondary memory • Resolves references and/or calls to external data
Loading • Copying process data stored in RAM or secondary memory into cache memory • “Page loading” • Reading external data and loading into cache memory • “Remote accessing”
Binding • Process of translating virtual address into physical address • Most programs use more storage than cache can hold, so virtual address refers to RAM location without needing extremely long address • Address can still fit into register • Allows for continual extension of “onboard” memory space
Saving • Restore data to secondary memory • “Reallocation” • Write data to external memory • “Uploading”
Allocation • Distributing memory among processes • Process’ available space called “address space” • Three main techniques: • Fixed-Partition • Variable-Partition • Dynamic
Fixed Partition Allocation • Called pages • System has predetermined page size • Only one page per process in cache at a time • Common in batch and time-share systems
How Paging Works • Process allocated a page • Data is filled in from start to end • New data added to end of last data block, allowing for data boundaries • If page fills, new page is allocated • Pages tracked with Page Table • We’ll discuss that in a few sessions
Internal Fragmentation • If data freed during process, Memory Manager will attempt to reuse • Desired data must be same size or smaller • Could leave “holes” on page, called “internal fragmentation” • Internal fragmentation cleared by page reallocation • Copies existing data to new page, then clearing old page
Variable Partition Allocation • Called segments • Memory Manager obtains storage as process produces data or needs external data • All current processes share memory • Each process has its own piece of memory • Common in Client-Server systems
How Segmentation Works • System starts with blank page • Processes are created and queued • Initial data for each process allocated a segment • Segments contiguous in storage • New segments added if processes created or processes demand more
External Fragmentation • As processes release data or processes complete, data is freed • System tries to reuse data • Request must be at most same size • Could leave “holes” called “external fragmentation” • Freed storage too small to use at current time • Most systems maintain a Free Space table to track these fragments
Defragmentation • Also called “dynamic relocation” • Moving segments to fill external fragments • Logical addresses reset using dynamic binding • We’ll discuss that with dynamic allocation
Dynamic Allocation • Process allowed to specify and change size of its storage • If that much space is not available, process held until space is available • Often requested storage obtained in chunks, using multiple free space fragments • Space chained together via linked list
Dynamic Binding • Memory Manager can move segment around as process executes • All process data referenced by symbol name • Variable name if defined, or system-created name • Process maintains Symbol Table to resolve reference • Dynamic Binding means Memory Manager resolves to new physical address when process references data
How Dynamic Binding Works • When data placed in segment, entry added to symbol table • Entry is offset in segment • Processor has Relocation Register • Contains start address of segment • Segment moves due to dynamic relocation • Address in relocation register changes • Subsequent reference resolves to new physical location
Swapping • Process of saving process’ current address page to secondary storage and loading new address page • Process is blocked during this time, as execution requires new data
Swapping Process • Process requests non-resident data • Processor blocks process and sends I/O interrupt • Interrupt Handler contacts Memory Manager with data reference • Memory Manager swaps out current page, finds new page, and swaps it in • Tells Interrupt Handler it is done • Interrupt Handler releases process to Ready queue