Вы находитесь на странице: 1из 10

Unit 4 - Memory Management

What is Memory Management?


Memory contains of a large array of words or bytes, each with its own address.
Memory management is the functionality of an operating system which handles or manages
primary memory and moves processes back and forth between main memory and disk during
execution.

Explain about Logical Address Space and Physical Address Space


 Logical address – generated by the CPU; also referred as virtual address (referred to by
application programs).
 Physical address – address seen by the memory unit.
 The set of all logical addresses generated by a program is a logical address space.
 The set of all physical addresses corresponding to these logical addresses are a physical
address space.

Write about the Memory-Management Unit (MMU)


 MMU is a Hardware device and it maps the virtual address to Physical address.
 In MMU, the value in the Relocation Register is added to every address generated by a
user process at the time it is sent to memory.
 The user program deals with logical addresses; it never sees the real physical addresses
Please see the below Diagram of Memory-Management Unit (MMU)

1
Explain about the Memory allocation techniques?
Single contiguous allocation: Simplest allocation method used by MS-DOS. All memory (except
some reserved for OS) is available to a process.

Partitioned allocation: Memory is divided in different blocks. It is of three types :

i. First Fit:
The first hole that is big enough is allocated to the process.

ii. Best Fit:


The smallest hole that is big enough is allocated to the process.

iii. Worst Fit:


The largest hole that is big enough is allocated to the process.

Dynamic Loading
 The advantage of dynamic loading is that an unused routine is never loaded. With
dynamic loading, a routine is not loaded until it is called.
 Dynamic loading does not require special support from the operating system.
Dynamic Loading
 The advantage of dynamic loading is that an unused routine is never loaded. With
dynamic loading, a routine is not loaded until it is called.
 Dynamic loading does not require special support from the operating system.

Explain about the Swapping


 A process needs to be in memory for execution. But sometimes there is not enough
main memory to hold all the currently active processes.
 Swapping is a mechanism used to swap the process temporarily from main memory
to secondary storage (disk) device and make that memory available to other processes.
 At some later time, the system swaps back the process from the secondary storage to
main memory.

2
Backing Store : It is a secondary memory disk (hard disk ) used to store the data.

Roll out and Roll in : In Roll out, the lower priority process is swapped out into backing Store.
In Roll in, the high priority process is swapped in to main memory for execution.

Major part of swap time is transfer time. Total transfer time is proportional to the amount of
memory swapped.

Explain about the Paging ?


Paging is a memory management mechanism that allows the physical address space of a process
to be non-contagious.
In Paging, Physical memory is broken into fixed-sized blocks called Frames.
Also, logical memory is also broken into blocks of the same size called Pages.
When a process is to be executed, its pages are loaded into any available memory frames from
the backing store.
Here physical memory is divided into blocks of equal size called Pages. The pages belonging to a
certain process are loaded into available memory frames.
Virtual address is also known as Logical address and is generated by the CPU. While Physical
address is the address that actually exists on memory.
Page Table
A Page Table is the data structure used to mapping between the virtual address and physical
addresses.

3
Explain about the Segmentation in detail?
Segmentation is another memory management scheme that supports the user-view of
memory.
A program is a collection of segments.
– A segment is a logical unit such as:
main program
procedure
function
method
object
local variables, global variables
common block
stack
symbol table
arrays
 Each segment has a name and a length. The addresses specify both the segment name
and the offset within the segment.
 The user therefore specifies each address by two quantities: a segment name and an
offset.

4
 The details about each segment are stored in a table called as segment table. Segment
table is stored in one (or many) of the segments.
The use of a segment table is illustrated in Figure. A logical address consists of two parts: a
segment number s and an offset value d. The segment number is used as an index into the
segment table.

The offset d of the logical address must be between 0 and the segment limit.

 Segment table contains mainly two information about segment:


 Base: It is the base address of the segment
 Limit: It is the length of the segment.

Figure : Segmentation Hardware


