0% found this document useful (0 votes)
9 views64 pages

Unit 5

The document is a lecture note on Memory Management in Operating Systems, covering topics such as contiguous memory allocation, swapping, paging, and segmentation. It discusses various algorithms for memory allocation, advantages and disadvantages of different techniques, and concepts like virtual memory and disk scheduling. The content is structured for a Computer Science & Engineering course at VNRVJIET, providing essential insights into memory management strategies and their implementations.

Uploaded by

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

Unit 5

The document is a lecture note on Memory Management in Operating Systems, covering topics such as contiguous memory allocation, swapping, paging, and segmentation. It discusses various algorithms for memory allocation, advantages and disadvantages of different techniques, and concepts like virtual memory and disk scheduling. The content is structured for a Computer Science & Engineering course at VNRVJIET, providing essential insights into memory management strategies and their implementations.

Uploaded by

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

Vallurupalli Nageswara Rao Vignana Jyothi Institute of

Engineering &Technology

Department of Computer Science & Engineering

SUBJECT: Operating Systems


Subject Code: 18PC1IT05

Topic Name: Memory Management


III year, sec: C

CH Rama Satya
Assistant Professor
Email: [email protected]

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 1


Memory Management
 Memory Management
It is the process of controlling and co – ordinating computer memory.

 Use of Memory Management

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 2


Memory Management
 Contiguous memory Allocation
two techniques
1. Static partitioning / fixed size
2. Dynamic partitioning/ variable size

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 3


Contiguous memory allocation
 Dynamic Partitioning
- Dynamic partitioning is a variable size partitioning scheme.
- It performs the allocation dynamically.
- When a process arrives, a partition of size equal to the size of process is created.
Partition allocation algorithms same as static partition
First fit
Best fit
Worst fit
- When the process leaves the main memory a hole will be created.
- These holes are allocated to the process which will come later
So, these partition algorithm decide which hole should be allocated to the arrived process

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 4


Contiguous memory allocation
 Worst fit algorithm works best (space left – large size)
 Best fit algorithm works worst (space left – small size)

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 5


Contiguous memory allocation
 Advantages
- It does not suffer from internal fragmentation
- There is no limitation on the size of the process

 Disadvantages
- It suffers from external fragmentation
- Allocation and deallocation of memory is complex

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 6


Logical to physical
 Translating logical to physical address
it uses two registers
1. Relocation register - stores the base address or starting address of the process in the main
memory.
2. Limit register - Limit Register stores the size or length of the process.

Base = 30004
Limit = 12090
Range= 42094

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 7


swapping
 Swapping
- it is a method in which the
process should be swapped
temporarily from the main memory
to the backing store. It will be later
brought back into the memory for
continue execution.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 8


Swapping
• Swap-out is a method of removing a process from Main memory and adding it to the hard disk.
• Swap-in is a method of removing a program from a hard disk and putting it back into the main memory.

• Example: Suppose the user process's size is 10KB and is a standard hard disk where swapping has a data
transfer rate of 40kB. Now we will calculate how long it will take to transfer from main memory to
secondary memory.

process size: 10kb


Rate =40kb
Time=process size/transfer rate
10/40=1/4=0.25seconds=250milli seconds
500milliseconds (swapin swap out)

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 9


Swapping
 Advantages
- higher degree of multiprogramming.
- better utilization of memory.
- Minimum wastage of CPU time on completion

Dynamic loading
- it is a routine of a program which is not loaded until the program calls it. All routines should be contained on
disk in a relocatable load format. The main program will be loaded into memory and will be executed. Dynamic
loading also provides better memory space utilization.

Dynamic linking
- Linking is a method that helps OS to collect and merge various modules of code and data into a single
executable file. The file can be loaded into memory and executed. OS can link system-level libraries into a
program that combines the libraries at load time. In Dynamic linking method, libraries are linked at execution
time, so program code size can remain small.
Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 10
compaction
 compaction

Compaction
Non contiguous MMT
TO overcome fragmentation
NCMMT
Paging
Multi level paging
Inverted paging
Segmented paging

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 11


Paging
 Paging
- it is a process of mapping the logical address into the physical address

 Need of paging
logical address can not directly access the physical address.
Terminology
1. Logical address: the address generated by CPU (virtual)
2. Physical address: resides with memory(real/actual)
3. PAS: set of physical addresses corresponds to the LA
4. LAS: set of logical addresses generated by program

LA > PA PA/LA contains two parts: 1. page No (p) 2.offset(d)

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 12


paging
 No of pages in LAS = LAS/PS=2^13/2^10=2^3=8

 No of frames in PAS=PAS/FS
 Page table
