Operating System Tutorial

Operating System Tutorial Types of Operating System Evolution of Operating System Functions of Operating System Operating System Properties Operating System Services Components of Operating System Needs of the Operating System

Operating Systems

Linux Operating System Unix Operating System Ubuntu Operating System Chrome Operating Systems Fedora Operating System MAC Operating System MS Windows Operating System Solaris Operating System Cooperative Operating System CorelDRAW Operating System CentOS FreeBSD Operating Systems Batch Operating System MS-DOS Operating System Commercial Mobile Operating Systems


Difference Between Multi-programming and Multitasking Difference between C-LOOK and C-SCAN Difference between Rotational Latency and Disk Assess Time Trap vs Interrupt Difference between C-SCAN and SSTF Difference between SCAN and FCFS Difference between Seek Time and Disk Access Time Difference between SSTF and LOOK Difference between Process and Program in the Operating System Difference between Protection and Security in Operating System

How To

How to implement Monitors using Semaphores How to Install a Different Operating System on a PC


What is Kernel and Types of Kernel What is DOS Operating System What is Thread and Types of Thread What is Process Scheduler and Process Queue What is Context Switching What is CPU Scheduling What is Producer-Consumer Problem What is Semaphore in Operating System Monitors in Operating System What is Deadlock What is Paging and Segmentation What is Demand Paging What is Virtual Memory What is a Long term Scheduler What is Page Replacement in Operating System What is BSR Mode What is Convoy Effect What is Job Sequencing in Operating System Why is it critical for the Scheduler to distinguish between I/O-bound and CPU-bound programs Why is there a Need for an Operating System


Process Management Process State Scheduling Algorithm FCFS (First-come-First-Serve) Scheduling SJF (Shortest Job First) Scheduling Round-Robin CPU Scheduling Priority Based Scheduling HRRN (Highest Response Ratio Next) Scheduling Process Synchronization Lock Variable Mechanism TSL Mechanism Turn Variable Mechanism Interested Variable Mechanism Deadlock Avoidance Strategies for Handling Deadlock Deadlock Prevention Deadlock Detection and Recovery Resource Allocation Graph Banker’s Algorithm in Operating System Fixed Partitioning and Dynamic Partitioning Partitioning Algorithms Disk Scheduling Algorithms FCFS and SSTF Disk Scheduling Algorithm SCAN and C-SCAN Disk Scheduling Algorithm Look and C-Look Disk Scheduling Algorithm File in Operating System File Access Methods in Operating System File Allocation Method Directory Structure in Operating System N-Step-SCAN Disk Scheduling Feedback Queue in Operating System Contiguous Memory Allocation in Operating System Real-time Operating System Starvation in Operating System Thrashing in Operating System 5 Goals of Operating System Advantages of Operating System Advantages of UNIX Operating System Bit Vector in Operating System Booting Process in Operating System Can a Computer Run Without the Operating System Dining Philosophers Problem in Operating System Free Space Management in Operating System Inter Process Communication in Operating System Swapping in Operating System Memory Management in Operating System Multiprogramming Operating System Multitasking Operating Systems Multi-user Operating Systems Non-Contiguous Memory Allocation in Operating System Page Table in Operating System Process Scheduling in Operating System Segmentation in Operating System Simple Structure in Operating System Single-User Operating System Two Phase Locking Protocol Advantages and Disadvantages of Operating System Arithmetic operations in binary number system Assemblers in the operating system Bakery Algorithm in Operating System Benefits of Ubuntu Operating System CPU Scheduling Criteria in Operating System Critical Section in Operating System Device Management in Operating System Linux Scheduler in Operating System Long Term Scheduler in Operating System Mutex in Operating System Operating System Failure Peterson's Solution in Operating System Privileged and Non-Privileged Instructions in Operating System Swapping in Operating System Types of Operating System Zombie and Orphan Process in Operating System 62-bit operating system Advantages and Disadvantages of Batch Operating System Boot Block and Bad Block in Operating System Contiguous and Non - Contiguous Memory Allocation in Operating System Control and Distribution Systems in Operations Management Control Program in Operating System Convergent Technologies in Operating System Convoy Effect in Operating System Copy Operating Systems to SSD Core Components of Operating System Core of UNIX Operating System Correct Value to return to the Operating System Corrupted Operating System Cos is Smart Card Operating System Cosmos Operating Systems Examples Generation of Operating System Hardware Solution in Operating System Process Control Block in Operating System Function of Kernel in Operating System Operating System Layers History of Debian Operating Systems Branches and Architecture of Debian Operating Systems Features and Packages of Debian Operating Systems Installation of Operating System on a New PC Organizational Structure and Development in Debian Operating Systems User Interface in Operating System Types Of Memory in OS Operating System in Nokia Multilevel Paging in OS Memory Mapping Techniques in OS Memory Layout of a Process in Operating System Hardware Protection in Operating System Functions of File Management in Operating System Core of Linux Operating System Cache Replacement Policy in Operating System Cache Line and Cache Size in Operating System What is Memory Mapping? Difference Between Network Operating System And Distributed Operating System What is the difference between a Hard link and a Soft Link? Principles of Preemptive Scheduling Process Scheduling Algorithms What is NOS? What is the Interrupt I/O Process? What is Time Sharing OS What is process termination? What is Time-Sharing Operating System

