You are on page 1of 15

UNIT - III

Memory management:

The memory management modules of an os are concerted with the


management of primary memory. The task of substation is carried out dynamically by the os is
known as meamo0ry management. Memory consist 0f a char array or words or bites each with
its own address.

Functions:

1.keeping track of the status of each memory location. Whether the memory is allocated are
free.

2.determining allocation policy for memory.

3.meamory allocation technique, Memory allocation information must be allocated

4.Deallcation technique and policy. A process may release the allocated memory.

REQUIREMENTS:

memory management requires 5 Parameters

 Relocation
 protection
 sharing
 logical organization
 physical organization

Address binding:

the collection process on the disk that is waiting to be brought in to memory for executing for as
the input queue. It is used to for selecting one of the process for execution and loads into
memory. As a process executed its access data from memory and process will terminated. The
memory space becomes free. Most of the os allows the user process to reside in any part of
physical memory. User program consist various library files while executing each binding is
mapping from are address space to another.binding of instruction of data to memory address
can be done at any steps along the way

 Compile time
 Load time
 exicution time
compile time:

Process will reside in memory at compile time. I generate absolute code at compile
time binding. after compiling of the process with the memory location is changed, Then is
necessary that the code must be compiled.

Load time:

compiler must be generate replaceable code after compile time In this situation, Final
binding is delayed until load time. If the starting address changed ,it needs only reloaded the
user code to incorporate this changed value.

Execution time:

Process may be moved from one memory segment to another memory segment in
execution ,Then binding must be delayed until run time. Special hardware must be available for
this scheme to work. Most general propose os use execution time binding method.

Logical versus physical address space:

1. Logical address is generated by CPU.register.

2. Compile time and local time address binding method generate same logical address and
physical address.

3. Execution time address binding scheme results is different logical and physical address.

4. Generally logical address is referred by a virtual address.

5. Logical address space is set of all logical address generate by a program is a logical address
space.

6.Physical address space is a set of all physical address corresponding to these logical
address.

7. Relocation register also called by base register.

8. User program never sees the real physical address.

9. Dynamic relocation implies that mapping from the virtual address space to the physical
address is performed at run time.

10. Relocation is performed by hardware and is invisible to the user.

Dynamic loading:
 Dynamic loading is used for better memory space initialization.
 User program is large as compare to the memory space.
 A routine is not loaded until it is dynamic loading.
 The main program is loaded into memory and execute.

Advantage of dynamic loading:

Unused routine is never used

This method is particularly used useful when large amount of code of need for handled in
frequently occurring cases.

Dynamic loading does not required special support from the operating system.

Dynamic linking and shared libraries:

1. Dynamic linking only the main program is initially loaded.

2. The linking of subroutine is post pended until a reference is explicitly made.

3. There are several ways to accomplish dynamic linking.

4. With dynamic linking a stub included is the image for each library routine reference.

5. The stub is small piece of code that indicates how to locate the appropriate memory library
routine or how to load the library if the routine is not already present.

6. Each program uses its version information to decide which copy of the library to use.

7. Only program that are compiled with new library version affected by the incompatible
changes incorporated in it.

8. Other program linked before the new version installed until continue using the older library.
This type of system is called shared library.

Overlays:

The idea of the overlays is to keep in memory only those instruction and data that are
need that any given time. When other instruction are need they are loaded into space that was
occupied previously by instruction that are no longer need .It allows a process to execute
despite to the system having insufficient physical memory.

Example:

Consider a two pass assembler ,during pass1 it construct a symbol table, during pass 2
generates machine language code. We may be able to partition such an assembler pass1 code,
pass2 code, the symbol table and column support routine used. By both pass1 and pass2.

Assume that the size of there components are as follows:


Pass 1 70kb

Pass 2 80kb

Symbol table 20kb

Common routine 30kb

To load everything as one’s we could require 200KB of memory. If only 150KB is


available we cannot run our process. Thus we defined two overlays

Overlay A -- Symbol table, common routine and Pass 1.

Overlay B -- symbol table, common routine and Pass 2

We add an overlay driver (10kb) and start with overlay a in memory. When we finish
pass 1, We jump to the overlay driver which reads overlay B into memory. Over writing overlay
A and then transfer control to pass 2 overlay A needs only 120Kb Where as overlay B needs
130Kb. We can now run our assembler in the 150Kb of memory.