The offset d of the logical address must be between 0 and the segment limit. If it is not, we trap
to the operating system.

Explain about the Segmentation with Paging?

 The Intel 386 uses segmentation with paging for memory management with a two-level
paging scheme.

 The logical-address space of a process is divided into two partitions. The first partition
consists of up to 8 KB segments that are private to that process.

 The second partition consists of up to 8 KB segments that are shared among all the
processes. Information about the first partition is kept in the Local Descriptor Table

5
(LDT), information about the second partition is kept in the Global Descriptor Table
(GDT).

 To improve the efficiency of physical-memory use, Intel 386 page tables can be swapped
to disk.

Explain the Difference between paging and segmentation?

Explain about the Demand Paging in Memory Management?

 A demand paging technique is similar to the paging system with swapping feature.

 The process of loading the page into memory on demand (whenever page fault occurs)
is known as demand paging.

6
The process includes the following steps :

1. If CPU try to refer a page that is currently not available in the main memory, it generates
an interrupt indicating memory access fault ((Page Fault).
2. The OS puts the interrupted process in a blocking state . For the execution to proceed
the OS must bring the required page into the memory.
3. The OS will search for the required page in the logical address space.
4. The required page will be brought from logical address space to physical address space.
The page replacement algorithms are used for the decision making of replacing the page
in physical address space.
5. The page table will updated accordingly (Please refer below Page Table).

7
6. The signal will be sent to the CPU to continue the program execution and it will place
the process back into ready state.

Page Fault Service Time :


The time taken to service the page fault is called as page fault service time. The page fault
service time includes the time taken to perform all the above six steps.

Advantages of Demand Paging:


More processes may be maintained in the main memory:
A process larger than the main memory can be executed because of demand paging.

Explain about the Page Replace Algorithms?

The job of the Page Replacement algorithm is to decide which page gets victimized/removed to
make room for a new page.

1. FIFO Page Replacement Algorithm


2. LRU Page Replacement Algorithm
3. LFU Page Replacement Algorithm
4. Optimal Page Replacement Algorithm

1.FIFO algorithm (First In First Out)


The simplest page-replacement algorithm is a FIFO algorithm.
A FIFO replacement algorithm Replaces pages based on their order of arrival: oldest page is
replaced.

8
2.Least Recently Used Algorithm (LRU)
LRU chooses that page that has not been used for the longest period of time.

3.Least Frequently Used Algorithm (LFU)


LFU chooses that page that has the lowest reference frequency.

4.Optimal Page Replacement Algorithm


It is a Lowest Page Fault algorithm. It looks for the pages in future. Replace the page that will
not be use for the longest period of time. It is Hard to Implement.

Explain about the Fragmentation?

As processes are loaded and removed from memory, the free memory space is broken into
little pieces. After sometimes these broken memory blocks cannot allocate to the process due
to its small size. These memory blocks are remains unused due to its small size. This problem is
known as Fragmentation.

Two types in Fragmentation

1. Internal fragmentation
2. External fragmentation

Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left unused, as it
cannot be used by another process. The internal fragmentation can be reduced by effectively
assigning the smallest partition but large enough for the process.

External fragmentation
Total memory space is enough to satisfy a memory allocation request or to reside a process in
it, but it is not contiguous, so it cannot be used. External fragmentation can be reduced by
compaction or gather the free memory together in one large block.

9
Explain about the Thrashing?

 A process that is spending more time paging than executing is said to be thrashing.

 In other words it means, that the process doesn't have enough frames to hold all the
pages for its execution, so it is swapping pages in and out very frequently to keep
executing,

 As the memory fills up, process starts to spend a lot of time for the required pages to be
swapped in, again leading to low CPU utilization because most of the proccesses are
waiting for pages.

 Hence the scheduler loads more processes to increase CPU utilization, as this continues
at a point of time the complete system comes to a stop.

 To prevent thrashing we must provide processes with as many frames as they really
need "right now".

10

Вам также может понравиться