36
3.0 : Resource Management Part 1 : Memory Management

3.0 : Resource Management Part 1 : Memory Management

Embed Size (px)

Citation preview

Page 1: 3.0 : Resource Management Part 1 : Memory Management

3.0 : Resource Management

Part 1 : Memory Management

Page 2: 3.0 : Resource Management Part 1 : Memory Management

Learning Outcomes

• Understand the Memory Management• Types of memory allocate scheme

• Single – User Configuration • Fixed – partition memory management• Dynamic memory management• Paging• Segmentation

• Virtual Memory • Dynamic Address Translation

Page 3: 3.0 : Resource Management Part 1 : Memory Management

Primary Activities Perform in Memory management

• Keep track of which part of memory are currently being used and by whom.

• Decide which process to load when memory becomes available

• Allocate and deal locate memory space as needed

Page 4: 3.0 : Resource Management Part 1 : Memory Management

Features of Static and Dynamic Memory Allocation

Kind of Allocation Key features

Static Allocation

Allocation before start of execution of program

Size should be known before start of execution , else over allocation and wastage of memory will result

No allocation during program execution

Dynamic Allocation Allocation during execution of program

Allocation exactly equal requirement, no wastage of memory

Allocation overhead during program execution

Page 5: 3.0 : Resource Management Part 1 : Memory Management

Types of Memory Allocation Scheme

a. Single – User Configuration

b. Fixed- Partition

c. Dynamic Partition

d. Paging/ Paged Memory Allocation

e. Segmentation

Page 6: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Single – User Configuration

• Is early memory management schema – seldom use by today OS.

• This is fundamentals concept that helped memory management evolve

• Single – User Configuration work like this ;– Each program to be processed was loaded entirely and

allocated as must contiguous space in memory as it needed.

– If the program too large and didn’t fit the available memory space , it couldn’t be executed

– It demonstrates limiting factor of all computer.

Page 7: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Single – User Configuration

• Each user given access all available main memory for each job and job processed sequentially, one after the other

• For allocate memory OS use this algorithm;

Page 8: 3.0 : Resource Management Part 1 : Memory Management

Algorithm to load a job in a Single – User Configuration

1. Store first memory location of program into base register (for memory protection)

2. Set program counter (it keeps track of memory space used by the program) equal to address of first memory location

3. Read first instruction of program

4. Increment program counter by number of bytes instruction

5. Has last instruction been reached?

1. If yes, then stop loading

2. If no, then continue with step 6

6. Is program counter greater than memory size?

1. If yes, stop loading

2. If no, then continue step 7

7. Load instruction in memory

8. Read next instruction of program

9. Go to step 4

Page 9: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Single – User Configuration

• Notice amount of work done by operating system using these schema is minimal.

• The code perform the function is straightforward and logic is quite simple

• Only two hardware item is needed:– a register (to store the base address )

– a accumulator (to keep track the size of program as it’s being read into memory)

• Once program is entirely loaded into memory, it remains there until execution is complete, either through normal termination or by intervention of the OS

Page 10: 3.0 : Resource Management Part 1 : Memory Management

Major problem in Single – User Configuration Scheme

• The scheme doesn’t support multiprogramming

• It can only handle one job at a time

• Commercially in the late 1940s and early 1950s

Page 11: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Fixed Partition

• First attempt to allow multiprogramming – create fixed partition scheme within the main memory (one partition of each job)

• Also known as static partition

• This is because the size of partition was designated when the system was powered on.

• Each partition could only be reconfigured when the computer system was shut down, reconfigured, restart.

• Once system in operation the partition sized remained static

Page 12: 3.0 : Resource Management Part 1 : Memory Management

Algorithm to load a job in a Fixed Partition

1. Determine job requested memory size2. If job_size > size of largest partition

Then reject the job 1. Print appropriate message to operator 2. Go to step 1 to handle next job in line

Else Continue with step 3

3. Set counter to 14. Do while counter <= number of partitions in memory

If job_size > memory _partition_size (counter)Then counter = counter +1

ElseIf memory_partition_status(counter) = freeThen load job into memory_partition(counter)

change memory_partition_status(counter) to “busy”go to step 1

Elsecounter = counter +1

End do No partition available at this time, put job in waiting queue, get next job Go to step 1

Page 13: 3.0 : Resource Management Part 1 : Memory Management

Example of Fixed Partition

• 2560K

• Operating System

• 0

• 400K

• 2160K

Job Queue

Process

P1 600KP2 1000KP3 300KP4 700KP5 500K

size

Page 14: 3.0 : Resource Management Part 1 : Memory Management

Example of Fixed Partition

Page 15: 3.0 : Resource Management Part 1 : Memory Management

Advantages and Disadvantages of Fixed Partition

Advantages DisadvantagesMore flexible scheme compare to single – user scheme because allow several program to be in memory at the same time.

Internal Fragmentation occur

Internal fragmentation is allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.

However, it still requires that the entire program be stored contiguously and in memory from the beginning to the end of it’s execution

Page 16: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Dynamic Partition

• Available memory is still kept in contiguous block

• But jobs are given only as much memory as they request when they are loaded for processing.

