Midterm 3 Revision Prof. Sin-Min Lee Department of Computer Science.

Slides:



Advertisements
Similar presentations
Chapters 7 & 8 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Advertisements

Virtual Memory II Chapter 8.
Chapter 8 Virtual Memory
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Part IV: Memory Management
Memory Management Chapter 7.
Fixed/Variable Partitioning
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
CS 311 – Lecture 21 Outline Memory management in UNIX
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Virtual Memory Chapter 8.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
CS 104 Introduction to Computer Science and Graphics Problems
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management 2010.
Virtual Memory Chapter 8.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
Memory Management Chapter 5.
Computer Organization and Architecture
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 3 Memory Management: Virtual Memory
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Memory Management Chapter 7.
Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Dr.
Memory Management Techniques
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Mid2 Revision & VM Prof. Sin-Min Lee. Classification of Digital Circuits Combinational. – Output depends only on current input values. Sequential. –Output.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
Memory Management Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only storage.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Memory.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Memory.
ITEC 202 Operating Systems
Chapter 9 – Real Memory Organization and Management
Chapter 8 Virtual Memory
Lecture 10: Virtual Memory
Main Memory Management
Chapter 9: Virtual-Memory Management
Memory Management.
Main Memory Background Swapping Contiguous Allocation Paging
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Operating Systems Concepts
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
CSE 542: Operating Systems
Presentation transcript:

Midterm 3 Revision Prof. Sin-Min Lee Department of Computer Science

Memory Allocation Compile for overlays Compile for fixed Partitions –Separate queue per partition –Single queue Relocation and variable partitions –Dynamic contiguous allocation (bit maps versus linked lists) Fragmentation issues Swapping Paging

Overlays Overlay Manager Overlay Area Main Program Overlay 1 Overlay 2 Overlay 3 Secondary Storage Overlay 1Overlay 2Overlay 3Overlay 1 0K 5k 7k 12k

Multiprogramming with Fixed Partitions Divide memory into n (possible unequal) partitions. Problem: –Fragmentation Free Space 0k 4k 16k 64k 128k

Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated)

Fixed Partition Allocation Implementation Issues Separate input queue for each partition –Requires sorting the incoming jobs and putting them into separate queues –Inefficient utilization of memory when the queue for a large partition is empty but the queue for a small partition is full. Small jobs have to wait to get into memory even though plenty of memory is free. One single input queue for all partitions. –Allocate a partition where the job fits in. Best Fit Worst Fit First Fit

Relocation Correct starting address when a program starts in memory Different jobs will run at different addresses –When a program is linked, the linker must know at what address the program will begin in memory. Logical addresses, Virtual addresses – Logical address space, range (0 to max) Physical addresses, Physical address space –range (R+0 to R+max) for base value R. User program never sees the real physical addresses Memory-management unit (MMU) –map virtual to physical addresses. Relocation register –Mapping requires hardware (MMU) with the base register

Relocation Register Memory Base Register CPU Instruction Address + BA MA MA+BA Physical Address Logical Address

Storage Placement Strategies Best fit –Use the hole whose size is equal to the need, or if none is equal, the whole that is larger but closest in size. –Rationale? First fit –Use the first available hole whose size is sufficient to meet the need –Rationale? Worst fit –Use the largest available hole –Rationale?

Storage Placement Strategies Every placement strategy has its own problem –Best fit Creates small holes that cant be used –Worst Fit Gets rid of large holes making it difficult to run large programs –First Fit Creates average size holes

Locality of Reference Most memory references confined to small region Well-written program in small loop, procedure or function Data likely in array and variables stored together Working set –Number of pages sufficient to run program normally, i.e., satisfy locality of a particular program

Page Replacement Algorithms Page fault - page is not in memory and must be loaded from disk Algorithms to manage swapping –First-In, First-Out FIFO – Belady’s Anomaly –Least Recently Used LRU –Least Frequently Used LFU –Not Used Recently NUR Referenced bit, Modified (dirty) bit –Second Chance Replacement algorithms Thrashing –too many page faults affect system performance

Virtual Memory Tradeoffs Disadvantages SWAP file takes up space on disk Paging takes up resources of the CPU Advantages Programs share memory space More programs run at the same time Programs run even if they cannot fit into memory all at once Process separation

Virtual Memory vs. Caching Cache speeds up memory access Virtual memory increases amount of perceived storage –Independence from the configuration and capacity of the memory system –Low cost per bit compared to main memory

How Bad Is Fragmentation? Statistical arguments - Random sizes First-fit Given N allocated blocks 0.5  N blocks will be lost because of fragmentation Known as 50% RULE

Solve Fragmentation w. Compaction MonitorJob 3 Free Job 5Job 6Job 7Job 8 5 MonitorJob 3 Free Job 5Job 6Job 7Job 8 6 MonitorJob 3 Free Job 5Job 6Job 7Job 8 7 MonitorJob 3 Free Job 5Job 6Job 7Job 8 8 MonitorJob 3 Free Job 5Job 6Job 7Job 8 9

Storage Management Problems Fixed partitions suffer from –internal fragmentation Variable partitions suffer from –external fragmentation Compaction suffers from –overhead

Placement Policy Determines where in real memory a process piece is to reside Important in a segmentation system Paging or combined paging with segmentation hardware performs address translation

Replacement Policy Placement Policy –Which page is replaced? –Page removed should be the page least likely to be referenced in the near future –Most policies predict the future behavior on the basis of past behavior

Replacement Policy Frame Locking –If frame is locked, it may not be replaced –Kernel of the operating system –Control structures –I/O buffers –Associate a lock bit with each frame

