0% found this document useful (0 votes)
25 views58 pages

OS U-IV Memory Management

ppt

Uploaded by

Rahul Moin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views58 pages

OS U-IV Memory Management

ppt

Uploaded by

Rahul Moin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Artificial Intelligence And Data

Science
Operating System
By
Prof. A.A.Salunke
M.Tech. Computer

Course Code [ 217521]


SEM I
Credit - 03
UNIT - IV
Memory Management
06 Hrs.
Content :
1. Memory Management: Memory Management Requirements
2. Memory Partitioning: Fixed Partitioning, Dynamic Partitioning.
3. Buddy System.
4. Relocation.
5. Paging.
6. Segmentation.
7. Virtual Memory: Hardware and Control Structures.
8. Operating System Software .
1. Memory Management: Memory Management Requirements

What is Memory Management


In a uni-programming system, main memory is divided into two parts:
one part for the operating system (resident monitor, kernel) and
one part for the user program currently being executed.

In a multiprogramming system, the “user” part of memory must be further


subdivided to accommodate multiple processes.
The task of subdivision is carried out dynamically by the operating system and is
known as memory management.
Why Memory Management is required:

Allocate and de-allocate memory before and after process execution.

To keep track of used memory space by processes.

To minimize fragmentation issues.

To proper utilization of main memory.

To maintain data integrity while executing of process.


Memory Partitioning: Fixed Partitioning , Dynamic Partitioning.

1. Fixed Partitioning:
Main memory (RAM) is divided into a no. of static partitions at system generation
time.
A process may be loaded into a partition of equal or greater size.
Memory Manager will allocate a region to a process that best fits it
Unused memory within an allocated partition called internal fragmentation

Advantages:
1. Simple to implement
2. Little OS overhead
Fixed Partitioning:

1. Simplest technique which can be used to load more than one processes into
the main memory is Fixed partitioning or Contiguous memory allocation.

1. In this technique, the main memory is divided into partitions of equal or


different sizes.
2.
3. The operating system always resides in the first partition while the other
partitions can be used to store user processes. T

1. he memory is assigned to the processes in contiguous way.


Fixed Partitioning Problem : Internal Fragmentation
Internal Fragmentation In Fixed partition
If the size of the process is lesser then the total size of the partition then some size
of the partition get wasted and remain unused.
This is wastage of the memory and called internal fragmentation.

Internal Fragmentation
Disadvantages:
1. Inefficient use of Memory due to internal fragmentation.

2. Main memory(RAM) utilization is extremely inefficient.

3. Any program, no matter how small, occupies an entire partition. This

phenomenon, in which there is wasted space internal to a partition due to the

fact that the block of data loaded is smaller than the partition, is referred to

as internal fragmentation.
Dynamic Partitioning
1. Dynamic partitioning tries to overcome the problems caused by fixed
partitioning.
2. In this technique, the partition size is not declared initially.
3. It is declared at the time of process loading.
4. The first partition is reserved for the operating system.
5. The remaining space is divided into parts.
6. The size of each partition will be equal to the size of the process.
7. The partition size varies according to the need of the process so that the
internal fragmentation can be avoided.
8. The partitions are of variable length and number. When a process is brought
into main memory, it is allocated exactly as much memory as it requires and no
more.
Dynamic Partitioning Problem : External fragmentation

It occurs when enough total main memory space exists to satisfy

a request, but it is not contiguous, storage is fragmented into a

large number of small holes. SHOWN IN DIAGRAM BELOW

The rule says that the process must be contiguously present in

the main memory to get executed


External Fragmentation
External Fragmentation

The rule says that the process must be contiguously present in the main memory to get executed
Buddy System
The buddy system is a memory allocation and management
algorithm that manages memory in power of two increments

Assume the memory size is 2U, suppose a size of S is required

▪ If 2U-1<S<=2U: Allocate the whole block

▪ Else: Recursively divide the block equally and test the condition at
each time, when it satisfies, allocate the block and get out the
loop

▪ System also keep the record of all the unallocated blocks each
and can merge these different size blocks to make one big chunk
Buddy System
Example
Q. Consider a system having buddy system with physical address space 128 KB.
Calculate the size of partition for 18 KB process.
Solution – ▪ S=18 KB required
▪ If 2U-1< S <=2U: Allocate the whole block
▪ Else: Recursively divide the block equally and test the condition at each time, when it
satisfies, allocate t he block and get out the loop

memory size is 27

memory size is 26

memory size is 25

So, size of partition for 18 KB process = 32 KB. It divides by 2, till possible to get minimum block to fit 18
KB.
Buddy System
Advantage –
1. Easy to implement a buddy system
2. Allocates block of correct size
3. It is easy to merge adjacent holes
4. Fast to allocate memory and de-allocating memory

Disadvantage –
1. It requires all allocation unit to be powers of two
2. It leads to internal fragmentation
Relocation
1. Relocation Means Moving Program from One Memory Area to
Another Memory Area

1. It’s processes of load the program into main memory by


relocating program’s virtual address to physical address space
for execution.