- it is a data structure
- it is used to map the page number to the frame number where the page is stored
- it contains page table entries, index F.No BKI
i. frame No (essential entry)
0 i
ii. Book keeping information (optional)
• Page tables are stored in main memory 1 v
• Each process is having its own page table Page
number 2

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 13


Paging
 Paging hardware

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 14


Paging
 Paging model of logical and physical memory

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 15


Paging
 Paging example for a 32-byte memory with 4-byte pages

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 16


Paging with TLB
 TLB (Translation Look a side Buffer)
- To reduce the effective memory access time TLB is introduced
 TLB is a hardware device which is located before the page table.
 It contains most frequently referenced page numbers along with their frame numbers.
 It works based on the principle locality of reference.

Pg no F.No

TLB

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 17


Paging
 Paging hardware with TLB

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 18


Paging
 Multi level paging
- as it is difficult to maintain the large page
table size multi level paging is introduced.
 In this paging is applied on the page table.
 Dividing the page table into pages.
 This division process is continued till
reaching the page size.
 Once the page table size reaches to the
page size then we stop it.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 19


Multi level paging
 Example
Given logical address of 32bits with a page size of 4KB and page table entry size of 4B. Find at which level
page size is reached?
Solution
Logical address space(LAS) =2^32
Page size(PS)=4KB
PTES(e)=4B
No of pages in LAS = no of entries in page table (n) = LAS/PS = 2^32/2^12 = 2^20

Page table size (PTS) = n*e = (2^20) * 4B=4MB -1 st level

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 20


Multi level paging
 No of pages= 1st level PTS/PS
=4MB/4KB=(4*(2^20))/(4*(2^10))=2^10=1KB
PTS in 2nd level is (n*e) =(1KB) * 4B=4KB
PTS =PS

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 21


Inverted paging
 Inverted paging
- to avoid the overhead of maintaining
the page table for each process, inverted
paging concept is implemented.
- In this a single table will be maintained
for all the processes in the system.
- frame number acts as index to the
frame table
Disadvantages
The searching time for the corresponding
pages of the process takes more time

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 22


Inverted paging
 Example
Consider a system with the logical address 34bit and physical address of 29bit. Assume that page size is
16KB and page table entry size is 8bytes then calculate
i. Conventional page table size
ii. Inverted page table size
solution
Given data LAS= 2^34
PAS = 2^29
PS = 16KB
PTES= 8
i) No of pages = LAS/PS=(2^34)/16KB = 2^20
PTS =n*e = (2^20) * 8 = 8MB

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 23


Inverted paging
 Inverted PTS
no of frames = PAS/PS
=(2^29)/ (2^14) = 2^15
PTS =n*e
(2^15) * 8 = 2^18=(2^8)KB =256KB

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 24


Segmentation
 Segmentation
Process of dividing the logical
address space into variable size
partition is called segmentation.
 Segment
Each variable size partition

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 25


Segmentation
 Segmentation Hardware

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 26


Segmentation
 Example of segmentation

Limit Base

1000 1400

400 3600

400 4300

1100 3200

1000 4700

Segment table

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 27


Segmentation
 Exercise
Consider the following segment table, which following logical address will produce Trap addressing error.
1. 0,430 Segment Base length
2. 1,11 No
0 1219 700
3. 2,100
1 2300 14
4. 3,425
2 90 100
5. 4, 95 3 1327 580
4 1952 96

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 28


Virtual Memory
 Virtual memory
- it is a storage allocation
scheme.

Degree of multiprogramming
- The no. of programs that can
Be executed simultaneously
In a memory.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 29


Virtual Memory
 Page fault
- requested page is not available
in the main memory from page
table.
Steps in handling page fault

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 30


Virtual Memory
Demand paging
keeping all pages of the frames in the secondary memory until they are required.

Thrashing
if the no. of page faults is equal to the number of referred pages.

EAT= PF * S + (1-PF) * (ma)


EAT – Effective memory Access Time
PF - Page Fault rate
S - Service time
ma - memory access time

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 31


Secondary Storage Structure
 Disk Structure
Operations performed on the
disk are read and write
when these operations are
performed following will possible
• Successful completion
• Partial failure
• Total failure

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 32


Disk Structure
 Terminology
- Allocation Unit
- Capacity
- Density
 Disk scheduling
To schedule I/O requests arriving for the Disk
It is also known as I/O Scheduling
Terminology used in disk scheduling
• Seek time
• Rotational latency
• Transfer time
• Disk Access Time
• Disk Response Time

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 33


Disk Scheduling Algorithms
 The following are some Disk scheduling algorithms
