OS Notes
OS Notes
An operating system is a system software that provide an interface between user and computer
hardware and along with application software.
Purposes of OS:
1) Manage all resources like CPU, memory, I/O etc.
2) Provide an environment so that other application program can run smoothly
3) Control the I/O devices and I/O operation
4) Manage file system
5) Schedule all tasks
6) Control traffic of network system
Resource Management: The operating system manages the hardware resources of a computer
system, including the CPU, memory, storage devices, and input/output devices. It allocates
resources to various programs and processes, ensuring efficient utilization and preventing
conflicts.
Provide a user interface: The user interface allows you to run programs, manage files, and
access the computer's features. This is the way you interact with the computer. It can be a
graphical user interface (GUI) with icons and windows, or a command-line interface (CLI)
where you type commands.
What is process? Why IPC is necessary?
Process are instance of program execution. A process communicate with other process via
system call.
IPC is necessary because:
i) to avoid deadlock
ii) to avoid critical region problem
iii) to avoid race condition
iii) synchronization of tasks (when many process are working at a time)
System calls are the way programs interact with the operating system kernel to request services
related to process management. Here are some common system calls for process management:
Process Creation:
fork(): This system call creates a new process that is a nearly identical copy of the calling
process. The new process is called the child process, and the original process is called the
parent process. Both parent and child continue execution after the fork, with the child
process receiving a unique identifier.
Process Termination:
exit(): This system call allows a process to terminate itself and indicate an exit status to
the parent process (if any). The exit status is a small integer value that can be used by the
parent process to understand why the child process exited.
wait() / waitpid(): These system calls allow a parent process to wait for one or more of
its child processes to terminate. They provide information about the exited child process,
including the exit status.
A process table entry typically holds information for managing a process, including:
Identification: Process ID (PID), owner/user ID, parent process ID.
State: Current state (running, waiting, ready).
Execution: Program counter (PC), registers.
Memory Management: Memory pointers, memory limits.
Scheduling: Priority, CPU usage, scheduling information.
Resources: Open files/devices (file descriptors).
Communication: Inter-process communication (IPC) mechanisms.
What is Kernel?
The kernel of an operating system (OS) is its core component that manages system resources and
communication between hardware and software. It handles essential tasks such as process
management, memory management, device control, and system calls, providing a bridge
between applications and the hardware.
What is Shell?
It is the primary interface between a user sitting at his terminal and the OS.
Command-Line Shell (CLI): This is the classic text-based interface where you type
commands and see text output.
Graphical Shell (GUI): This is the more user-friendly interface with windows, icons, menus,
and a mouse. While GUIs provide a visual way to interact with the system, they often rely on a
shell underneath to execute commands in the background.
What is System call? What the purpose of it?
The interface between the OS and the user program is defined by a set of instruction set called
system call. Program's request to OS for privileged services (hardware, files, etc. ). A system call
in operating systems is a controlled entry point to request services from the kernel for tasks like
file operations, process management, and device control.
Purpose of the system call:
Resource Management
-process Communication
Compare the monolithic system and layered system of operating system structure.
Monolithic System:
In a monolithic operating system structure, all operating system services are packaged into a
single large kernel.
Layered System:
Description: A layered operating system structure divides the OS into layers, each providing
specific functionalities, with higher layers relying on services from lower layers.
What is Buffer cache?
To speed up data access and improve overall system performance, the operating system keeps a
portion of frequently accessed data in a reserved memory area called the buffer cache. This
reduces the need for constant disk access, minimizing response time and boosting throughput.
What is Multiprogramming?
Multiprogramming allows an operating system to manage and execute multiple programs
concurrently on a single CPU system.
What are the advantages and disadvantages of monolithic and microkernel architectures?
Monolithic Architecture
Advantages:
Performance: Typically faster as all system services run in a single address space.
Simplicity: Easier to design and implement since all components are tightly integrated.
Ease of Access: System calls can be made directly, leading to lower overhead.
Disadvantages:
Stability and Security: A bug in any part of the kernel can crash the entire system or
compromise security.
Complexity in Debugging: Difficult to debug and maintain due to the tightly coupled
nature.
Scalability: Less modular, making it harder to extend and adapt to new requirements.
Microkernel Architecture
Advantages:
Stability and Security: Better isolation of services, so faults in one service do not affect
others.
Modularity: Easier to update and maintain since components are more independent.
Scalability: More adaptable to new requirements and easier to extend with new services.
Disadvantages:
Performance: Generally slower due to the overhead of message passing between the
kernel and services.
Complexity: More complex to design and implement due to the need for inter-process
communication.
Resource Consumption: Higher resource usage due to the additional mechanisms for
communication and separation.
What is a real-time operating system (RTOS)? How does it differ from a general-purpose
OS?
Real-time operating system (RTOS) ensures tasks meet strict deadlines, crucial for timing-
sensitive systems like:
A hypervisor, also known as a virtual machine monitor (VMM), manages multiple VMs on a
single physical host by allocating resources like CPU, memory, and storage.
There are two types of hypervisors: Type 1 runs directly on hardware (bare-metal), while Type 2
runs on a host operating system.
The hypervisor ensures isolation between VMs, allowing them to operate independently and
securely.
Parallel Operating System: A parallel OS is designed to manage and utilize multiple processors
within a single computer system. It enables simultaneous processing of tasks by dividing them
into smaller sub-tasks and distributing them across multiple processors.
What is Thread?
In an operating system (OS), a thread is the smallest unit of execution within a process. A
process can have multiple threads, all of which share the same resources but can execute
independently.
(a) Three processes each with one thread (b) One process with three threads
The Thread Model-2
What is a process scheduling algorithm? What are its properties? Describe different type
of CPU scheduling algorithm.
A process scheduling algorithm is a method used by an operating system to determine which
processes should be executed by the CPU and in what order.
• When more than one process is runnable, the OS must decide which one to run first.
• Scheduler makes this decision using some scheduling algorithm
Properties:
CPU Utilization: The algorithm aims to keep the CPU as busy as possible. Higher CPU
utilization means better performance.
Throughput: This refers to the number of processes that complete their execution in a given time
period. A higher throughput indicates a more efficient scheduling algorithm.
Turnaround Time: The total time taken from the submission of a process to its completion. The
algorithm aims to minimize turnaround time.
Waiting Time: The total time a process spends in the ready queue waiting to be executed. The
goal is to minimize waiting time.
Response Time: The time it takes from when a request was submitted until the first response is
produced. This is particularly important in interactive systems.
Fairness: Ensuring that each process gets a fair share of the CPU without any process being
starved.
Preemptive Scheduling: The operating system can interrupt and suspend a currently running
process to start or resume another process, ensuring higher priority tasks are executed promptly.
Describe all process scheduling algorithms (round robin, shortest job first, guaranteed
scheduling, lottery, etc.)
Description: The process with the shortest execution time is selected next.
Pros: Minimizes average turnaround time.
Cons: Can cause starvation for longer processes; requires knowing the execution time in
advance.
(a) list of runnable processes list of runnable processes after (b) B uses up its quantum
• Suppose quantum is 20 ms and context switch takes 5 ms (total 25 ms)
Cause 20% CPU time wastage
• If quantum is 500 ms . Cause less than 1% CPU time wastage but poor response time
Priority Scheduling
To prevent high-priority processes from running indefinitely, the
scheduler may decrease the priority of currently running process at each clock tick.
I/O bound processes are given highest priority
What is Semaphore ?
Semaphores help prevent race conditions and ensure that resources are used efficiently without
conflicts. A semaphore is a synchronization primitive used to control access to a common
resource by multiple processes or threads in a concurrent system.
-Proposed by Dijkstra
Counts the number of wakeups:
Values — 0 (no wakeup)
1+ (pending wakeups)
Two operations —
down: decrements value if greater than 0, otherwise process goes to sleep
up: increments value if no process is sleeping, otherwise wakes a process at random —
Operations are atomic
What is Monitors?
• One have to be very careful while using semaphore
• Monitor is like class where only one procedure is active at one time
It is sufficient to put only the critical regions into monitor procedures as no two processes will
ever execute their critical regions at the same time
What is Mutexes?
In an operating system (OS), a mutex (short for "mutual exclusion") is a synchronization
primitive used to prevent multiple threads or processes from concurrently accessing a shared
resource, such as a variable, data structure, or critical section of code.
1. Lock (Acquire):
o A thread locks a mutex before entering the critical section. If the mutex is already
locked, the thread is blocked until the mutex becomes available.
2. Unlock (Release):
o A thread unlocks the mutex after leaving the critical section, allowing other
threads to acquire the mutex and enter the critical section.
Problem Description
Philosophers: Each philosopher thinks, then gets hungry, and tries to eat.
Forks: Shared resources that philosophers need to pick up before they can eat.
Challenges:
Mutual Exclusion: Ensure that no two philosophers can use the same fork simultaneously.
Deadlock: Avoid situations where all philosophers pick up their left fork and are waiting for the
right fork, causing a circular wait.
Starvation: Ensure that every philosopher gets a chance to eat and does not starve.
Solutions in General:
Mutual Exclusion: Ensure only one philosopher can access the forks (critical section) at a
time.
Ordered Access: Introduce an order to acquire forks, like picking up the left one first and
then the right one.
Semaphores: Use semaphores (synchronization primitives) to control access to the forks.
Monitors: Implement monitors (high-level constructs) to manage access and conditional
waiting.
Math: Say all processes arrived at time 0. Now, given p1 (burst time=10, priority 3), p2 (burst
time=1, priority 1), p3 (burst time=2, priority 3), p4 (burst time=1, priority 4), p5 (burst time=5,
priority 2), determine the Gantt chart for FCFS, SJF, and priority scheduling.
Chapter: Resource
What is Remote resources?
In operating systems, remote resources refer to hardware, software, or data that's located on a
different computer and accessed over a network. This allows users to share and utilize resources
that aren't physically present on their own machine.
Examples:
• Files and storage
• Printers
• Applications
• Databases:
• Network Services:
• Peripherals
What is Deadlock ?
A deadlock in an OS is a waiting loop where processes hold resources and wait for others to
release resources they hold creating a cycle of dependencies with no possibility of resolution.
Recovery through preemption: Take a resource from another process, depending on the nature of
the resource.
Recovery through rollback: Periodically checkpoint processes, using saved states to restart
deadlocked processes.
Recovery through killing processes: Break deadlock by terminating one of the processes in the
deadlock cycle, allowing others to acquire its resources. Choose processes that can be restarted
from the beginning.
Resource Allocation Graph (RAG) Updates: Update the RAG each time a resource is requested
or released. Check for the existence of cycles in the graph:
Periodic Process Checking: Regularly monitor processes to identify if any are blocked for an
extended period. Terminate such processes to prevent potential deadlock situations from arising.
Hold and Wait Prevention: Require processes to request all required resources at once, and block
the process until all resources can be allocated simultaneously.
Mutual Exclusion: Ensure that some resources are only allocated in a way that does not require
mutual exclusion.
The resource allocation graph (RAG) finds deadlock by detecting cycles: processes and resources
are nodes, with edges indicating which processes hold which resources. A cycle indicates each
process waits for a resource held by another, signaling a potential deadlock and triggering OS
interventions like process termination or resource reallocation.
Two-Phase Locking is a concurrency control method used in database systems and operating
systems to ensure serializability of transactions. It involves two distinct phases:
1. Phase One:
o The process attempts to lock all necessary records, one at a time.
o If a needed record is found to be locked, the process starts over (no real work is
done in this phase).
2. Phase Two:
o If Phase One succeeds, the process proceeds to the second phase.
o It performs the required updates and then releases the locks.
The Two-Phase Locking (2PL) system prevents deadlock by sequentially acquiring and releasing
locks:
1. Growing Phase: Transactions acquire locks one at a time, holding them until all required
locks are obtained, preventing partial execution that could lead to deadlock.
2. Shrinking Phase: After completing operations, locks are released in reverse order,
ensuring resources cannot be reacquired to avoid potential deadlock situations.
3. Key Points: 2PL ensures sequential locking to minimize resource holding, prevents
circular waits, and maintains transaction serializability for system stability and
performance.
What is Starvation?
Starvation occurs in resource allocation algorithms where a certain resource allocation policy,
such as giving resources to the shortest job first, may prioritize short jobs effectively but could
indefinitely delay longer jobs from accessing resources, even if they are not blocked.
Math: using a page table(given below) determine physical address corresponding to each of the
following virtual address : (a) 25, (b) 8200 c) 46000
15 000 0
14 000 0
13 000 0
12 000 0
11 111 1
10 000 0
9 101 1
8 000 0
7 000 0
6 000 0
5 011 1
4 000 1
3 000 1
2 110 1
1 001 1
0 000 1
Chapter: Memory management
Both techniques aim to maximize memory utilization and system performance by allowing more
processes to be loaded and executed concurrently.
Fixed Partition Swapping
In fixed partition swapping, memory is divided into fixed-size partitions. Each partition can hold
exactly one process. If a process is swapped out, its partition becomes available for another
process. However, this can lead to inefficient memory utilization due to internal fragmentation,
as a process may not fully use the entire partition.
In non-fixed partition swapping, memory is divided into variable-sized partitions based on the
exact memory needs of the processes. When a process is swapped in, it is allocated just enough
memory to fit its requirements. This approach minimizes internal fragmentation but can lead to
external fragmentation, where free memory is scattered in small blocks, making it difficult to
allocate large contiguous memory regions.
Virtual memory is a memory management technique that allows an operating system to use hard
disk space as additional RAM. This enables a computer to run larger applications or multiple
applications simultaneously, even if the physical RAM is insufficient. Virtual memory creates
the illusion of a large, contiguous block of memory by mapping physical memory addresses to
virtual addresses. The operating system handles this mapping, allowing programs to access more
memory than is physically available.
What is Swapping?
Swapping is a process where the operating system moves data or entire processes between the
physical memory (RAM) and the swap space on a hard disk. When the system runs out of
physical memory, inactive or less frequently used pages or processes are swapped out to the disk
to free up RAM for active processes. When the swapped-out processes or data are needed again,
they are brought back into RAM, possibly swapping out other data in the process. This
mechanism ensures that the system can handle more processes or larger data sets than would
otherwise fit in physical memory alone.
Compare Virtual Memory and swapping .
Virtual Memory:
Definition: A technique that uses disk space to extend the available RAM, creating an illusion of
a larger, continuous memory space.
Function: Allows running large applications and multiple processes by mapping virtual
addresses to physical addresses.
Swapping:
Definition: A specific memory management process where entire processes or data segments are
moved between RAM and disk space (swap space).
Paging in virtual memory splits both physical memory (RAM) and virtual memory into fixed-
size chunks (frames and pages). A page table tracks where each page resides in RAM. When a
program needs data, the virtual address is translated using the page table to find the physical
location in RAM. If the data isn't in RAM (page fault), the OS swaps it in from disk. This
reduces fragmentation and simplifies memory management.
X
X
5 7
6 6
X 5
4 4
X 3
0 2
7 1
2 0
1
3
The relation between virtual addresses and physical memory addresses given by page table
Internal operation of MMU with 16 4 KB pages
TLB is used to accelerate the process of address translation in virtual memory systems,
enhancing the efficiency and speed of memory access in computers. A Translation Lookaside
Buffer (TLB) is a small, fast cache in the CPU that stores recent translations of virtual memory
addresses to physical memory addresses.
Purpose:
Speed Up Address Translation: The TLB reduces the time taken to translate virtual
addresses to physical addresses by caching recent translations.
Enhance Performance: By quickly providing the physical address for frequently
accessed memory locations, the TLB minimizes the need to repeatedly access the page
table, thus speeding up memory access and improving overall system performance.
What is Fragmentation?
Explain the arguments for and against having a larger page size.
Large Page Size: Faster, less overhead, good for big data, but wastes some memory.
Small Page Size: Less waste, flexible for varied usage, but slower due to more overhead.
Dynamic memory allocation involves managing the allocation and deallocation of memory for
processes. The OS allocates memory from the system's physical memory or swap space, using
paging or segmentation techniques. Memory allocation strategies like first fit or best fit are used
to efficiently allocate memory blocks. The OS handles fragmentation to optimize memory usage
and may employ techniques like compaction or paging to manage memory fragmentation. Proper
memory deallocation ensures that memory is released for reuse, preventing memory leaks and
maintaining system stability.
Temporal locality: This refers to the principle that if a memory location is accessed, it is
likely to be accessed again in the near future. Programs often exhibit temporal locality
when accessing data or instructions repeatedly within a short time frame, leveraging
caching mechanisms to improve performance.
Spatial locality: This principle suggests that if a memory location is accessed, nearby
memory locations are also likely to be accessed soon. Spatial locality occurs when
programs access contiguous memory locations or nearby addresses in memory, benefiting
from caching and prefetching strategies to optimize data retrieval.
Math: Given a logical address of 16 pages of 2048 words each, mapped onto physical memory
of 64 frames:
a) How many bits are there in the logical address?
Virtual memory paging is used for memory management to provide an abstraction that allows
programs to use more memory than is physically available. It enables efficient use of physical
memory by loading only the necessary parts of a program into memory, reducing fragmentation,
and isolating processes for security and stability. This abstraction also simplifies the
programming model by allowing each process to have its own virtual address space.
Address space:
Address space refers to the range of memory addresses that a process can use. Each process in a
system has its own virtual address space, which is independent of the physical memory layout.
This space includes program code, data, and stack segments, and it allows processes to execute
and store data as if they have access to a contiguous block of memory, even though the physical
memory may be fragmented or shared among multiple processes.
Logical address: Addresses used by a process to access memory, generated by the CPU. They
are virtual addresses mapped to physical addresses by the memory management unit (MMU)
during execution.
Physical address: Actual addresses in the physical memory hardware where data and
instructions are stored. The MMU translates logical addresses to physical addresses, ensuring
processes access the correct locations in physical memory.
•Estimate by …
–logging page use on previous runs of process
Now for the further page reference string —> 0 Page fault because they are already available
in the memory.
Optimal page replacement is perfect, but not possible in practice as the operating system
cannot know future requests. The use of Optimal Page replacement is to set up a benchmark so
that other replacement algorithms can be analyzed against it.
4.referenced, modified
•NRU removes page at random
–from lowest numbered non empty class
•Disadvantage
–page in memory the longest may be often used
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page
faults
0 is already their so–> 0 page fault
when 3 comes it will take place of 0 because it is most recently used —>1 Page fault
when 0 comes it will take place of 3 —>1 Page fault
when 4 comes it will take place of 0 —>1 Page fault
2 is already in memory so —> 0 Page fault
when 3 comes it will take place of 2 —>1 Page fault
when 0 comes it will take place of 3 —>1 Page fault
when 3 comes it will take place of 0 —>1 Page fault
when 2 comes it will take place of 3 —>1 Page fault
when 3 comes it will take place of 2 —>1 Page fault
NRU is a simple page replacement algorithm that classifies pages into four categories based on
their recent access history:
Working:
Periodically, the operating system clears the reference bits (used to track accesses) for all
pages.
As pages are accessed, their corresponding reference bit is set.
When a page needs to be replaced, the OS selects a page from the lowest numbered non-
empty class (preferably from Class 0, then Class 1, then Class 2, and finally from Class
3).
Advantages:
Simple to implement.
Avoids excessive overhead of tracking exact access times.
Disadvantages:
May not always make the best decision since it only uses a basic classification of access
patterns.
Doesn't distinguish between pages accessed once versus pages accessed frequently.
LRU is based on the idea that pages that have not been used for the longest time are least likely
to be used in the near future.
Working:
The OS keeps track of when each page was last accessed (using timestamps or counters).
When a page needs to be replaced, the OS selects the page that hasn't been accessed for
the longest time (the least recently used page).
Implementation Techniques:
Counters: Each page has a counter; when accessed, the counter is updated.
Stacks: Maintain pages in a stack or queue ordered by access time, with the least recently
used at one end.
Clock Algorithms: Uses a circular list and a hand that points to the oldest page not
recently used.
Advantages:
Often performs well in practice because it tends to keep pages that will be used again
soon in memory.
Can be implemented efficiently with various data structures.
Disadvantages:
Requires additional overhead to track and update access times, especially in systems with
large amounts of memory.
Some implementations may struggle with accurately identifying the least recently used
page in highly dynamic systems.
Math: A computer has four frames. The time of loading, time of access, and the R and M bits
for each pages are as shown below (the times are in clock ticks):
1. TLB (Translation Lookaside Buffer): Use a TLB to cache recent translations of virtual
addresses to physical addresses, reducing the need to access the page table for every
memory reference.
2. Hierarchical (Multilevel) Page Tables: Utilize multilevel page tables to reduce the size
of each table, minimizing the memory overhead and speeding up page table lookups.
3. Large Pages: Use larger page sizes to reduce the number of page table entries and the
overhead of managing them, improving performance for large memory applications.
4. Page Table Caching: Implement hardware or software mechanisms to cache parts of the
page table, speeding up address translation.
5. Efficient Page Replacement Algorithms: Use efficient page replacement algorithms
(e.g., LRU, FIFO) to minimize page faults and ensure that the most frequently accessed
pages remain in memory.
Reading: Retrieving data from a file into memory for processing or display.
Seeking: Moving the current position within a file, enabling random access.
Deleting: Removing a file from the file system, freeing allocated space.
Name: The identifier used to access the file within the file system.
Type: Indicates the nature of the file (e.g., text, executable, directory).
Size: Specifies the amount of storage space occupied by the file's data.
Location: Records the physical location of the file within the storage device.
Permissions: Defines access rights for users and groups (e.g., read, write, execute).
Timestamps: Track the creation, modification, and access times of the file.
Owner: Identifies the user who owns the file, with associated security attributes.
• Many important applications need to store more information then have in virtual address
space of a process
• The information must survive the termination of the process using it.
• Multiple processes must be able to access the information concurrently.
• Disks are used to store files
• Information is stored in blocks on the disks
• Can read and write blocks
• Use file system as an abstraction to deal with accessing the information kept in blocks on
a disk
• Files are created by a process
• Thousands of them on a disk
• Managed by the OS
• OS structures them, names them, protects them
• Two ways of looking at file system
• User-how do we name a file, protect it, organize the files
• Implementation-how are they organized on a disk
• Start with user, then go to implementer
• The user point of view
• Naming
• Structure
• Directories
What is Directories?
• Files which are used to organize a collection of files
• Also called folders in weird OS’s
What is Single Level Directory Systems?
Figure : Linked list allocation using a file allocation table in main memory.
• The bad-table becomes really big
• E.g 200 GB disk with 1 KB blocks needs a 600 MB table
• Growth of the table size is linear with the growth of the disk size
What is I-nodes ?
• Keep data structure in memory only for active files
• Data structure lists disk addresses of the blocks and attributes of the files
• K active files, N blocks per file => k*n blocks max!!
• Solves the growth problem
• How big is N?
• Solution: Last entry in table points to disk block which contains pointers to other disk
blocks
What is Journaling File Systems?
A journaling file system maintains consistency by recording changes in a log (journal) before
committing them to the main file system structures. After a crash, the system can recover by
replaying the journal, ensuring that incomplete transactions are either completed or reverted,
maintaining file system integrity and preventing data loss.
Want to guard against lost files when there are crashes. Consider what happens when a file has to
be removed.
• Remove the file from its directory.
• Release the i-node to the pool of free i-nodes.
• Return all the disk blocks to the pool of free disk blocks
• If there is a crash somewhere in this process, have a mess.
• Keep a journal (i,.e. list) of actions before you take them, write journal to disk, then
perform actions. Can recover from a crash!
• Need to make operations idempotent. Must arrange data structures to do so.
• Mark block n as free is an idempotent operation.
• Adding freed blocks to the end of a list is not idempotent
• NTFS (Windows) and Linux use journaling
What is Hard link and soft link?
A hard link is a directory entry that points directly to the data blocks of a file, sharing the same
inode as the original file. It acts as a duplicate of the original file, maintaining the same file
content even if the original is deleted.
A soft link (symbolic link) is a special file that points to another file by its path name. It creates
a new file that references the target file's pathname, enabling indirect access. If the original file is
deleted, the symbolic link becomes invalid ("broken").
Describe the different ways of keeping track of free blocks in file systems
1. Bitmaps: Use a bitmap where each bit represents the allocation status of a block.
2. Linked lists: Maintain linked lists of free blocks, with each free block containing a
pointer to the next free block.
3. Counting: Use a count of free blocks maintained by the file system, which is updated as
blocks are allocated or deallocated.
4. Grouping: Organize blocks into groups or clusters, with each group having its own
bitmap or linked list to manage free blocks, optimizing access and management.
Write down 3 advantages and 3 disadvantages of a large block size in the file system.
1. Reduced Metadata Overhead: Larger blocks reduce the number of metadata entries
needed to track allocated blocks, leading to lower overhead in terms of storage and
processing.
2. Improved Sequential Access: Larger blocks facilitate efficient sequential access, as more
data can be read or written in a single operation, reducing the number of disk seeks and
enhancing throughput.
3. Reduced Fragmentation: Larger blocks can reduce internal fragmentation, where
allocated space within a block is not fully utilized, by aligning more closely with the size
of typical data operations.
1. Increased Wastage: Larger blocks may lead to increased external fragmentation, where
small gaps of unused space exist between allocated blocks, reducing overall storage
efficiency.
2. Poor Space Utilization: Large blocks may allocate more space than necessary for small
files or data structures, potentially wasting disk space and reducing storage capacity.
3. Slower Random Access: Larger block sizes can lead to inefficiencies in random access
scenarios, where only small portions of data are needed, as the entire block must be read
or written, increasing latency and reducing responsiveness.
How the logical dumping algorithm works in short?
The logical dumping algorithm involves creating a backup or snapshot of the file system's logical
structure and data without necessarily replicating the physical layout of the storage medium. It
typically works by traversing the file system hierarchy, copying files and directories, preserving
metadata (such as file attributes and permissions), and optionally compressing the data for
storage efficiency. This approach ensures that the backup captures the organization and content
of the file system, making it useful for disaster recovery and data migration purposes.
Simple and compatible: Works on most operating systems (Windows, Mac, Linux).
Limited size: Not ideal for large files (max 4GB with FAT32).
Prone to fragmentation: Can become slow over time as files get scattered across the
disk.
In a nutshell: FAT: Simple and universal, but limited in size and performance. NTFS: Powerful
and secure, but mainly for Windows. ext4: Efficient and scalable, but primarily for Linux.
Chapter: Disk Management.
Explain disk arm scheduling algorithms (considerations and types like SSF, elevator)
Disk arm scheduling algorithms determine the order in which disk I/O requests are serviced to
minimize seek time and maximize throughput.
Considerations for selecting a good algorithm include:
Seek time (the time to move the arm to the proper cylinder).
Rotational delay (how long for the proper sector to appear under the reading head).
Actual data transfer time
Requests are serviced in the order they arrive. Simple but can lead to high average seek
times, especially if there are requests scattered across the disk.
Services the request that requires the least movement of the disk arm first. Minimizes
seek time but may result in starvation for some requests if there are constantly arriving
requests close to the arm.
The disk arm starts at one end of the disk and moves toward the other end, servicing
requests along the way. Upon reaching the end, it reverses direction. This reduces
average seek time but can lead to delays for requests at the far end of the disk.
RAID (Redundant Array of Independent Disks) is a data storage technology that combines
multiple physical disk drives into a single logical unit to improve performance, redundancy, or
both.
RAID Levels:
The operating system controls all I/O devices (disks, clocks, keyboards, displays, network
interfaces), providing a device-independent interface between the devices and the rest of the
system. It issues commands, catches interrupts, handles errors, and ensures consistency across
different devices. Without OS-managed I/O, each application would need to handle device
programming individually.
• Block devices
• Stores information in fixed-size blocks, each one with its own address
• Character devices
What is Interrupts?
• When an I/O device has finished the work given to it, it causes an interrupt.
• It does this by asserting a signal on a bus line that it has been assigned.
• This signal is detected by the interrupt controller chip, which then decides what to do.
The interrupt signal causes the CPU to stop what it is doing and start doing something else.
A precise interrupt leaves the machine in a well-defined state with the following properties:
is a method of controlling input/output devices by mapping their control registers and data
buffers into the system's memory address space. This allows the CPU to interact with devices
using standard memory instructions, treating device registers as if they were memory locations.
Memory-Mapped I/O
Device Controllers:
o Have registers to command actions.
o Contain data buffers for reading/writing by programs or the OS.
Approaches to Manage Space:
1. Separate address spaces for memory and I/O.
2. Map all control registers into the memory space (Memory-Mapped I/O).
Memory-Mapped I/O
b) map all the control registers into the memory space – Memory-Mapped I/O
Modern personal computers is to have a dedicated highspeed memory bus, tailored to optimize
memory performance
What is Direct Memory Access (DMA)?
Direct Memory Access (DMA) is a system feature that allows certain hardware components to
access the main system memory (RAM) independently of the CPU. DMA allows the CPU to
perform other tasks while the data transfer occurs, improving overall system efficiency.
How it works:
1. DMA Controller: A dedicated DMA controller takes over the data transfer process.
2. Initiation: The CPU initiates the transfer by providing the DMA controller with the
source and destination addresses and the amount of data to transfer.
3. Data Transfer: The DMA controller manages the data transfer directly between the I/O
device and memory, bypassing the CPU.
4. Completion: Once the transfer is complete, the DMA controller signals the CPU with an
interrupt.
Managing I/O access for CPU and loading data directly into memory
1. Device Independence:
o Programs should access any I/O device without needing to specify the device in
advance.
o Example: Reading a file should work the same on a hard disk, DVD, or USB
stick.
2. Uniform Naming:
o File or device names should be simple (e.g., a string or integer) and not device-
dependent.
o Example: A USB stick can be mounted as /usr/ast/backup.
3. Error Handling:
o Errors should be managed as close to the hardware level as possible.
o Example: A controller should attempt to correct read errors automatically.
1) Programmed I/O
Definition:
o CPU handles all aspects of I/O operations directly.
Characteristics:
o CPU-intensive: The CPU is fully engaged until the I/O operation completes.
o Busy waiting / polling: CPU repeatedly checks the status of the I/O device.
Considerations:
o Suitable when waiting periods are short or when the CPU has no other tasks.
o In complex systems, CPU resources are often needed for other processes, making
programmed I/O less efficient.
First the data are copied to the kernel. Then the operating system enters a tight loop, outputting
the characters one at a time.
Interrupt-driven I/O allows the CPU to multitask while waiting for I/O operations:
CPU Multitasking: Instead of waiting, the CPU switches to handle other processes until
an interrupt signals that the I/O operation is complete.
Efficiency Consideration: However, frequent interrupts during each I/O request can
potentially waste CPU time.
What is I/O Using DMA?
1. Save Registers: The CPU preserves any registers not already saved by the interrupt
hardware, including the Program Status Word (PSW).
2. Context Setup: This prepares the environment for the interrupt service routine (ISR). It
might involve setting up the Translation Lookaside Buffer (TLB), Memory Management
Unit (MMU), and a page table.
3. Interrupt Stack: A separate stack is established specifically for the ISR.
4. Interrupt Acknowledgement: The CPU signals the interrupt controller (or directly re-
enables interrupts if there's no central controller) that the interrupt is recognized.
5. Register Backup: The saved registers (potentially from a stack) are copied to the process
table for later use.
6. ISR Execution: The interrupt service routine runs, typically extracting information from
the device's registers that triggered the interrupt.
7. Process Selection: The CPU determines which process to run next. An interrupt might
make a high-priority process ready, prompting the CPU to switch to it.
8. MMU Setup (Next Process): The MMU context for the process chosen to run next is
configured, potentially involving TLB setup.
9. Register Load (Next Process): The CPU loads the registers of the newly chosen process,
including the PSW.
10. Process Execution: Control is transferred to the chosen process, and it starts running.