0% found this document useful (0 votes)
7 views32 pages

Lecture 4

Uploaded by

Aim It
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)
7 views32 pages

Lecture 4

Uploaded by

Aim It
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

Lecture 4

Memory & Storage Management


What is Memory Management?

• - Controls how RAM is used


• - Gives memory to programs
• - Keeps programs from interfering
• - Maximizes efficiency
Types of Memory Allocation

• - Single Partition: One program in RAM


• - Multiple Partitions: Many programs
• - Fixed vs Variable Sizes
• - Swapping: Move processes to/from disk
Contiguous Allocation &
Fragmentation

• - First Fit, Best Fit, Worst Fit methods


• - External Fragmentation: Gaps between
memory blocks
• - Internal Fragmentation: Wasted space inside
blocks
• In contiguous memory allocation, processes
are assigned to continuous memory blocks.
Three main algorithms are used:
• First Fit: Allocates the first available memory
block that is large enough.
• Best Fit: Chooses the smallest available block
that fits the process, minimizing wasted space.
• Worst Fit: Selects the largest available block,
hoping to leave large chunks of free space.
Practice Question
• Consider six memory partitions of size 200 KB,
400 KB, 600 KB, 500 KB, 300 KB and 250 KB.
These partitions need to be allocated to four
processes of sizes 357 KB, 210 KB, 468 KB and
491 KB in that order.
• Perform the allocation of processes using-
– First Fit Algorithm
– Best Fit Algorithm
– Worst Fit Algorithm
Solution
• According to question. The main memory has
been divided into fixed size partitions as-
Process P1 = 357 KB
Process P2 = 210 KB
Process P3 = 468 KB
Process P4 = 491 KB

Allocation Using First Fit Algorithm-

In First Fit Algorithm,

Algorithm starts scanning the partitions serially.


When a partition big enough to store the process is found, it
allocates that partition to the process.
• The allocation of partitions to the given processes is
shown below-
• Step 1

• Step 2

• Step 3

• Step 4: Process P4 can not be allocated the memory.


This is because no partition of size greater than or
equal to the size of process P4 is available.
• Now do the other algorithms
Paging (Non-Contiguous
Allocation)

• - Divides memory into equal-sized pages


• - Pages stored anywhere in RAM
• - Page Table keeps track of page locations
• - Solves external fragmentation
Segmentation (Logical Division)

• - Divides memory into logical parts: Code,


Data, Stack
• - Segments are variable-sized
• - Helps organize and protect memory use
What is Virtual Memory?

• - Makes programs think they have more RAM


• - Uses hard disk as backup memory
• - Allows large programs to run
Demand Paging & Page Faults

• - Pages loaded only when needed


• - Page Fault = page not in memory
• - OS loads it from disk
Page Replacement Algorithms

• - FIFO: Oldest page removed


• - LRU: Least recently used removed
• - Optimal: Best theoretical choice
Thrashing: Too Many Page Faults

• - CPU spends more time swapping than


working
• - Caused by low memory
• - Fix: Add RAM or limit programs
Frame Allocation Methods

• - Equal vs Proportional allocation


• - Local vs Global page replacement
HDD Basics: Tracks, Sectors,
Platters

• - Disks have spinning platters


• - Data stored in concentric tracks
• - Read/write head accesses sectors
Disk Scheduling Algorithms

• - FCFS: First Come First Serve


• - SSTF: Shortest Seek Time First
• - SCAN: Elevator movement
• - C-SCAN: Circular scanning
Problem
• Consider a disk queue with requests for I/O to
blocks on cylinders 98, 183, 41, 122, 14, 124,
65, 67. The FCFS scheduling algorithm is used.
The head is initially at cylinder number 53.
The cylinders are numbered from 0 to 199.
The total head movement (in number of
cylinders) incurred while servicing these
requests is
Solution

Total head movements incurred while servicing these requests


= (98 – 53) + (183 – 98) + (183 – 41) + (122 – 41) + (122 – 14) + (124 – 14) +
(124 – 65) + (67 – 65)
= 45 + 85 + 142 + 81 + 108 + 110 + 59 + 2
= 632
• Now try the other algorithms
Disk Management & Boot Block

• - Low-level Formatting: Prepares disk


• - Partitioning: Splits disk into parts
• - Logical Formatting: Sets up file system
• - Boot Block: Loads OS
Swap Space on Disk

• - Used as extra 'virtual RAM'


• - Stores inactive programs
• - Can be a file or partition
Recap & Key Takeaways

• - Memory management keeps systems fast &


safe
• - Virtual memory allows big programs
• - HDDs use smart scheduling & formatting
• - OS does the work behind the scenes
What is Memory Management?
(Windows 10 Example)

• - Task Manager shows how memory is


allocated
• - 'Performance' tab → Memory graph
• - Shows how much RAM is in use and by which
apps
Memory Allocation (Windows 10)

• - Programs share RAM based on need


• - Background apps may be swapped out
• - Right-click task in Task Manager → 'Go to
details'
Paging in Windows 10

• - [Link] is used as virtual memory


• - Stored on disk (C:\[Link])
• - System automatically moves inactive data to
this file
Virtual Memory Settings (Windows
10)

• - Control Panel → System → Advanced System


Settings
• - Under 'Performance' > Settings > Advanced >
Virtual Memory
• - Users can view/change page file size
Thrashing in Windows 10

• - Symptoms: Slow performance, high disk


usage
• - Task Manager: Check if Disk usage is at 100%
• - Caused by too many apps using memory
Disk Management in Windows 10

• - Right-click Start → Disk Management


• - View partitions, format drives, assign letters
• - Shows how OS handles physical storage
Swap Space in Windows 10

• - Windows uses a swap file ([Link])


• - Used when RAM is full
• - Can be adjusted or turned off in system
settings

You might also like