






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Detailed notes for Unit III of Operating Systems for the academic year 2025–26, written in a clear and easy-to-follow way with real-life analogies. Covers Main Memory and its role in CPU operations, followed by Swapping — how the OS moves processes in and out of RAM, including swap-in and swap-out. Then explains Contiguous Memory Allocation with fixed and variable partitions, First-fit, Best-fit, and Worst-fit algorithms, and the fragmentation problem. Segmentation and Paging are both covered in depth — including segment tables, page tables, and the difference between logical and physical addresses. From there, Virtual Memory explains how systems create the illusion of more RAM than available, and Demand Paging covers how pages are loaded only when needed.
Typology: Lecture notes
1 / 30
This page cannot be seen from the preview
Don't miss anything!























What is Main Memory? To achieve a degree of multiprogramming and proper utilization of memory, memory management is important. Many memory management methods exist, reflecting various approaches, and the effectiveness of each algorithm depends on the situation. The main memory is central to the operation of a Modern Computer. Main Memory is a large array of words or bytes, ranging in size from hundreds of thousands to billions. Main memory is a repository of rapidly available information shared by the CPU and I/O devices. Main memory is the place where programs and information are kept when the processor is effectively utilizing them. Main memory is associated with the processor, so moving instructions and information into and out of the processor is extremely fast. Main memory is also known as RAM (Random Access Memory). This memory is volatile. RAM loses its data when a power interruption occurs. ______________________________________________________________________________
To increase CPU utilization in multiprogramming, a memory management scheme known as swapping can be used. Swapping is the process of bringing a process into memory and then temporarily copying it to the disc after it has run for a while. The purpose of swapping in an operating system is to access data on a hard disc and move it to RAM so that application programs can use it.
It's important to remember that swapping is only used when data isn't available in RAM. Although the swapping process degrades system performance, it allows larger and multiple processes to run concurrently. Because of this, swapping is also known as memory compaction. The CPU scheduler determines which processes are swapped in and which are swapped out. Consider a multiprogramming environment that employs a priority-based scheduling algorithm. When a high-priority process enters the input queue, a low-priority process is swapped out so the high-priority process can be loaded and executed. When this process terminates, the low- priority process is swapped back into memory to continue its execution. The below figure shows the swapping process in the operating system: Swapping has been subdivided into two concepts: swap-in and swap-out. Swap-out is a technique for moving a process from RAM to the hard disc. Swap-in is a method of transferring a program from a hard disc to main memory, or RAM.
In contiguous memory allocation, each process is assigned a single, continuous block of memory. This means all the process's data is stored in adjacent memory locations. This method is simple and efficient for accessing memory, as the CPU can easily calculate the address of any location within
Efficiency: Can lead to faster memory access due to the contiguous nature of storage. Reduced overhead: Fewer address translations compared to non- contiguous methods. Drawbacks: Fragmentation: Can lead to wasted space and difficulty in allocating large processes. External fragmentation: Occurs when there is enough total memory, but it's not in a contiguous block. Internal fragmentation: Occurs when the allocated block is larger than the process needs. Limited multiprogramming: Can limit the number of processes that can be loaded into memory simultaneously, especially with fixed-size partitioning. ________________________________________________________________________
In operating systems (OS), segmentation is a memory management technique where a process's memory space is divided into variable-sized segments, not fixed-size pages like in paging. These segments can represent logical units of the program like code, data, or the stack. Unlike paging, segmentation reflects how a program is logically structured, allowing for more efficient memory allocation based on the program's needs. Key aspects of segmentation:
Logical Division: Processes are divided into segments corresponding to different program parts. Variable Size: Unlike paging, segments can have different sizes. Segment Tables: The OS uses segment tables to store information about each segment, including its base address and length. Mapping: Logical addresses (segment number and offset) are mapped to physical addresses using the segment table. Protection and Sharing: Segmentation can be used to protect segments from unauthorized access and to facilitate sharing of segments between processes. Virtual Memory: Segmentation can be used to implement virtual memory, allowing processes to use more memory than physically available. Benefits of segmentation: Efficient Memory Allocation Improved Program Organization Enhanced Protection Facilitates Sharing _____________________________________________________________________
Paging is the process of moving parts of a program, called pages, from secondary storage (like a hard drive) into the main memory (RAM). The main idea behind paging is to break a program into smaller fixed-size blocks called pages. To keep track of where each page is stored in memory, the operating system uses a page table. This table shows the connection between the
Page table stored in main memory: The page table is kept in main memory. This can add overhead when processes are swapped in or out. ________________________________________________________________________
A page table is a data structure used in operating systems to map virtual addresses to physical addresses in memory. This mapping is crucial for virtual memory, allowing processes to access more memory than physically available and enabling the OS to manage memory effectively. ________________________________________________________________________
Virtual memory is a memory management technique used in operating systems that allows programs to run even when they are larger than the physical RAM available. It creates an illusion of a larger memory space than what physically exists by using both RAM and hard disk storage. Purpose: Virtual memory is crucial for running large programs and multiple programs simultaneously, even when RAM is limited. How it works: The operating system divides virtual memory into pages and uses a page table to map virtual addresses to physical memory locations. Page Faults:
When the CPU attempts to access a page not currently in RAM, a page fault occurs. The operating system then fetches the necessary page from the hard disk (secondary storage) and loads it into RAM. Swapping: The operating system can also swap less recently used pages from RAM to the hard disk (swap space) to make room for other pages. Benefits: Allows programs to be larger than RAM: Programs can have a virtual address space larger than the available physical RAM. Enables efficient memory usage: The OS can manage memory more effectively by moving pages between RAM and disk. Supports multitasking: Multiple programs can run seemingly concurrently without being limited by physical RAM size. Simplified programming: Programmers don't need to be concerned with memory limitations. Drawbacks: Slower performance: Accessing pages on the hard disk is significantly slower than accessing RAM. Thrashing: If the OS is constantly swapping pages between RAM and disk, the system can become extremely slow, a condition known as thrashing. ____________________________________________________________________________
Demand paging is a memory management scheme used in operating systems to improve memory usage and system performance. Let's understand demand paging with real life example Imagine you are reading a very thick book, but you don’t want to carry the entire book around because it’s too heavy. Instead, you decide to only bring the pages you need as you read through the book. When you finish with one page, you can put it away and grab the next page you need. In a computer system, the book represents the entire program, and the pages are parts of the program called “pages” of memory. Demand paging
When a process tries to access a page that is not currently in physical memory, a page fault occurs. This triggers the OS to bring the needed page into memory. Limited Physical Memory: If physical memory is full (no free frames), a page replacement algorithm is needed to decide which page to swap out (write to disk) to make room for the new page.
2. How Page Replacement Works: Swapping: The process of moving pages between physical memory (RAM) and secondary storage (disk) is called swapping. Choosing a Page: Page replacement algorithms decide which page to swap out when a new page needs to be loaded. Minimizing Page Faults: The goal is to choose a page that is likely to be accessed in the near future, reducing the number of page faults. 3. Common Page Replacement Algorithms: First-In, First-Out (FIFO): Replaces the oldest page in memory, regardless of its use. Least Recently Used (LRU): Replaces the page that was least recently accessed. Optimal (OPT): Replaces the page that will not be used for the longest time in the future (theoretically optimal, but requires future knowledge). Other Algorithms: There are other algorithms like LFU (Least Frequently Used) and variants of FIFO and LRU.
An important aspect of operating systems, virtual memory is implemented using demand paging. Demand paging necessitates the
development of a page-replacement algorithm and a frame allocation algorithm. Frame allocation algorithms are used if you have multiple processes; it helps decide how many frames to allocate to each process. There are various constraints to the strategies for the allocation of frames: You cannot allocate more than the total number of available frames. At least a minimum number of frames should be allocated to each process. This constraint is supported by two reasons. The first reason is, as less number of frames are allocated, there is an increase in the page fault ratio, decreasing the performance of the execution of the process. Secondly, there should be enough frames to hold all the different pages that any single instruction can reference. Frame allocation algorithms - The two algorithms commonly used to allocate frames to a process are:
Causes of Thrashing: Insufficient Memory: When the system doesn't have enough physical memory to accommodate the combined demands of all running processes, it leads to frequent page faults and thrashing. Inefficient Page Replacement Algorithms: If the OS uses a page replacement algorithm that repeatedly removes pages that are soon needed again, it can contribute to thrashing. Excessive Multiprogramming: Running too many processes simultaneously can overload the system, increasing the frequency of page faults and thrashing. Poor Memory Allocation: If processes are allocated insufficient memory, they will constantly fault and thrash.
Memory mapping is a technique that allows a part of the virtual address space to be associated with a file logically. This technique of memory mapping leads to a significant increase in performance. Basic Mechanism of Memory Mapping
The Operating System uses virtual memory for memory mapping a file. It is performed by mapping a disk block to a page present in the physical memory. Initially, the file is accessed through demand paging. If a process references an address that does not exist in the physical memory, then page fault occurs and the Operating System takes charge of bringing the missing page into the physical memory. A page-sized portion of the file is read from the file system into a physical page. Multiple processes may be allowed to map a single file simultaneously to allow sharing of data. If any of the processes write data in the virtual memory, then the modified data will be visible to all the processes that map the same section of the file. The sharing of memory is depicted with the help of a diagram shown below.
Platters: Hard disk drives (HDDs) typically use multiple platters, which are rigid, circular disks coated with a magnetic material. These platters are stacked and rotate on a central spindle. Tracks: Each platter's surface is divided into concentric circles called tracks. Sectors: Tracks are further divided into smaller segments called sectors. Sectors are the basic units of storage and typically hold 512 bytes of data. Cylinders: A cylinder is a set of tracks, one on each platter, that are all at the same radial position. The OS uses cylinders as a way to address data on the disk.
Read/Write Heads: Each platter has a read/write head that can move across the tracks to read or write data. Logical Blocks: While physically organized into tracks and sectors, the OS logically treats the disk as a sequence of fixed-size logical blocks. Data Organization: The OS uses this disk structure to manage file systems, store data, and efficiently access information. Partitioning: Disks can be divided into partitions, each of which can have its own file system
The disk attachment is a special feature that allows you to attach a disk (such as a USB flash drive) to your computer’s hard drive. Users can use this feature to store files in the cloud or transfer files between computers on their network. Host-Attached Storage Host-attached storage (HAS) is a form of internal computer storage that can be attached to a host computer, such as a PC or server. Host-attached devices are often used for backup purposes and can include tape drives, optical drives, hard disk drives (HDDs), solid state drives (SSDs), USB flash drives, and other similar media. A common example of host-attached storage is the use of an external USB flash drive for data transfer between computers. This type of connection allows users to copy files from one device onto another without having to connect them directly through their operating system's file-sharing functionality - this means that you don't have access rights over your own system if someone else has access! Network-Attached Storage (NAS) A Network-Attached Storage (NAS) is a computer that is connected to a network and shared by multiple users. NAS can also be called a file server, or
The main goals of disk scheduling are to optimize the performance of disk operations, reduce the time it takes to access data and improve overall system efficiency. Key Terms Associated with Disk Scheduling Seek Time: Seek time is the time taken to locate the disk arm to a specified track where the data is to be read or written. So the disk scheduling algorithm that gives a minimum average seek time is better. Rotational Latency: Rotational Latency is the time taken by the desired sector of the disk to rotate into a position so that it can access the read/write heads. So the disk scheduling algorithm that gives minimum rotational latency is better. Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating speed of the disk and the number of bytes to be transferred. Disk Access Time:
Disk Access Time and Disk Response Time Disk Response Time: Response Time is the average time spent by a
the measure of how individual requests are serviced with respect to average response time. So the disk scheduling algorithm that gives minimum variance response time is better. Disk Scheduling Algorithms
There are several Disk Several Algorithms. We will discuss in detail each one of them. FCFS (First Come First Serve) SSTF (Shortest Seek Time First) SCAN C-SCAN LOOK C-LOOK RSS (Random Scheduling) LIFO (Last-In First-Out) N-STEP SCAN F-SCAN
1. FCFS (First Come First Serve) FCFS is the simplest of all Disk Scheduling Algorithms. In FCFS, the requests are addressed in the order they arrive in the disk queue. Let us understand this with the help of an example.