0% found this document useful (0 votes)
34 views

Unit 3

Operating system concepts

Uploaded by

krishkiran2408
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Unit 3

Operating system concepts

Uploaded by

krishkiran2408
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

UNIT-3

Main Memory and


Virtual Memory
G.Krishna Kumari
01 02
Memory management is
the functionality of an Memory management
operating system which keeps track of each

Memory
handles or manages and every memory
primary memory and location, regardless of
moves processes back either it is allocated to
and forth between main

management
some process or it is
memory and disk free.
during execution.

03 04
It checks how much
It tracks whenever
memory is to be
some memory gets
allocated to processes.
freed or unallocated
It decides which
and correspondingly it
process will get
updates the status.
memory at what time.
Static Loading
• In static loading, Initially, the complete program is loaded into the
main memory before execution.
• In the case of static loading, the entire program is compiled and
linked, leaving no program or external module dependencies at
compile time.
• Static Loading is very useful when the program isn’t too big or
complicated, and when you plan to use the program multiple times.
• Example – Static loading is only done in the case of structured
programming languages ​like C.
Dynamic loading
• So the Dynamic loading, the compiler, the program, and for any
module that needs to be included dynamically, that provided only as a
reference to them, and the rest of the work will be done at runtime.
And the complete program and all process data must be in physical
memory for the process to run.

• Example – Dynamic loading occurs in Oops languages ​such as C++ and


Java.
Static and Dynamic linking
• When static linking is used, the linker combines all other modules
needed by a program into a single executable program to avoid any
runtime dependency.

• When dynamic linking is used, it is not required to link the actual


module or library with the program, rather a reference to the dynamic
module is provided at the time of compilation and linking. Dynamic
Link Libraries (DLL) in Windows and Shared Objects in Unix are good
examples of dynamic libraries.
Memory management techniques
• Swapping
• Contiguous allocations
• Paging
• Segmentation
Swapping
Swapping is a mechanism in which a process can be
swapped temporarily out of main memory (or move) to
secondary storage (disk) 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.

Though performance is usually affected by


swapping process but it helps in running multiple
and big processes in parallel and that's the reason
Swapping is also known as a technique for memory
compaction.
Let us assume that the user process is of size 2048KB and on a standard
hard disk where swapping will take place has a data transfer rate around
1 MB per second. The actual transfer of the 1000K process to or from
memory will take

2048KB / 1024KB per second


= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds
plus other overhead where the process competes to regain main memory.
Contiguous memory allocation
• Contiguous memory allocation is a memory allocation strategy.
• As the name implies, we utilize this technique to assign contiguous blocks of
memory to each task.
• Thus, whenever a process asks to access the main memory, we allocate a
continuous segment from the empty region to the process based on its size.
• In this technique, memory is allotted in a continuous way to the processes.
• Contiguous Memory Management has two types:

• Fixed(or Static) Partition


• Variable(or Dynamic) Partitioning
Fixed and Dynamic partitioning
Fragmentation
• Fragmentation refers to an unwanted problem that occurs in the OS in
which a process is unloaded and loaded from memory, and the free
memory space gets fragmented. The processes can not be assigned to
the memory blocks because of their small size. Thus the memory
blocks always stay unused.
Algorithms for partition allocation
There are different Placement Algorithm:

A. First Fit

B. Best Fit

C. Worst Fit
1. First Fit:
• In the first fit, the partition is
allocated which is the first
sufficient block from the top of
Main Memory. It scans memory
from the beginning and chooses
the first available block that is
large enough. Thus it allocates
the first hole that is large
enough.
2. Best Fit
• 2. Best Fit Allocate the process
to the partition which is the first
smallest sufficient partition
among the free available
partition. It searches the entire
list of holes to find the smallest
hole whose size is greater than
or equal to the size of the
process.
3. Worst Fit
• 3. Worst Fit Allocate the process
to the partition which is the
largest sufficient among the
freely available partitions
available in the main memory. It
is opposite to the best-fit
algorithm. It searches the entire
list of holes to find the largest
hole and allocate it to process.
Paging
• Paging is a method used by
operating systems to manage
memory efficiently.
• It breaks physical memory into
fixed-size blocks called “frames”
and logical memory into blocks
of the same size called “pages.”
• When a program runs, its pages
are loaded into any available
frames in the physical memory.
Paging protection
• The paging process should be protected by using the concept of
insertion of an additional bit called Valid/Invalid bit.
• This bit is used to indicate whether a page is currently in memory or
not.
• If the bit is set to valid, the page is in memory, and if it is set to
invalid, the page is not in memory.
Advantage and disadvantage
• Paging in operating systems offers streamlined memory management
but presents challenges like internal fragmentation and the overhead
of managing page tables.
Segmentation
• The segmentation technology is used in operating systems and the
process is divided into many pieces called segments and these
segments are of variable size.
• In this, segmentation uses a variable partitioning method: one
segment is equal to one complete memory block.
• The access and details of each segment, they are stored in a
segment table consisting of two fields.
There are two types of information
stored in segment table:
• Limit
• Base
Limit:The limit is the length or size of the segment
Base:The base is the base address of the segment
Types of segmentation
• Virtual Memory Segmentation: Each process is divided into a number
of segments, but the segmentation is not done all at once. This
segmentation may or may not take place at the run time of the
program.
• Simple Segmentation: Each process is divided into a number of
segments, all of which are loaded into memory at run time, though
not necessarily contiguously.
Advantages and Disadvantages
• Internal fragmentation is • External fragmentation may
avoided occur
• Less overhead • Expensive
• Segment table size is less than • Tough to allocate memory in
the page table size contiguous manner to variable
• Relocation of segment is easier size partition
Segmentation with paging
• A memory management technique known as Segmentation with
Paging in OS combines the benefits of both segmentation and paging.
• The main memory is split into variable-size segments, which are
subsequently partitioned into segmentation with paging in os"smaller
fixed-size disk pages
Advantages of segmented paging
• Reduces memory usage
• Page table size is limited by segment size
• External fragmentation is not there
• Simplifies memory allocation
Disadvantages of segmented paging
• Internal fragmentation is there
• Complexity level is higher
• Page tables should be stored contiguously in memory

You might also like