Basic Replacement Algorithms Optimal policy –Selects for replacement that page for which the time to the next reference is the longest –Impossible to have perfect knowledge of future events

Basic Replacement Algorithms Least Recently Used (LRU) –Replaces the page that has not been referenced for the longest time –By the principle of locality, this should be the page least likely to be referenced in the near future –Each page could be tagged with the time of last reference. This would require a great deal of overhead.

Basic Replacement Algorithms First-in, first-out (FIFO) –Treats page frames allocated to a process as a circular buffer –Pages are removed in round-robin style –Simplest replacement policy to implement –Page that has been in memory the longest is replaced –These pages may be needed again very soon

Basic Replacement Algorithms Clock Policy –Additional bit called a use bit –When a page is first loaded in memory, the use bit is set to 1 –When the page is referenced, the use bit is set to 1 –When it is time to replace a page, the first frame encountered with the use bit set to 0 is replaced. –During the search for replacement, each use bit set to 1 is changed to 0

Early memory management schemes Originally used to devote computer to single user: User has all of memory

Limitations of single-user contiguous scheme Only one person using the machine--lots of computer time going to waste (why?) Largest job based on size of machine memory

Next: fixed partitions Created chunks of memory for each job: Job 1Job 2Job

Limitations of fixed partitions Operator had to correctly guess size of programs Programs limited to partitions they were given Memory fragmentation resulted The kind illustrated here is called internal memory fragmentation

Dynamic Partitions

Internal versus external memory fragmentation: Job 8 Space previously allocated by Job 1 Space currently allocated by Job 8

Dynamic Partitions Contiguous memory is still required for processes How do we decide size of the partitions? Once the machine is going, how do old jobs get replaced by new ones?

Dyanmic Partitions: First Fit In this scheme, we search forward in the “free list” for a partition large enough to accommodate the next job Fast, but the gaps left can be large

Dynamic Partitions: Best Fit In this scheme, we try to find the smallest partition large enough to hold the next job This tends to minimize the size of the gaps But it also requires that we keep list of free spaces

Deallocating memory If the block we are deallocating is adjacent to one or two free blocks, then it needs to be merged with them. So either we are returning a pointer to the free block, or we are changing the size of a block, or both

Relocatable Dynamic Partitions We can see that in some cases, a job can “fit” into the combined spaces within or between partitions of the early schemes So how do we take advantage of that space? One way is to move programs while they are in the machine--compacting them down into the lower end of memory above the operating system

Several names for this Garbage collection Defragmentation Compaction All share a problem: relative addressing!

Special registers Early machine architectures went through a phase of “more complexity is better” Few registers, but large sets of commands RISC computers have changed all of that (for architectural reasons we won’t go into in detail)

But... In order to manage dynamic relocatable partitions, two registers were assigned to each partition Note: jobs were not broken into parts, but were relocated whole hog Note that the whole job is stored in memory--still no heavy use of external storage devices

Summary of early schemes These were adequate for batch jobs But speed of components continued to advance Storage devices appear And then the biggie: remote terminals Note that processor speeds double about every 1.5 years--much faster than memory!

To accommodate changes We really need to be able to extend memory by hiding unused parts of programs on storage devices--called virtual memory We can do this if we can break a program into pieces--called pages--that can be independently loaded and removed from memory without affecting the running program

Paged Memory Allows jobs to reside in noncontiguous memory More jobs can be squeezed into memory But—some internal fragmentation, particularly if the number of jobs is large

Disk partitions to page frames Disk partitions varied in size before Now we want to fix the size to match the chunk size of the programs coming in (plus a tiny bit of bookkeeping space) We call these chunks of memory page frames

Is there any fragmentation? We can see that if page frames are chosen right, we shouldn’t have external fragmentation Seldom will the size of code exactly fit the frames, so there will be a little bit of internal fragmentation Tradeoff between internal fragmentation and processor time spent managing frames

Other problems Earliest schemes didn’t allow virtual memory Tables for managing memory a significant part of the operating system--its growing!

Demand Paging Demand paging broke jobs into pieces and became popular because it allowed only parts of jobs to be active in memory New problems: thrashing and page faults

Page Replacement Algorithms Optimal page replacement simply not possible Keep referenced (R) and Modify (M) bits to allow us to keep track of past usage instead –Page is referenced by any read or write in it –Page is modified by any change (write) made to it

Page Replacement Algorithms, Continued FIFO = First in, first out LRU = Least recently used LFU = Least frequently used both of the latter rely on a page request call to the operating system a failure to find a page = page interrupt we might measure quality by failure rate = page interrupts / page requests

Page Replacement Algorithms, Continued Clock page replacement –Hand of the clock points to the oldest page –If a page fault occurs, check R bits in “clockwise” order A variant called the “two-handed clock” is used in some UNIX systems

FIFO solution is not more memory Called Belady’s anomaly the page request order is an important factor, not just the size of memory

LRU Doesn’t suffer from Belady’s anomaly Presumes locality of reference But while it works well, it is a little more complex to implement in software –Consequently, aging and various clock algorithms are the most common in practice –Aging can yield a good approximation

Segmented Memory Allocation Instead of equal divisions, try to break code into its natural modules Compiler now asked to help operating system No page frames--different sizes required (meaning we get external fragmentation again)

Segmented/Demand Paging Subdivide the natural program segments into equal sized parts to load into page frames eliminates external fragmentation allows for large virtual memory, so it is often used in more modern OS’s

Tradeoffs Note that there is a tradeoff between external fragmentation and page faults in paging systems Note also that we probably want slightly smaller page frames in a Segmented- Demand Paging framework

And Onward! Next Thursday we’ll do our Mid3 exam Study guide already posted Don’t miss the exam!