Paging and Segmentation in OS

What is Paging in OS?

Paging is a storage technique used for memory management. In paging, the (OS) Operating System retrieves the processes from the secondary memory into the main memory, and the memory is in the form of the pages. In this technique, we split the main memory into the small blocks of physical memory which are called frames. The size of the frames is fixed. In paging, for the maximum usage of the main memory and to prevent external fragmentation, the frame size must be the same as the page size. Paging is a logical concept, and it helps us to access the data faster.

Benefits of Paging

The benefits of Paging are:

  1. In Paging, there is no need of external fragmentation.
  2. In Paging, the swapping between the equal-size pages and page frames is easy.
  3. Paging is a simple technique that we use for memory management.

Drawbacks of Paging

The Drawbacks of Paging are:

  1. In Paging, there may be a chance of Internal Fragmentation.
  2. In Paging, the Page table consumes extra memory.
  3. Due to Multi-level Paging, there may be a chance of memory reference overhead.

What is Paging Protection?

Paging Protection means to protect the paging process by inserting an extra bit, known as valid/Invalid bit.

In paging, memory protection is done by adding the protection bits with each page. With each page table entry, these bits are linked. It also helps to specify the protection on the corresponding page.

Example of Paging

Suppose we have main memory, and the size of the main memory is 16 KB, and the size of the frame is 1 KB. In this, the main memory is split into 16 frames, and each frame is of 1 KB.

In the system, we have four distinct processes, and the processes are A1, A2, A3, and A4, and the size of each process is 4 KB. In this, we split or divide all the pages into the pages of size 1KB so that the OS can store 1page in 1 frame.

What is Paging?

When the process started its execution, all the frames were vacant to store process pages in a contiguous manner.

The below figure shows the frames, pages, and the mapping between the frames and the pages.

We can see in the following example that after some time, the process A2 and the process A4 are moved into the waiting state. So, the eight frames will become vacant, and we need to load or put other pages in those vacant blocks. The process A5 is having a size of eight pages (8 KB), which are waiting in the ready queue.

What is Paging?

We can see in the following example that we have eight non-contiguous frames that are existing in the memory, with the help of paging, we can store the processes at different places. Due to this, we can load the pages of the A5 process instead of process A2 and Process A4.

What is Segmentation?

Segmentation is a technique of memory management. It is just like the Paging technique except the fact that in segmentation, the segments are of variable length but, in Paging, the pages are of fixed size. In segmentation, the memory is split into variable-length parts. Each part is known as segments. The information which is related to the segment is stored in a table which is called a segment table.

