Storage Management - Chap 10 MANAGING A STORAGE HIERARCHY on-chip --> main memory --> 750ps - 8ns ns. 128kb - 16mb 2gb -1 tb. RATIO 1 10 hard disk --> cartridge tape system ms. seconds 1gb - 1 tb. infinite RATIO:100,000 10,000,000
Storage Management Algorithms Fetch -- what object’s storage to bring into memory -- SWAP IN Placement -- what empty slot to use to satisfy a storage request Replacement -- what used slot(s) to free to satisfy a storage request -- SWAP OUT
New and Malloc 1. Round the requested size; e.g. to an aligned memory address or minimum block size. Results in internal fragmentation. 2. Search the free space data structure 3. Split the block(s) found, if required Free 1. Coalesce multiple free blocks into one
Fixed-Size Requests 1. Linked list or bit map data structure Varying-Size Requests 1. Bit map data structure Results in small unusable fragments, external fragmentation May require de-fragmentation routine 2. Overhead of the data structure is referred to as table fragmentation
Bit Map Example allocate(3) returns allocate(5) returns free(11, 2)
Program Model Multiple Segments, consisting of at least Code, Data, Stack, Heap
Requirements It should be possible to control access to an segment. For example, writing over a procedure should be illegal. It should be possible to validate access to an segment. The arguments to a procedure should always be of the correct type and it should not be possible for a procedure to access segments outside its sphere of influence (principle of least privilege). The size of a segment can vary dynamically and be arbitrarily large. Each segment can be shared in a controlled manner among any number of processes. A segment can dynamically link to other segments by referring to their symbolic names at execution time.
Hardware Placement Options
Hardware Placement Support NONE Static Relocation Onion Skin Algorithm Operating System 0 Program One 100,000 Top of Program Two
Hardware Placement Support One Relocation Register (base/limit) Dynamic Relocation Operating System 0 Program One 100,000 All of Program Two 250,000 PHYSICAL ADDRESSES LOGICAL ADDRESSES Base=0 Limit=99,999 Base=100,000 Limit=249,999 Base=250,000 Limit=299,999
Hardware Placement Support Two Relocation Registers (base/limit) One for Code, One for Data/Stack Operating System 0 DATA STACK V ^ CODE 100,000 All of Program Two 250,000 PHYSICAL ADDRESSES LOGICAL ADDRESSES Limit=249,999 Base=150,000 Limit=149,999 Base=100,000
Hardware Placement Support Multiple Relocation Registers SEGMENT TABLE LOGICAL ADDRESS OFFSETSEGMENT NO. SEGMENT TABLE PHYSICAL ADDRESS OFFSETSEGMENT BASE ADDR.
Hardware Placement Support Multiple Segments
Segments Vary in Size SO We still have the external fragmentation problem BUT We meet all the requirements for managing our Program Model
Paging to Solve Placement Make all requests the same size
Paging Solves Placement Only but not Program Model
Replacement What is a process’ page fault rate? t - the access time to main store T - the access time to a page on disk f - the fraction of a program kept in main store. p(f) - the average number of page faults per store reference as a function of f (0<=p(f)<=1).
Replacement What is a process’ page fault rate? FAULT INTERARRIVAL TIME >= PAGE TRANSFER TIME FROM DISK t/p(f) >= T t/(1-f) >= T assume random f >= 1 - t/T t = 50ns T = 5ms t/T = 1/100,000
Conclusion A program with a random page reference pattern is BAD!! Luckily, for loops, arrays, recursion, stack access all increase Program Locality
Replacement Algorithms SCOPE –Global : take pages from anybody –Local : only take pages from process that caused the page-not-in-memory fault ALLOCATION –Fixed : physical memory per process is limited –Variable : physical memory per process can grow or shrink during execution
Replacement Algorithms page reference trace TIME Refs 5 PAGES, 15 TIME PERIODS
Replacement Algorithms least-recently used
CANNOT IMPLEMENT IN PRACTICE The little matter of a stack of thousands of page #s LRU Approximation Add bits to each page table entry DIRTY - set on a write ACCESSED - set on a read/write
LRU Approximation Clock Algorithm At certain clock ticks, –Step a sweep pointer through every page table for a certain number of entries e.g. 100 IF THE PAGE TABLE POINTS TO PHYSICAL MEMORY –DIRTY ACCESSED ACTION – F F Take that page away – F T Turn ACCESSED off – T T Turn ACCESSED off – T F Write page to disk (clean) then turn DIRTY off