1. Relocation Done by
1) Static Relocation
2) Dynamic Relocation
Two Program Loaded into Physical Memory (RAM) same time
Physical Address

Logical Address Logical Address


What’s mean by Base Register and Limit Register ?
Dynamic Relocation
Logical Address(Virtual Address) Added with Hardware added Relocation Register
(Base address) to get the Physical Address
Paging -> IS memory Management scheme
Paging is a memory management scheme that eliminates the need for
contiguous allocation of physical memory

This scheme permits the physical address space of a process to be non –


contiguous

•Logical Address or Virtual Address (represented in bits): An address generated


by the CPU

•Logical Address Space or Virtual Address Space( represented in words or


bytes): The set of all logical addresses generated by a program

•Physical Address (represented in bits): An address actually available on


memory unit

•Physical Address Space (represented in words or bytes): The set of all physical
addresses corresponding to the logical addresses

A byte is eight bits, a word is 2 bytes (16 bits)


The mapping from virtual to physical address is done by the
memory management unit (MMU) which is a hardware device and
this mapping is known as paging technique.

1. The Physical Address Space is conceptually divided into a number

of fixed-size blocks, called frames.

2. The Logical address Space is also spitted into fixed-size blocks,

called pages.

3. Page Size = Frame Size


Let us consider an example:

1. Physical Address = 12 bits, then Physical Address Space = 4 K words

2. Logical Address = 13 bits, then Logical Address Space = 8 K words

3. Page size = frame size = 1 K words (assumption)


Address generated by CPU is divided into

▪ Page number(p): Number of bits required to represent the pages in Logical Address Space
or Page number

▪ Page offset(d): Number of bits required to represent particular word in a page or page
size of Logical Address Space or word number of a page or page offset.

Physical Address is divided into

▪ Frame number(f): Number of bits required to represent the frame of Physical Address
Space or Frame number.

▪ Frame offset(d): Number of bits required to represent particular word in a frame or


frame size of Physical Address Space or word number of a frame or frame offset.
TLB (translation Look-aside buffer)-> fast look up hardware cache
1. The hardware implementation of page table can be done by using dedicated registers.

But the usage of register for the page table is satisfactory only if page table is small.

2. If page table contain large number of entries then we can use TLB (translation Look-

aside buffer), a special, small, fast look up hardware cache.

▪ The TLB is associative, high speed memory.


▪ Each entry in TLB consists of two parts: a tag and a value.
▪ When this memory is used, then an item is compared with all
tags simultaneously.
If the item is found, then corresponding value is returned.
TLB : is used to reduce the time taken to access the memory locations in the page-table
method
Why Segmentation is required?
1. Paging is more close to the Operating system rather than the User.

2. It divides all the processes into the form of pages regardless of the fact that a process can

have some relative parts of functions which need to be loaded in the same page.

3. IN PAGING Operating system doesn't care about the User's view of the process.

4. It may divide the same function into different pages and those pages may or may not be

loaded at the same time into the memory. It decreases the efficiency of the system.

5. It is better to have segmentation which divides the process into the segments.

6. Each segment contains the same type of functions such as the main function can be

included in one segment and the library functions can be included in the other

segment.
Segmentation.
Segmentation is a Memory Management Technique in which the
memory is divided into the variable size parts.

Segmentation It support use’s view of memory.

A process is divided into Segments

Each Process (Program) is divided into a number of segments, all of


which are loaded into main memory (RAM) at run time, though not
necessarily contiguously. (Process may store in non-contiguous
memory location).
A Program is basically a collection of segments. And a segment is a logical unit such as:
A logical address space is a collection of segments

▪ main program
▪ procedure
▪ Function
▪ method
▪ object
▪ local variable
▪ global variables.
▪ symbol table
▪ common block
▪ stack
▪ arrays
With the help of segment map tables and hardware assistance (MMU), the
operating system can easily translate a logical address into physical address on
execution of a program.
Segment Table
It maps two-dimensional Logical address into one-dimensional Physical address.
It’s each table entry has : (Base Address, Limit)

1. Base Address: It contains the starting physical address where the segments
reside in memory.
2. Limit: It specifies the length of the segment.
Logical Address Generated by CPU

Address generated by the CPU is divided into:


1. Segment number (s): Number of bits required to represent the segment.
2. Segment offset (d): Number of bits required to represent the size of the segment.
S: Segment Number
d : Size of the Segment.

Limit: It specifies the length of the segment


Base Address: Starting Physical Address for
Segment

Translation of Logical Address to one dimensional Physical Address.


Translation of Logical address into physical address by segment table
1. The operating system also generates a segment map table for each program.

2. With the help of segment map tables and hardware assistance(MMU), the operating

system can easily translate a logical address into physical address on execution of a

program.

3. The Segment number (S) is mapped to the segment table.

4. The limit of the respective segment is compared with the offset (d) .

5. If the offset is less than the limit (d< limit) then the address is valid otherwise it throws

an error as the address is invalid.

6. In the case of valid addresses, the Base address of the segment is added to the offset to

get the physical address of the actual word in the Main memory(RAM).
Advantages of Segmentation
1.No internal fragmentation