Overlay do not require any special support for operating system. They can be
implemented completely user with simple file structure, Reading from files into memory and
executively read instruction.

Small program need not be over layer obtaining a sufficient under standing a program may
be difficult. Automatic techniques to run large program limited amount of physical memory are
certainly preferable.

Overlay of a two pass assembler

Contiguous memory allocation:


Single contiguous allocation is a simple memory management
scheme that requires no special hardware features. For allocation memory , it is divided in to
number fixed size partition. Each partition contain exactly one process. Thus degree of
multiprogramming depends on the number of partition’s. Multiple partition method is used in
multiprogramming environment.

1.If the partition is free, process is selected from the input queue and it loaded into the free
partition of a memory.

2. When the process terminates, the memory partition becomes available for another process.

This type of memory allocation is no longer in we. Batch operating system uses the
fixed-size partition scheme. The operating system keeps the record of memory allocation and
de-allocation in the form of table. Hole is one large black of few available memory. If any free
hole is found, process is allocated to the free hole of memory as is need. After allocating
number of hole for the process, a set of various size holes is scattered throughout at any given
times.

Memory management uses these algorithm for selecting free holes:

1.First fit

2.Worst fit

3.Best fit

First fit:

It begins to scan memory from the beginning and chooses from first available block that is
large enough.

Best fit:

It chooses block that is closet in the size of a request. It allocates the smallest hole that is
big enough.

Worst fit:

Allocate the longest the hole. It reaches the entire list.

First and best fit are among the most popular algorithm for dynamic
memory allocation. First fit is generally faster ,On the average ,First fit searches hole of the free
list per allocation. Best fit searches the entire free list to find the smallest free block large
enough. Worst fit reduces the rate of production of small holes. All these fragmentation these
algoritham suffer from external fragmentation.

Advantages:
1.Simple to implement

2.Does not require expertise to understand and use such system.

Disadvantages:

1.Memory is not fully utilized.

2.Poor utilization of memory.

3.User’s process being limited to the size of available main memory.

Functions of os for the single absolute partition:

When the system is booted, The os loads the base register with the address of lowest
memory location that can be accessed by a user program.

Functions of memory management hardware:

1.Each time a memory location is referenced, its address is compared to the address in the
base register.

2.Adress smaller than the address in the base register results in a memory fault trap.

Example:

Given memory partition of 100k,200k,300k,500k and 600k how would each of the first fit,
Best fit, worst fit algorithm face process of 21k,417k,112k and 426k? Which algorithm make the
most efficient use of memory.

1.First fit:

Memory partition

100k 500k 200k 300k 600k

process 212k 417k 112k 426k

No memory partition

2.Best Fit
3.Worst fit:

Memory partitions

100k 500k 200k 300k 600k

processes

No memory partitions

Best fit algorithm make most efficient use of memory

212k 417k 112k 426k

FRAGMENTATION

Memory fragmentation can be two types:

1.Internal fragmentation.

2.External fragmentation.

Memory that is to a partition, but is not being used for example, In multiple partition
scheme. Hole of 10,524 bytes. Sppose that the next process requites 10,520 bytes. If we
allocate exactly the request block, then there is left with a hole of 4 bytes.
The external fragmentation exists when the enough total memory space exists to
satisfy a request, but it is not contiguous, storage is fragmented in to a large number of small
holes.There is a hole of 200k and 500k in multiple partition allocation scheme. Next process
request for 700k of memory. Actually 700k of memory is free which satisfy the request but hole
does not contiguous. So there is an external fragmentation of memory.

External fragmentation

One technique for overcoming the external fragmentation is compaction. From time to time,
The operating system shifts the process so that they are contiguous and all the free memory is
together is one block.
Compaction

Compaction implies the need for dynamic capability. If reallocation is static


and its done of assembly and load time, Compaction can not be done. Reallocation is done at
execution time then compaction is possible. Cost is may or factor for compaction. The simplest
algorithm of compaction is, The process move towards one side of memory and holes move in
the other direction of memory. It produces one large hole of available memory. But cost of this
scheme can be more. Swapping can also be combined with compaction. The compaction
process is completed by update free list. If swapping already part of a system. The additional
code for compaction may be minimal.

Paging:

It is a memory management scheme. It reduces the external fragmentation. Memory is


divided into fixed size blocks called page frames. The virtual address space of a process is also
split into fixed size blocks of the same size, called pages.