• FCFS
• SSTF
• SCAN
• C-SCAN
• LOOK
• C-LOOK

FCFS:
In FCFS, the requests are addressed in the order they arrive in the disk queue.
• Every request gets a fair chance
• No indefinite postponement

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 34


Disk Scheduling Algorithms
 Example:
Suppose the order of request is-
(82,170,43,140,24,16,190)
And current position of Read/Write
head is : 50
total seek time:
=(82-50)+(170-82)+(170-
43)+(140-43)+(140-24)+(24-
16)+(190-16)
=642

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 35


Disk Scheduling Algorithms
 SSTF (Shortest Seek Time First )
• Requests having shortest seek time are executed first.
• The seek time of every request is calculated in advance in the queue
• Now scheduling will be done according to their calculated seek time.
• So, the request near the disk arm will get executed first.

Advantages
• Average Response Time decreases
• Throughput increases

Disadvantages
• Overhead to calculate seek time in advance
• Can cause Starvation for a request if it has higher seek time as compared to incoming requests
• High variance of response time

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 36


Disk Scheduling Algorithms
 SSTF Example:
Suppose the order of request is-
(82,170,43,140,24,16,190)
And current position of Read/Write
head is : 50
 total seek time:
=(50-43)+(43-24)+(24-
16)+(82-16)+(140-
82)+(170-40)+(190-170)
=208
Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 37
Disk Scheduling Algorithms
 SCAN
• In this algorithm the disk arm moves into a particular direction and services the requests coming in its
path and after reaching the end of disk, it reverses its direction and again services the request arriving in
its path.
• This algorithm works as an elevator and hence also known as elevator algorithm.
• As a result, the requests at the midrange are serviced more and those arriving behind the disk arm will
have to wait.
 Advantages
• High throughput
• Low variance of response time
 Disadvantages
• Long waiting time for requests for locations just visited by disk arm
• It causes the head to move till the end of the disk even if there are no requests to be serviced.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 38


Disk Scheduling Algorithms
 Example (SCAN)
Suppose the requests to be
addressed are-
82,170,43,140,24,16,190. And the
Read/Write arm is at 50, and it is
also given that the disk arm should
move “towards the larger value”.
Seek time
=(199-50)+(199-16)
=332
Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 39
Disk Scheduling Algorithms
 CSCAN
• in which the disk arm instead of reversing its direction goes to the other end of the disk and starts
servicing the requests from there.
• So, the disk arm moves in a circular fashion and this algorithm works similar to SCAN algorithm
• Hence it is known as C-SCAN (Circular SCAN).
• Provides more uniform wait time compared to SCAN
Comparison with SCAN
• In SCAN algorithm, the disk arm again scans the path that has been scanned, after reversing its
direction. So, it may be possible that too many requests are waiting at the other end or there may be
zero or few requests pending at the scanned area.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 40


Disk Scheduling Algorithms
 Example:
Suppose the requests to be
addressed are-
82,170,43,140,24,16,190. And the
Read/Write arm is at 50, and it is
also given that the disk arm should
move “towards the larger value”.
 Seek time
 =(199-50)+(199-0)+(43-0)
=391
Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 41
Disk Scheduling Algorithms
 LOOK
• LOOK is similar to SCAN algorithm.
• the disk arm in spite of going to the end of the disk goes only to the last request to be serviced in front
of the head and then reverses its direction from there only.
• Thus it prevents the extra delay which occurred due to unnecessary traversal to the end of the disk.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 42


Disk Scheduling Algorithms
 Example:
Suppose the requests to be
addressed are-
82,170,43,140,24,16,190. And the
Read/Write arm is at 50, and it is
also given that the disk arm should
move “towards the larger value”.
Seek time
=(190-50)+(190-16)
=314
Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 43
Disk Scheduling Algorithms
 CLOOK:
• CLOOK is similar to CSCAN disk scheduling algorithm.
• the disk arm in spite of going to the end goes only to the last request to be serviced in front of the head
and then from there goes to the other end’s last request.
• Thus, it also prevents the extra delay which occurred due to unnecessary traversal to the end of the disk.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 44


Disk Scheduling Algorithms
 Example:
Suppose the requests to be
addressed are-
82,170,43,140,24,16,190. And the
Read/Write arm is at 50, and it is
also given that the disk arm should
move “towards the larger value”
Seek time
=(190-50)+(190-16)+(43-16)
=341
Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 45
Disk Management
 Disk Management
It is a utility which can be used to create, delete, format partitions and assign drive letters.
• It can also be used to view partitions and their formatted file systems on the hard drive.
 DISK formatting