2.Average Segment Size is larger than the actual page size.

3.Less overhead

4.It is easier to relocate segments than entire address space.

5.The segment table is of lesser size as compared to the page table in paging.

Disadvantages

1.It can have External fragmentation.

2.it is difficult to allocate contiguous memory to variable sized partition.

3.Costly memory management algorithms.


Virtual Memory: Hardware and Control Structures.

A computer can address more memory than the amount physically


installed on the system. This extra memory is actually called virtual
memory and it is a section of a hard disk that's set up to emulate
the computer's RAM.

The main visible advantage virtual memory is that programs can be


larger than physical memory.
1. Virtual memory serves two purposes.
2. First, it allows us to extend the use of physical memory by using
disk.
3. Second, it allows us to have memory protection, because each
virtual address is translated to a physical address.
Virtual Memory: Hardware and Control Structures.
1. Memory references are dynamically translated into physical
addresses at run time.
2. A process may be broken up into pieces that do not need to
located contiguously in main memory
3. Hardware must support paging and segmentation
4. Operating system must be able to manage the movement of pages
and/or segments between secondary memory and main memory
Virtual Memory: Hardware and Control Structures.
Execution of a Program
Operating system brings into main memory a few pieces of the program
● Resident set - portion of process that is in main memory
● An interrupt is generated when an address is needed that is not in main memory (page
fault)
● Operating system places the process in a blocking state
– the process is waiting its page from disk
– this is equivalent to a blocking I/O request
Piece of process that contains the logical address is brought into main memory
More processes may be maintained in main memory
A process may be larger than all of main memory
Thrashing
Swapping out a piece of a process just before that piece is needed
The processor(CPU) spends most of its time swapping pieces rather than executing user
instructions
Principle of Locality
Program and data references within a process tend to cluster
● Only a few pieces of a process will be needed over a short period of time
● Possible to make intelligent guesses about which pieces will be needed in the future
● This suggests that virtual memory may work efficiently
Support Needed for Virtual Memory
Hardware must support paging and segmentation
● Operating system must be able to manage the movement of pages and/or
segments between secondary memory and main memory
Operating System Software
1. An Operating System (OS) is a software that acts as an interface between
computer hardware components and the user

1. Every computer system must have at least one operating system to run other
programs. Applications like Browsers, MS Office, Notepad Games, etc., need
some environment to run and perform its tasks.

1. An operating system (OS) is the program that, after being initially loaded into the
computer by a boot program, manages all of the other application programs in a
computer.

1. The application programs make use of the operating system by making requests
for services through a defined application program interface (API).

1. It is not possible for the user to use any computer or mobile device without
having an operating system.
Operating System Software
Operating System Software
Following are some of important functions of an operating System.
1. Memory Management
2. Processor Management
3. Device Management
4. File Management
5. Security
6. Control over system performance
7. Job accounting
8. Error detecting aids
9. Coordination between other software and users
Operating System Software
In an operating system software performs each of the function:

1.Process management: Process management helps OS to create and delete


processes. It also provides mechanisms for synchronization and communication
among processes.

1.Memory management: Memory management module performs the task of


allocation and de-allocation of memory space to programs in need of this resources.

1.File management: It manages all the file-related activities such as organization


storage, retrieval, naming, sharing, and protection of files.

1.Device Management: Device management keeps tracks of all devices. This


module also responsible for this task is known as the I/O controller. It also performs
the task of allocation and de-allocation of the devices.

1. I/O System Management: One of the main objects of any OS is to hide the peculiarities of
that hardware devices from the user.
Operating System Software
6. Secondary-Storage Management: Systems have several levels of storage which includes primary
storage, secondary storage, and cache storage. Instructions and data must be stored in primary storage or
cache so that a running program can reference it.

7. Security: Security module protects the data and information of a computer system against malware
threat and authorized access.

8. Command interpretation: This module is interpreting commands given by the and acting system
resources to process that commands.

9. Networking: A distributed system is a group of processors which do not share memory, hardware
devices, or a clock. The processors communicate with one another through the network.

10. Job accounting: Keeping track of time & resource used by various job and users.

11. Communication management: Coordination and assignment of compilers, interpreters, and another
software resource of the various users of the computer systems.
Operating System Software
Common desktop operating systems include the following:

•Windows is Microsoft's flagship operating system, the de facto standard for home and business
computers. Introduced in 1985, the GUI-based OS has been released in many versions since then.
The user-friendly Windows 95 was largely responsible for the rapid development of personal
computing.

•Mac OS is the operating system for Apple's Macintosh line of PCs and workstations.

•Unix is a multiuser operating system designed for flexibility and adaptability. Originally developed
in the 1970s, Unix was one of the first operating systems to be written in the C language.

•Linux is a Unix-like operating system that was designed to provide PC users a free or low-cost
alternative. Linux has a reputation as an efficient and fast-performing system.
https://www.studytonight.com/operating-system/memory-management-in-os

https://www.cs.jhu.edu/~yairamir/cs418/os5/sld004.htm

You might also like