1 / 77

Memory Management:

Memory Management:. Introduction. Introduction. Management of main memory is critical Entire system performance dependent on two items How much memory is available Optimization of memory during job processing This chapter introduces: Memory manager Four types of memory allocation schemes

indra
Télécharger la présentation

Memory Management:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Memory Management: Introduction

  2. Introduction Management of main memory is critical Entiresystem performance dependent on two items How much memory is available Optimization of memory during job processing This chapter introduces: Memory manager Four types of memory allocation schemes Single-user systems Fixed partitions Dynamic partitions Relocatable dynamic partitions

  3. What is memory? In computing, memory refers to the physical devices used to store programs (sequences of instructions) or data on a temporary or permanent basis for use in a computer or other digital electronic device. Cache memory is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations. The term primary memory is used for the information in physical systems which are fast (i.e. RAM), as a distinction from secondary memory, which are physical devices for program and data storage which are slow to access but offer higher memory capacity. Primary memory stored on secondary memory is called "virtual memory“.

  4. Memory Hierarchy Memory hierarchy is used in the theory of computation when discussing performance issues in computer architectural design, algorithm predictions, and the lower level programming constructs such as involving locality of reference. A 'memory hierarchy' in computer storage distinguishes each level in the 'hierarchy' by response time. Since response time, complexity, and capacity are related, the levels may also be distinguished by the controlling technology. There are four major storage levels. Internal – Processor registers and cache. Main – the system RAM and controller cards. On-line mass storage – Secondary storage. Off-line bulk storage – Tertiary and Off-line storage.

  5. Memory Management: Early System

  6. Single-User Contiguous scheme • Each program is loaded in its entirety into memory and allocated as much contiguous space as it needed. • Once the program is loaded into memory, it remains there until execution is complete. • Only one program can be loaded in memory. • Advantage: • Simple • Disadvantages: • If the program is larger than the available memory space, it couldn’t be executed. Program size must be less than memory size to execute. • It doesn’t support multiprogramming. • Possible solutions: • The size of main memory must be increased. • The program must be modified to make it smaller.

  7. Fixed Partitions • Memory is divided into many unequal size, fixed partitions. • Each partition has to be protected. • Before loading a job, its size must be matched with the size of the partition to make sure it fits completely. • Only one job can be loaded into a partition. • The memory manager must keep a table showing each partition size, address, and its current status (free/busy). • Advantage: • Multiprogramming. • Disadvantages: • If partitions sizes are too small, big jobs are rejected. • If partitions are too big, memory is wasted. • Internal fragmentation (fragment within a block). • Still, entire and contiguous jobs are required.

  8. Dynamic Partitions Main memory is partitioned Jobsgiven memory requested when loaded One contiguous partition per job Job allocation method First come, first serve allocation method Memory waste: comparatively small Disadvantages Full memory utilization only during loading of initial jobs Subsequent allocation: memory waste External fragmentation: fragments between blocks

  9. Job allocation policies • How the OS Keeps track of the free sections of memory? • First-fit • Best-fit • First-fit: The first partition that fits the job. • Best-fit: The smallest partition that fits the job. • In first-fit, Memory Manager organizes the free/busy lists by memory location. • In best-fit, Memory Manager organizes the free/busy lists by size.

  10. Best-Fit Versus First-Fit Allocation First-fit memory allocation: first partition fitting the requirements Leads to fast allocation of memory space Best-fit memory allocation: smallest partition fitting the requirements Results in least wasted space Internal fragmentation size reduced, but not eliminated Fixed and dynamic memory allocation schemes use both methods

  11. Advantages & Disadvantages • First-fit: • Advantages: • Fast. • Disadvantages: • Large jobs must wait for the large spaces. • memory waste. • Best-fit: • Advantages: • Best use of memory space. • Disadvantages: • Wasting time looking for the best memory block.

  12. Advantages & Disadvantages of Dynamic Partitions • Advantages: • External fragmentation problem is solved. • Best use of memory space. • Disadvantage: • More overhead* (due to compaction) is incurred than with the two previous schemes. *overhead is any combination of excess or indirect memory that are required to attain a particular goal.

  13. Relocatable Dynamic Partitions Memory Manager relocates programs Gathers together all empty blocks Compact the empty blocks Make one block of memorylarge enough to accommodate some or all of the jobs waiting to get in Compaction: reclaiming fragmented sections of memory space Every program in memory must be relocated Programs become contiguous Operating system must distinguish between addresses and data values Every address adjusted to account for the program’s new location in memory Data values left alone

  14. Compaction issues: What lists have to be updated? What goes on behind the scenes when relocation and compaction take place? What keeps track of how far each job has moved from its original storage area? What lists have to be updated? Free list Must show the partition for thenew block of free memory Busy list Must show the new locations for all of the jobs already in process that were relocated Each job will have a new address Exception: those already at the lowest memory locations

  15. What goes on behind the scenes when relocation and compaction take place? What keeps track of how far each job has moved from its original storage area? In order to address the two last questions, special-purpose registers are used for relocation: Bounds register Stores highest location accessible by each program Relocation register Contains the value that mustbe added to each address referenced in the program Must be able to access the correctmemory addresses after relocation If the program is not relocated, “zero” value storedin the program’s relocation register

  16. Compacting and relocatingoptimizes use ofmemory Improves throughput The crucial factor is the timing of the compaction –when and how often it should be done Options for timing of compaction: When a certain percentage of memory is busy When there are jobs waiting to get in After a prescribed amount of time has elapsed Goal: optimize processing time and memory use while keeping overhead as low as possible

  17. Summary Four memory management techniques Single-user systems,fixed partitions, dynamic partitions, and relocatable dynamic partitions Common requirements of four memory management techniques Entire program loaded into memory Contiguous storage Memory residency until job completed Each places severe restrictions on job size Sufficient for first three generations of computers

  18. Memory Management: Recent System

  19. Introduction The basic functionality of the memory allocation methods covered in this chapter: paged, demand paging, segmented, and segmented/demand paged memory allocation. The influence that these page allocation methods have had on virtual memory. The difference between a first-in first-out page replacement policy, a least-recently-used page replacement policy, and a clock page replacement policy. The mechanics of paging and how a memory allocation scheme determines which pages should be swapped out of memory. The concept of the working set and how it is used in memory allocation schemes. The impact that virtual memory had on multiprogramming.

  20. Paged Memory Allocation Divides each incoming job into pages of equal size Best condition Page size = Memory block (page frame) size = Size of disk section (sector) Sizes depend on operating system and disk sector size Memory manager tasks prior to program execution Determines number of pages in program Locates enough empty page frames in main memory Loads all program pages into page frames Advantage of storing program non-contiguously New problem: keeping track of job’s pages

  21. Job Table Page Map Table Memory Map Table

  22. Three tables for tracking pages: 1. Job Table (JT) contains Size of each active job and Memory location where its PMT is stored One JT for the wholesystem 2. Page Map Table (PMT) contains Page number and Its corresponding page frame address One PMT for each job 3. Memory Map Table (MMT) contains Locationfor each page frame and Free/busy status One MMT for the wholesystem

  23. Displacement (offset) of a line (statement) To determine line distance from beginning of its page Used to locate line within its page frame A relative value Determining page number and displacement of a line Divide job space address by the page size Page number: integer quotient from the division Displacement: remainder from the division

  24. Steps to determining exact location of a line in memory Determine page number and displacement of a line Refer to the job’s PMT Determine page frame containing required page Obtain address of the beginning of the page frame Multiply page frame number by page frame size Add the displacement (calculated in first step) to starting address ofthe page frame Address resolution Translating job space address into physical address Relative address into absolute address

  25. Advantage Allows job allocation in non-contiguous memory Efficient memory use Disadvantages Increased overhead from address resolution Internalfragmentation in last page Must store entire job in memory location Page size selection is crucial Too small: generates very long PMTs Too large: excessive internal fragmentation

  26. Demand Paging Introduced the concept of loading only a part of the program into memory for processing – the first widely used scheme that removed the restriction of having the entire job in memory from beginning to the end of its processing. Pages are brought into memory only as needed Removes restriction: entire program in memory Requires high-speed page access Exploits programming techniques Modules written sequentially All pages not necessary needed simultaneously

  27. Allowed for wide availability of virtual memory concept Provides appearance of almost infinite or nonfinite physical memory Jobs run with less main memory than required in paged memory allocation scheme Requires high-speed direct access storage device Works directly with CPU Swapping: how and when pages passed in memory Depends on predefined policies

  28. Memory Manager requires three tables: Job Table Page Map Table: additional three new fields If requested page is already in memory If page contents have been modified If page has been referenced recently Determines which page remains in main memory and which is swapped out Memory Map Table

  29. Swapping Process Exchanges resident memory page with secondary storage page Involves Copying resident page to disk (if it was modified) Writing new page into the empty page frame Requiresclose interaction between: Hardware components Software algorithms Policyschemes

  30. Hardware instruction processing Page fault: failure to find page in memory Page fault handler Part of operating system Determines if empty page frames in memory Yes: requested page copied fromsecondary storage No: swapping occurs Deciding page frame to swap out if all are busy Directly dependent on the predefinedpolicy for page removal

  31. Thrashing An excessive amount of page swapping between main memory and secondary storage Due to main memory page removal that iscalled back shortly thereafter Produces inefficient operation Occurs across jobs Large number of jobs competing for a relatively few number of free pages Occurs within a job In loops crossing pageboundaries

  32. Advantages Job no longer constrained by the size of physical memory (concept of virtual memory) Utilizes memory more efficiently than previous schemes Faster response Disadvantage Increased overhead caused by tables and page interrupts

  33. Page Replacement Policies and Concepts Policy to select page removal Crucial to systemefficiency Page replacement polices First-In First-Out (FIFO) policy Best page to remove is one in memory longest Least Recently Used (LRU) policy Best page to remove is least recently accessed Mechanics of paging concepts

  34. First-In First-Out (FIFO) Removes the longest page in memory Efficiency: Ratio of page faults to page requests FIFO example: not so good Efficiency is 9/11 or 82% FIFO anomaly: More memory frames does not lead to better performance

  35. Least Recently Used (LRU) Removes the leastrecently accessed page Efficiency: Causes either decrease in or same number of page interrupts (faults) Slightly better (compared to FIFO): 8/11 or 73% LRU is a stack algorithm removal policy Increasing main memory will cause either a decrease in or the same number of page interrupts Does not experience FIFO anomaly

More Related