There are two types of information stored in the segment table:

  1. Limit
  2. Base

Limit: - The limit is the length or size of the segment

Base: - The base is the base address of the segment.

A segment of the program comprises of the utility function, data structure, and the main function of the program for each process. The operating system preserves a segment map table for mapping. The table consists of segment number, list of the memory blocks which are free along with its size, and its memory location in the virtual memory or the main memory.

What is Paging?

Types of Segmentation:

There are two types of Segmentation:

1. Simple Memory Segmentation

2. Virtual Memory Segmentation

Simple Memory Segmentation: - In simple memory segmentation, each process is split into different segments, and at the run time, all the processes are loaded. Also, not all the processes need to be loaded into a contiguous way.

Virtual Memory Segmentation: - As simple memory segmentation, in virtual memory segmentation, each process is split into different segments, but not all of them are residents at any point of time.

Benefits of Segmentation

The benefits of Segmentation are:

  1. Internal fragmentation is not present in the segmentation.
  2. Less overhead.
  3. In segmentation, the segment table size is less than the page table size.
  4. In segmentation, the relocation of the segment is easier than the whole address space.

Drawbacks of Segmentation

The drawbacks of segmentation are:

  1. In segmentation, there may be a chance of external fragmentation.
  2. The segmentation technique is expensive.
  3. In Segmentation, it is tough to allocate memory in a contiguous manner to a variable-sized partition.

Why Segmentation is needed?

Initially, we used the Paging technique for memory management. But instead of the user, it is closer to the operating system more probably. In paging, all the processes are split into the pages. Sometimes there may be a situation where a process having some relevant sections of the function requires being loaded on the same page.

The operating system does not mind the process from the user’s point of view. The operating system split the same function into the number of pages, and at the same time, the pages may be loaded or not loaded into the memory. Due to this reason, system efficiency could be decreased.

So, it is better to use the segmentation technique for memory management. In segmentation, the process is split into the segments. In this, every segment consists of a similar kind of function as a library function contained in one segment, and the main function contained in the other segment.

Translation of Logical Address into Physical Address by Segment Table

The CPU generates a logical address that comprises of two parts:

  1. Segment Number
  2. Segment Offset

Segment Number: - Segment Number is defined as the number of bits that are needed to represent the segment.

Segment Offset: - Segment Offset is defined as the number of bits which are needed to represent the size of the segment.

What is Paging?

We map the segment number to the segment table, and after mapping, a comparison is done between the limit of the segment to the offset. If the offset bit is less than the limit, then we can say that the address is valid. Otherwise, the address is invalid.

If the address is valid then we add the base address of the segment to the offset so that we can get the physical address of the actual word in the main memory.

Difference between Paging and Segmentation

            Paging          Segmentation
Paging is a memory management technique. In paging, memory is partitioned into fixed-size pages. Segmentation is also a memory management technique. In segmentation memory is partitioned into the variable size segments.
In paging, with the help of hardware page size is determine. In segmentation, the user gives the size of the segments.
In paging the OS is accountable for paging. There is a compiler which is accountable for the segmentation.
Paging is faster than the segmentation. Segmentation is slower than the paging.
In paging, there may be a chance of internal fragmentation. In segmentation, there may be a chance of external fragmentation.
In this technique, the logical address is partitioned into the page number and the page offset. In this technique, the logical address is partitioned into the section number and the section offset.
In paging, to calculate the absolute address requires page number and the offset. In segmentation, to calculate the value of absolute address require Segment number and the offset.
The user cannot see the Paging. The user can see the segmentation.
In this technique, the list of free frames is maintained by the operating system. In this technique, the list of holes is maintained by the operating system.
The page table is created to maintain page data. Section table is created to maintain the section data.
In paging, a page table encloses the base address of each page. In Segmentation, a segment table encompasses the segment number and the offset.