• Improvement over fixed partition because memory isn’t wasted within the partition.

• Dynamic partition scheme fully utilize memory when the first job loaded.

• Will use concept first –come first serve priority.

• External Fragmentation occur– total memory space exists to satisfy a request, but it is not contiguous

Page 17: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Paging

• Is dividing incoming job into pages of equal size • Normally OS choose a page size same as memory

block size and same size as section of the disk in which the job is stored.– Section of the disk called sector/ block– Section of the main memory are called pages frame

• The scheme work quite efficiently when the pages, sector and page frame are all the same size.

Page 18: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Paging

• Before 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 program’s pages into pages frames

• When 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.

Page 19: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Paging

• The 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

Page 20: 3.0 : Resource Management Part 1 : Memory Management

Example 1 Memory Allocation Scheme: Paging

Page 21: 3.0 : Resource Management Part 1 : Memory Management

Example 2 Memory Allocation Scheme: Paging

Page 22: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme: Paging

Advantages DisadvantagesIs storing program in noncontiguous location is that main memory. Main memory is used more efficiently because an empty page frame can be used by any page of any job

Because job pages / program can be located anywhere in main memory, Memory Manager needs mechanism to keep track of them(job pages).

Eliminate compaction scheme. Which is used for reloadable partition. This is because of no external fragmentation between pages frames

External Fragmentation a situation happened in dynamic allocation scheme. Creates unusable fragment of free memory between blocks of busy, or allocated, memory.

Enlarging the size and complexity of the operating system software. Which increase overhead

Internal fragmentation is still a problem, although only in the last page of each job

Page 23: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

• Concept : based on the common practice by programmers of structuring their program in modules

• Segmentation 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 program’s structural modules.

Page 24: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

• A program is a collection of segments. A segment is a logical unit such as:– Main program ,subroutine– Procedure– Function– Method– Object– Local variable, global variable,– Stack, array ,symbol table

Page 25: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

• Each segment is numbered and a Segment Map Table(SMT) is generated for each job.

• SMT contains the segment numbers, their lengths, access right, status and when each is loaded into memory and it’s location

• Memory Manager need to keep track of the segments in memory.

Page 26: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

• Each segment is numbered and a Segment Map Table(SMT) is generated for each job.

• SMT contains the segment numbers, their lengths, access right, status and when each is loaded into memory and it’s location

• Memory Manager need to keep track of the segments in memory.

Page 27: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

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

User’s View of a Program

Page 28: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

1

4

2

3

user space physical memory space

1

3

2

4

Page 29: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

• Before execute the program/job Memory Manager prepare it by :– The job table list every job in process (one for whole system)– The Segment Map Table lists details about each segment (one for

each job)– The Memory Map Table monitor the allocation of main memory

(one for the whole system)

• The program’s instructions within each segment are ordered sequentially .

• The segment don’t need to be stored contiguously in memory• The content of the segments themselves are contiguous in

this scheme.

Page 30: 3.0 : Resource Management Part 1 : Memory Management

Example Memory Allocation Scheme : Segmentation

• To access specific location within a segment we can perform an operation similar to the one used paging scheme.

• Differences is segment instead of pages.• The addressing scheme requires the segment

number and the displacement within segment• Because the segment are of different sizes, the

displacement must be verified to ensure it isn’t outside the segment’s range.

Page 31: 3.0 : Resource Management Part 1 : Memory Management

Memory Allocation Scheme : Segmentation

SMT – map two dimensional physical address; each table has limit : specifies the length(size) of the segment base : contain the starting physical address where the segments reside in memory (memory address)

Page 32: 3.0 : Resource Management Part 1 : Memory Management

Comparison of memory allocation schemes

Scheme Problem Solved Problem Created Changes in Software

Single-user contiguous

-Job size limited to physical memory size-CPU often idle

None

Fixed Partition Idle CPU time -Internal fragmentation occur-Job size limited to partition size

-Add Processor Scheduler-Add protection handler

Dynamic Partitions

Internal fragmentation External Fragmentation None

Paging Need for compaction scheme

-Memory needed for tables-Job size limited to physical memory size-Internal fragmentation returns

Need algorithm to handle Page Map Tables

Segmentation -Internal fragmentation-Sharing of segments

Difficulty managing variable-length segments in secondary storage- External fragmentation

Two-dimensional addressing scheme

Page 33: 3.0 : Resource Management Part 1 : Memory Management

Virtual Memory

• Virtual memory it is a illusion of a memory which is different from a real memory (RAM) existing in a computer system.

• This memory maybe much larger than the real memory.

• The basis of VM implementation is noncontiguous memory allocation

Page 34: 3.0 : Resource Management Part 1 : Memory Management

Cont..

• Noncontiguous allocation permit parts of a program to be loaded into two or more non-adjacent areas of memory execution

• This 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

Page 35: 3.0 : Resource Management Part 1 : Memory Management

Cont..

• The 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

Page 36: 3.0 : Resource Management Part 1 : Memory Management

Dynamic Address Translation

• Dynamic address translation (DAT) is the process of translating a virtual address during a storage reference into the corresponding real address.