chapter 2 part 1

31
Memory and process management Part 1: Memory Management of OS

Upload: jeff

Post on 04-Nov-2015

215 views

Category:

Documents


0 download

DESCRIPTION

part1

TRANSCRIPT

  • Memory and process managementPart 1: Memory Management of OS

  • Learning outcomeAt the end of this chapter, students will be able to:1) Identify between resident and transient routines2) Explain the following terminology:- Fixed-partition memory management- Dynamic memory management- Segmentation- Paging3) Explain dynamic address translation4) Explain how virtual memory works

  • Memory management goalsMemory management is concerned with managing:The computers available pool of memory Allocating space to application routines and making sure that they do not interfere with each other.

  • Resident & Transient RoutinesThe operating system is a collection of software routines.

    Resident routinesTransient routinesRoutines that directlysupport applicationprograms as they runStored on disk and readinto memory only whenneededExample: routine that control physical I/OExample: routine that formats disks

  • Resident & Transient Routines Generally, the operating system occupies low memory beginning with address 0. Key control information comes first followed by the various resident operating system routines. The remaining memory, called the transient area, iswhere application programs and transient operating system routines are loaded.Resident & transient routines structure

  • Fixed-partition memory managementThe simplest approach to managing memory for multiple, concurrent programs.

    On many systems, multipleprograms are loaded intomemory and executedconcurrently.

  • Fixed-partition memory managementDivides the available space into fixed-length partitions, each of which holds one program.Partition sizes are generally set when the system is initially started, so the memory allocation decision is made before the actual amount of space needed by a given program is known.Advantages:- Its major advantage is simplicityDisadvantages:Because the size of a partition must be big enough to hold the largest program that is likely to be loaded, fixed-partition memory management wastes space

  • Fixed-partition memory managementFixed-partition memorymanagement divides theavailable space into fixed lengthpartitions each ofwhich holds one program.Fixed-partition memory management structure diagram

  • Dynamic memory managementUnder dynamic memory management, the transient area is treated as a pool of unstructured free space.When the system decides to load a particular program, a region of memory just sufficient to hold the program is allocated from the pool.Advantages: Because a program gets only the space it needs relatively little is wasted.However, dynamic memory management does not completely solve the wasted space problem.Fragmentation (bits of unused space spread throughout memory) is a possible problem.

  • Dynamic memory management3 algorithm for searching free block for a specific amount of memory:1) First fit- Allocate the first free block that is large enough for the new process.- This a fast algorithm.2) Best fit - Allocate the smallest block among those that are large enough for the new process.- OS search entire list, or it can keep it sorted and stop it when it has an entry which has a size larger than the size of process.- This algorithm produces the smallest left over block.

  • Dynamic memory management3) Worst fit- Allocate the largest block among those that are large enough for the new process.- Search or sorting of the entire list is needed.- This algorithm produces the largest left over block.

    Compaction:Method to overcome the external fragmentation problem.All free blocks are brought together as one large block of free space.

  • Dynamic memory managementAssume, for example, that a 640K program has just finished executing.If there are no 640K programs available, the systemmight load a 250K program and a 300K program, but note that 90K remains unallocated.If there are no 90K or smaller programs available, the space will simply not be used. Over time, little chunks of unused space will be spread throughout memory, creating a fragmentation problem.

  • SegmentationConcept : based on the common practice by programmers of structuring their program in modulesSegmentation scheme : each job is divided into several segment of different sizes. One for each module that contains pieces that perform related function Main memory is no longer divided into page frames because the size of each segment is different (some are large some are small)When a program is compiled the segment are set up according to the programs structural modules.

  • SegmentationA program is a collection of segments. A segment is a logical unit such as:Main program ,subroutineProcedureFunctionMethodObjectLocal variable, global variable,Stack, array ,symbol table

  • SegmentationMemory-management scheme that supports user view of memory.

    Users View of a Program

  • Segmentation1324user space physical memory space

  • SegmentationWith segmentation, programs are divided into variable size segments, instead of fixed size pages.Every logical address is formed of a segment name and an offset within that segment.In practice, segments are numbered.Programs are segmented automatically by compiler or assembler.

  • SegmentationFor logical to physical address mapping, a segment table is used.When a logical address is generated by processor:Base and limit values corresponding to segment s are determined using the segment table.The OS checks whether d is in the limit. ( 0
  • Segmentation SMT map two dimensional physical address; each table has length : specifies the size of the segment base : contain the starting physical address where the segments reside in memory (memory address)

    lengthbase

  • SegmentationDynamic address translation.To dynamically translate a segment address to an absolute address:1) Break the address into segmentand displacement portions2) Use the segment number to find the segments absolute entry pointaddress in a program segment table3) Add the displacement to the entry point address.

  • PagingA programs segments can vary in length. Under paging, a program is broken into fixed-length pages. Page size is generally small (perhaps 2K to 4K), and chosen with hardware efficiency in mind.Like segments, a programs pages are loaded into noncontiguous memory.Addresses consist of two parts , a page number in the high-order positions and a displacement in the low-order bits.Addresses are dynamically translated as the program runs. When an instruction is fetched, its base-plus displacement addresses are expanded to absolute addresses by hardware. Then the pages base address is looked up in a program page table (like the segment table, maintained by the operating system) and added to the displacement.

  • PagingBefore execute a program/job, Memory Manager prepares it by : Determining the number of pages in the program Locating enough empty pages frames in main memory Loading all of the programs pages into pages framesWhen program/job is initially prepared for loading, pages are in logical sequence (the 1st page contain the first instructions of the program and last page has the last instructions)Program instruction can be thought as lines of code or bytes.

  • PagingThe loading process is different from the previous schemes because the pages do not load in contiguous memory blocks.Each page can be stored in any available page frame. Anywhere in main memory

  • Paging

  • Paging

  • Virtual MemoryThe word virtual means not in actual fact.Virtual memory it is a illusion of a memory which is different from a real memory (RAM) existing in a computer systemTo the programmer or user, virtual memory acts just like real memory, but it isnt real memory.This memory maybe much larger than the real memory.Virtual memory is a model that holds space for the operating system and several application programs. The operating system and selected pages occupy real memory. Application programs are stored on an external paging device. The basis of VM implementation is noncontiguous memory allocation

  • Virtual MemoryNoncontiguous allocation permit parts of a program to be loaded into two or more non-adjacent areas of memory executionThis technique is reduce the problem of memory fragmentation since free area memory can be reused even the size is small than free memory.VM implementation is an arrangement which enable program to execute even when its entire code and data are not present in the memory

  • Virtual MemoryThe idea is to load required portion of code /data in memory at any time By this arrangement allow execution of program which size program exceed the size of memory.This strategy increases the number of program which can accommodated in memory.All modern general-purpose computer operating systems use virtual memory techniques for ordinary applications, such as word processors, spreadsheets, multimedia players, accounting, etc

  • Virtual memory structure

  • Virtual memory structureVirtual memory is a model that simplifies address translation. It contains the operating system and all the application programs, but it does not physically exist anywhere. Its contents are physically stored in real memory and on the external paging device.Divided into two components.First componentsThe first is exactly equal to the amount of real memory on the system and is physically stored in real memory. It contains the resident operating system and the transient program area (called the page pool).

  • Virtual memory structure2) Second componentsThe second component of virtual memory consists of space over and above real memory capacity. It is physically stored on the external paging device and contains the application programs. The operating system is loaded into real memory.Application programs are loaded onto the external paging device. Selected pages are then swapped between the real memory page pool and the external paging device