• Physical formatting
• Logical formatting
Boot block
The boot strap program is stored in a partition at a fixed location on the disk.
Bad block
It is an area of storing media that is no longer reliable for the storage of data because it is completely
damaged or corrupted.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 46


Swap Space Management
 Swapping
It is a memory management technique
used in multi programming to increase
the no. of process sharing the CPU.
 Swap – space
The area on the disk where the swapped
out processes are stored.
 Swap space management
Generally, in systems we require best
throughput, as disk access is slower than
memory access it has to be managed.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 47


Swap space management
 A swap space can reside in one of the two places
1. Normal file system
2. Separate disk partition
Swap space management example

A data structure for swapping on Linux systems

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 48


RAID Structure
 Secondary storage – advantages and limitations
 Secondary storage – advantages and limitations

 Increasing Reliability via Redundancy

 RAID

 Mirroring and Data-Striping

 RAID Levels

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 49


RAID Structure
 Significant role in storing large amount of data as memory is expensive

 Plays a vital role when disk is used as virtual memory

 Magnetic in nature

 Characteristically uses a “moving head disk” mechanism to read and write data

 Performance of a single disk is very limited

 Improvement in disk technologies is still very impressive BUT only in the capacity / cost area.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 50


RAID
 Redundant Array of Inexpensive Disks –RAID. Described the various types of Disk Arrays
 The basic idea of RAID was to combine multiple, small inexpensive disks drive into an array of disk drives
which yields performance exceeding that of a Single, Large Expensive Drive.
 this array of drives appear to the computer as a single logical storage unit or drive.
 Redundancy
It is a system design in which a component is duplicated so if it fails there will be a backup.
using techniques
mirroring
data striping

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 51


Redundancy - Mirroring
• Duplicate every disk
• Logical disk consists of two physical disks.
• Every write is carried out on both disks.
• If one of the disk fails, data read from the other
• Data permanently lost only if the second disk fails before the first failed disk is replaced.
• Parallel Disk systems
• We cannot improve the disk performance significantly as a single drive
• But many applications require high performance storage systems, this can be achieved using parallel disk
systems.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 52


RAID
 Data striping
A method of concatenating multiple drives into one logical storage unit.
bit – level striping
Splitting the bits of each byte across multiple disks
Ex: an array of eight disks, write bit i of each byte to disk I
block-level striping - for blocks of file

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 53


RAID Levels
 RAID – 0 - referred to as striping

 Striping at the level of blocks


 Data split across in drives resulting in higher data throughput
 Performance is very good but the failure of any disk in the array results in data loss
 Reliability Problems : No

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 54


RAID Levels
 RAID 1(Mirroring)
• Performance Issues
-- No data loss if either drive fails
• Good read performance
• Reasonable write performance
• Cost / MB is high

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 55


RAID Levels
 RAID 2
 Uses Hamming (or any other) error-correcting code (ECC)
 Intended for use in drives which do not have built-in error detection
 Central idea is if one of the disks fail the remaining bits of the byte and the associated ECC bits can be
used to reconstruct the data
 Not very popular
 RAID 3
 Improves upon RAID 2, known as Bit-Interleaved Parity
 Disk Controllers can detect whether a sector has been read correctly.
 Storage overhead is reduced – only 1 parity disk
 Expense of computing and writing parity
 Need to include a dedicated parity hardware

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 56


RAID Levels
 RAID 4 (block-interleaved parity)
• Stripes data at a block level across several drives, with parity stored on one drive
• Allows recovery from the failure of any of the disks
• Performance is very good for reads
• Writes require that parity data be updated each time.
• Slows small random writes but large writes are fairly fast

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 57


RAID Levels
 RAID 5 -Block-interleaved Distributed parity
• Spreads data and parity among all N+1 disks, rather than storing data in N disks and parity in 1 disk
• Avoids potential overuse of a single parity disk – improvement over RAID 4

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 58


RAID Levels
 RAID 6 (P+Q Redundancy Scheme)

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 59


RAID Levels
 RAID LEVEL (0+1)
 RAID LEVEL (1+0)

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 60


Stable storage implementation
 The disk write operation results to one of the following outcome:

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 61


Stable storage implementation
 Process of execution of output
operation
1.Write the information onto the first
physical block.
2.When the first write completes
successfully, write the same
operation onto the second physical
block.
3.When both the operation declares
successfully, declare the operation
as complete.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 62


References
 Operating System Principles- Abraham Silberchatz, Peter B. Galvin, Greg Gagne7th Edition, John Wiley.

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 63


THANK YOU

Department of Computer Science & Engineering, VNRVJIET, Hyderabad April 6, 2025 64

You might also like