What we will cover…

download What we will cover…

If you can't read please download the document

description

What we will cover…. Memory and Disk Storage Management. Logical vs. Physical Address Space. The concept of a logical address space that is bound to a separate physical address space is central to proper memory management - PowerPoint PPT Presentation

Transcript of What we will cover…

  • What we will coverMemory and Disk Storage Management1-*

    Lecture 5

  • Logical vs. Physical Address SpaceThe concept of a logical address space that is bound to a separate physical address space is central to proper memory managementLogical address generated by the CPU; also referred to as virtual addressPhysical address address seen by the memory unit

    Lecture 5

  • Base and Limit RegistersA pair of base and limit registers define the logical address spaceBound onto main memory physical address space

    Lecture 5

  • Binding of Addresses

    Address binding of instructions and data to memory addresses can happen at three different stagesCompile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changesLoad time: Must generate relocatable code if memory location is not known at compile time

    Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers)

    Lecture 5

  • Logical vs. Physical Address SpaceLogical and physical addresses are the same incompile-time and load-time address-binding schemes;

    logical (virtual) and physical addresses differ in execution-time address-binding scheme

    Lecture 5

  • Dynamic relocation using a relocation register

  • Dynamic LoadingRoutine is not loaded until it is calledBetter memory-space utilization; unused routine is never loadedUseful when large amounts of code are needed to handle infrequently occurring casesNo special support from the operating system is required implemented through program design

    Lecture 5

  • SwappingA process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution Backing store fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images Roll out, roll in swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows)System maintains a ready queue of ready-to-run processes which have memory images on disk

    Lecture 5

  • Schematic View of Swapping

    Lecture 5

  • Contiguous Memory Allocation Multiple-partition allocationHole block of available memory; holes of various size are scattered throughout memoryWhen a process arrives, it is allocated memory from a hole large enough to accommodate itOperating system maintains information about: a) allocated partitions b) free partitions (hole)OSprocess 5process 8process 2OSprocess 5process 2OSprocess 5process 2OSprocess 5process 9process 2process 9process 10

    Lecture 5

  • Dynamic Storage-AllocationFirst-fit: Allocate the first hole that is big enoughBest-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size Produces the smallest leftover holeWorst-fit: Allocate the largest hole; must also search entire list Produces the largest leftover holeHow to satisfy a request of size n from a list of free holesFirst-fit and best-fit better than worst-fit in terms of speed and storage utilization

    Lecture 5

  • External Fragmentation total memory space exists to satisfy a request, but it is not contiguousInternal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being usedReduce external fragmentation by compactionShuffle memory contents to place all free memory together in one large blockCompaction is possible only if relocation is dynamic, and is done at execution timeI/O problemLatch job in memory while it is involved in I/ODo I/O only into OS buffersDynamic Storage-Allocation Problem

    Lecture 5

  • PagingLogical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter is availableDivide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8,192 bytes)Divide logical memory into blocks of same size called pagesKeep track of all free framesTo run a program of size n pages, need to find n free frames and load programSet up a page table to translate logical to physical addressesInternal fragmentation

    Lecture 5

  • Address Translation SchemeAddress generated by CPU is divided into: Page number (p) used as an index into a page table which contains base address of each page in physical memory Page offset (d) combined with base address to define the physical memory address that is sent to the memory unit

    For given logical address space 2m and page size 2npage numberpage offsetpdm - nn

    Lecture 5

  • Paging Hardware

  • Paging Example32-byte memory and 4-byte pages

  • Implementation of Page TablePage table is kept in main memoryPage-table base register points to the page tablePage-table length register indicates size of the page table

    In this scheme every data/instruction access requires two memory accesses. One for the page table and one for the data/instruction.

    The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs)

    Lecture 5

  • Paging Hardware With TLB

  • Hierarchical Page TablesBreak up the logical address space into multiple page tables

    A simple technique is a two-level page table

    Lecture 5

  • Two-Level Page-Table Scheme

  • Two-Level Paging ExampleA logical address (on 32-bit machine with 1K page size) is divided into:a page number consisting of 22 bitsa page offset consisting of 10 bitsSince the page table is paged, the page number is further divided into:a 12-bit page number a 10-bit page offsetThus, a logical address is as follows: where pi is an index into the outer page table, and p2 is the displacement within the page of the outer page tablepage numberpage offsetpip2d121010

    Lecture 5

  • Address-Translation Scheme

    Lecture 5

  • SegmentationMemory-management scheme that supports user view of memory A program is a collection of segmentsA segment is a logical unit such as:main programprocedure functionmethodobjectlocal variables, global variablescommon blockstacksymbol tablearrays

    Lecture 5

  • Users View of a Program

  • Logical View of Segmentation1324user space physical memory space

  • Segmentation Hardware

  • Segmentation Architecture Logical address consists of a two tuple:,Segment table maps two-dimensional physical addresses; each table entry has:base contains the starting physical address where the segments reside in memorylimit specifies the length of the segment

    Since segments vary in length, memory allocation is a dynamic storage-allocation problem

    Lecture 5

  • Example of Segmentation

  • Virtual MemoryVirtual memory separation of user logical memory from physical memory.Only part of the program needs to be in memory for executionLogical address space can therefore be much larger than physical address spaceAllows address spaces to be shared by several processesAllows for more efficient process creation Virtual memory can be implemented via:Demand paging (more popular because of fixed size)Demand segmentation

    Lecture 5

  • Demand PagingBring a page into memory only when it is needed Page is needed reference to itinvalid reference abortnot-in-memory bring to memory

    Lazy swapper never swaps a page into memory unless page will be neededSwapper that deals with pages is a pager

    Lecture 5

  • Steps in Handling a Page Fault

  • Performance of Demand PagingPage Fault Rate 0 p 1.0if p = 0 no page faults if p = 1, every reference is a fault Effective Access Time (EAT)EAT = (1 p) x memory access+ p (page fault overhead + page in + restart overhead)

    Lecture 5

  • What happens if there is no free frame?Page replacement find some page in memory, but not really in use, swap it outalgorithmperformance want an algorithm which will result in minimum number of page faults

    Frame allocation algorithm in memoryHow many frames to allocate to each process

    Lecture 5

  • Page Replacement

  • Page ReplacementUse modify (dirty) bit to reduce overhead of page transfers only modified pages are written to disk

    Lecture 5

  • Page Replacement AlgorithmsWant lowest page-fault rate

    Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string

    In all our examples, the reference string is 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

    Lecture 5

  • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 53 frames (3 pages can be in memory at a time per process)

    4 frames Beladys Anomaly: more frames more page faultsFirst-In-First-Out (FIFO) Algorithm1231234125349 page faults1231235124510 page faults443

    Lecture 5

  • FIFO Page Replacement

  • Optimal AlgorithmReplace page that will not be used for longest period of time4 frames example 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

    12346 page faults45

    Lecture 5

  • Optimal Page Replacement

  • Least Recently Used (LRU) AlgorithmReference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

    Counter implementationEvery page entry has a counter; every time page is referenced through this entry, copy the clock into the counterWhen a page needs to be changed, look at the counters to determine which are to change

    52431234125412531243

    Lecture 5

  • LRU Page Replacement

  • LRU Algorithm (Cont.)Stack implementation keep a stack of page numbers in a double link form:Page referenced:move it to the toprequires 6 pointers to be changedNo search for replacement

    Lecture 5

  • Counting AlgorithmsKeep a counter of the number of references that have been made to each page LFU Algorithm: replaces page with smallest count MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used

    Lecture 5

  • Allocation of FramesEach process needs minimum number of pages

    Two major allocation schemesfixed allocationpriority allocation

    Lecture 5

  • Fixed AllocationEqual allocation For example, if there are 100 frames and 5 processes, give each process 20 frames.Proportional allocation Allocate according to the size of process

    Lecture 5

  • Priority AllocationUse a proportional allocation scheme using priorities rather than size If process Pi generates a page fault,select for replacement one of its framesselect for replacement a frame from a process with lower priority number

    Lecture 5

  • Global vs. Local AllocationGlobal replacement process selects a replacement frame from the set of all frames; one process can take a frame from another

    Local replacement each process selects from only its own set of allocated frames

    Which one is better?

    Lecture 5

  • ThrashingIf a process does not have enough pages, the page-fault rate is very high. This leads to:low CPU utilizationoperating system thinks that it needs to increase the degree of multiprogramminganother process added to the system Thrashing a process is busy swapping pages in and out

    Lecture 5

  • Thrashing (Cont.)

    Lecture 5

  • Thrashing Limit the effects of thrashing by using a local replacement algorithm

    Lecture 5

  • Mass Storage StructureMagnetic disks provide bulk of secondary storage of modern computersDrives rotate at 60 to 200 times per secondTransfer rate is rate at which data flow between drive and computerPositioning time (random-access time) is time to move disk arm to desired cylinder (seek time) and time for desired sector to rotate under the disk head (rotational latency)

    Lecture 5

  • Moving-head Disk Mechanism

  • Disk SchedulingThe operating system is responsible for using hardware efficiently for the disk drives, this means having a fast access time and disk bandwidth.Access time has two major componentsSeek time is the time for the disk are to move the heads to the cylinder containing the desired sector.Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head.Minimize seek timeSeek time seek distanceDisk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer.

    Lecture 5

  • Disk Scheduling (Cont.)Several algorithms exist to schedule the servicing of disk I/O requests. We illustrate them with a request queue (0-199). 98, 183, 37, 122, 14, 124, 65, 67

    Head pointer 53

    Lecture 5

  • First-come first-served (FCFS)Illustration shows total head movement of 640 cylinders.

  • Shortest seek time first (SSTF)Selects the request with the minimum seek time from the current head position.SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests.Illustration shows total head movement of 236 cylinders.

    Lecture 5

  • SSTF (Cont.)

  • SCANThe disk arm starts at one end of the disk, and moves toward the other end, servicing requests until it gets to the other end of the disk, where the head movement is reversed and servicing continues.Sometimes called the elevator algorithm.Illustration shows total head movement of 208 cylinders.

    Lecture 5

  • SCAN (Cont.)

  • C-SCANProvides a more uniform wait time than SCAN.The head moves from one end of the disk to the other. servicing requests as it goes. When it reaches the other end, however, it immediately returns to the beginning of the disk, without servicing any requests on the return trip.Treats the cylinders as a circular list that wraps around from the last cylinder to the first one.

    Lecture 5

  • C-SCAN (Cont.)

  • C-LOOKVersion of C-SCANArm only goes as far as the last request in each direction, then reverses direction immediately, without first going all the way to the end of the disk.

    Lecture 5

  • C-LOOK (Cont.)

  • Selecting a Disk-Scheduling AlgorithmSSTF is common and has a natural appealSCAN and C-SCAN perform better for systems that place a heavy load on the disk.Performance depends on the number and types of requests.Requests for disk service can be influenced by the file-allocation method.The disk-scheduling algorithm should be written as a separate module of the operating system, allowing it to be replaced with a different algorithm if necessary.Either SSTF or LOOK is a reasonable choice for the default algorithm.

    Lecture 5

  • RAID StructureRAID multiple disk drives provides reliability via redundancy.

    RAID is arranged into six different levels.

    Lecture 5

  • RAID (cont)Several improvements in disk-use techniques involve the use of multiple disks working cooperatively. Disk striping uses a group of disks as one storage unit. RAID schemes improve performance and improve the reliability of the storage system by storing redundant data.Mirroring or shadowing keeps duplicate of each disk.Block interleaved parity uses much less redundancy.

    Lecture 5

  • RAID Levels

  • RAID Level 2: detail discussion

  • RAID Level 6: detail discussion

  • RAID (0 + 1)

    ***********************************************************************