When a process is loaded into memory, the os loads each page into an un used
page frame. The page from used need not be contiguous. Os maintains the page table for each
process. The page table shows the frame location for each page of process.
Cpu generates the logical address and it consist of two pages.

1.A page number(p)

2.Page offset(d)

A logical address is the location of a word relative to beginning of the


program, the processor translate that into a physical address.

Page table stores the number of the page from allocate for each page.
Page table contains the base address of each page in physical memory . this base address is
combined with the page offset to define the physical memory address that is sent to the memory
unit.
The size of page is typically a power of 2, varying between 512 bytes and 16mb per
page. The physical address can be generated by concatenating the offset to the frame number.

PAGING MODEL:

Logical address consist of page number and page offset. The logical space may be the
same size as the physical address space or it may be smaller.

Protection and sharing

Protection bits are used with each page frame for protection memory in paging. The
protection bits can be check to verify that no writes are being made to a read-only page. One
more bit is generally attached to each entry in the page table, A valid-invalid bit. When valid bit
is set, then the page is in the process logical address space. Thus page is legal. If invalid bit is
set, Page is not in the process logical address space and illegal page. Illegal address are
trapped by using the valid-invalid bit.
VALID OR INVALID BIT IN A PAGE TABLE

Hardware support for paging

A hardware mechanism is needed to perform mapping from each instruction effective


address to the appropriate physical memory address. There must separate register for
each page. These may be actual high speed to a special area of physical memory.

Translation look aside buffer:(TLB)

Problem with paging is that extra memory reference to access translation can
slow program down by a factor of two are three, The standard solve to this
problem is to use a special, small fast look up hardware cache called TLB.

 It is a associative, high speed memory.

 A tlb is used to store a few of translation table entries.

On each memory reference:

 First ask TLB it if knows about the page, If also the reference
proceeds fast.
 If TLB has no information for page, must go through The hit ratio is
the ratio between access that find in the associative memory and
those that do not.

PAGING WITH TLB

Disadvantages:

 If two pages use the same entry of the memory, Only one of them
can be remembered at once.

 If process is referring both pages at same times TLB, does not work
very well.

Structure of page table:

Recent computer system support a large logical address space from


the 2^32 to 2^64. In this system table becomes large. Its difficult to allocate contiguous main
memory for page table. To solve this problem, two into number of scheme is used. The page
table is divided into number of small pieces.
Inverted page table:

As address spaces have grown to 64 bits, The side of traditional page


table become a problem. Even with for level page table, The tables themselves can become to
large. Inverted page table is used to solve this problem. The inverted page table is used has
one entry of each real page of memory. The physical page table is often called as inverted page
table. This table contains one entry from Physical page from logical page number, but not very
good at mapping from virtual page number from physical page number.

Advantages:

 Paging eliminates fragmentation.

 Support higher degree from multiprogramming.

 Paging increases memory and process utilization.

 Compaction overhead require for the replaceable partition scheme is also


eliminated.

Disadvantage

 Page address mapping hardware usually increase the cost of computer.

 Memory must be used to store the various tables like page table, memory map
table, etc…

 Some memory will still be unused if number of available block its not sufficient
for the address space of the jobs to be run.

Segmentation:

It divided a program into a number of smaller blocks called segments. A


segment can be defined as a logical grouping of information, Such as a subroutine, Array or
Data area. Segmentation is a variable size. The logical address consists of two parts:

 Segment number

 Offset

Segmentation eliminates internal fragmentation but it suffer from external fragmentation. It


is usually visible and is provide as a convenience for or gaining program and data

Hardware for segmentation:

A segmentation address space can be implemented by using


address mapping hard ware. Segments table contents the limit of segment and segment base.
The segment base contains the starting physical address where the segment resides in
memory. Segment Limit specifies the length of the segment.

A logical address consist of two parts:

Segment number(s)

Offset into that segment (d)

Segment number is used as index for the segment table.

Protection and sharing:

The memory mapping hard ware will check the protection bits
association with each segment entry to prevent illegal access to memory, Such as attempts to
write into a read only segment.Segments are shared when entries in the segment table of two
different process point to the same physical location. The sharing occurs at the segment level.

Advantages:

 It eliminates fragmentation.
 It provides virtual memory
 Allows dynamic segment growth.
 Assists dynamic linking.
 It is visible.

Disadvantages:

 Maximum size of a segment is limited by the size of main memory


 Difficult to manage variable size segments on secondary storage.

You might also like