0% found this document useful (0 votes)
24 views68 pages

OS Notes

An operating system (OS) is system software that manages hardware resources and provides an interface for users and applications. Key functions include resource management, process management, and providing user interfaces, while various scheduling algorithms determine process execution order. Concepts such as processes, threads, inter-process communication, and synchronization mechanisms like semaphores and message passing are essential for efficient OS operation.

Uploaded by

foorwebiosapp
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)
24 views68 pages

OS Notes

An operating system (OS) is system software that manages hardware resources and provides an interface for users and applications. Key functions include resource management, process management, and providing user interfaces, while various scheduling algorithms determine process execution order. Concepts such as processes, threads, inter-process communication, and synchronization mechanisms like semaphores and message passing are essential for efficient OS operation.

Uploaded by

foorwebiosapp
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
You are on page 1/ 68

Chapter: Operating System Basics

What is OS? What purposes of OS?

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

What are the two main functions of an operating 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)

Describe the system call for process management.


A system call for process management typically involves functions provided by the operating
system to create, control, and manipulate processes.

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.

Waiting for Processes:

 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.

What is process table entry?

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:

 Industrial control systems: Factory robots and assembly lines.


 Medical devices: Pacemakers and insulin pumps.
 Flight control systems: Critical for safety.

Differences from general-purpose OSes (Windows, macOS):

 Guaranteed response: RTOS prioritizes tasks to meet deadlines; general-purpose OSes


don't.
 Speed and efficiency: RTOSes are smaller and faster, focusing on essential functions.
 Limited features: RTOSes lack non-essential features like web browsers or games.
Explain the concept of virtual machines. How does a hypervisor work?

A virtual machine (VM) is a software emulation of a physical computer, running an operating


system and applications just like a real computer.

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.

What is parallel and distributed OS?

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.

Distributed Operating System: A distributed OS manages a group of independent computers


and makes them appear to the user as a single coherent system. It coordinates and controls the
resources of the distributed network, ensuring tasks are executed efficiently across multiple
machines.
Chapter: Process

What is the Process Model?

a) Multiprogramming of four programs


b) Conceptual model of 4 independent, sequential processes
c) Only one program active at any instant

What are the different steps of implementing a process?


Process Creation:
System initialization( Load Program into Memory)
Create Process Control Block (PCB)
Allocate Resources
Process Scheduling:
Place in Ready Queue
Select Process for Execution
Process Execution:
Dispatching
Context Switching
Process Suspension and Resumption:
Block State
Wake Up
Process Termination:
Release Resources
Exit can be normal
Exit can be fatal
Can be killed by other process
Remove from System

What is context switch of a process?


A process context switch is the procedure of saving the state of a currently running process and
loading the state of the next process to be executed by the CPU.
When doing a context switch the kernel save enough information like registers, program counter,
and other process-specific data.
When the kernel decide that it should execute another process it does a context switch so that the
system execute the context of other process. This allows multiple processes to share a single
CPU efficiently by switching between them.

What are the different process states?

1) Process block for input


2) Scheduler pick another process
3) Scheduler pick this process
4) Input become available
What is PCB?
PCB stands for Process Control Block. It is a data structure used by the OS to store all the
information about a process. This includes process state, program counter, CPU registers,
memory management information, accounting information, and I/O status information. The PCB
is essential for process management and allows the OS to switch between processes efficiently.

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.

What is the Thread Model?

(a) Three processes each with one thread (b) One process with three threads
The Thread Model-2

Each thread has its own stack

Thread Usage (1)

A word processor with three threads

How to Implementing Threads in User Space?


Advantage
• Fast switching among threads
Disadvantage
• when one thread blocks, the kernel blocks the entire process

How to implement Threads in the Kernel?


A threads package managed by the kernel

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.

Differentiate between preemptive and non-preemptive scheduling

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.

Non-Preemptive Scheduling: Once a process starts executing, it runs to completion without


being interrupted, leading to potentially lower responsiveness for higher priority tasks.

Describe all process scheduling algorithms (round robin, shortest job first, guaranteed
scheduling, lottery, etc.)

First-Come, First-Served (FCFS):

 Description: Processes are executed in the order they arrive.


 Pros: Simple and easy to implement.
 Cons: Can lead to long waiting times, especially for shorter processes

 Consider 4 jobs with run time of a, b, c and d respectively.


o The mean turnaround time is (4a +3b +2c + d)/4

Shortest Job First (SJF):

 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.

 Consider 4 jobs with run time of a, b, c and d respectively.


o The mean turnaround time is (4b +3c +2d + a)/4

Round Robin Scheduling


• Simplest, fairest and most widely used
• Each process is assigned a quantum (time interval) which it is allowed to run
• If the process is still running at the end of quantum, the CPU is preempted and given to
another process
• Also the CPU switches when a process blocks
• All Processes are equally important

(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

A scheduling algorithm with four priority classes


What is Inter-process Communication (IPC)?
• Processes frequently need to communicate with other processes.
• Example
• In a shell pipeline, the output of the first process must be passed to the second
process
• Generally shared memory is used to establish the connection among processes.
• This memory must be shared carefully to avoid inconsistency
What is Race Condition (in IPC)?
The situation where 2 or more processes are reading or writing some shared data is called race
condition.

Two processes want to access shared memory at same time


What is Critical Region/ Critical Section?
The part of the program where the shared memory is accessed is called the critical region
Four conditions to provide mutual exclusion:
 No two processes simultaneously in critical region
 No assumptions made about speeds or numbers of CPUs
 No process running outside its critical region may block another process
 No process must wait forever to enter its critical region

Mutual exclusion using critical regions


How to Manage Race Condition?
• Mutual Exclusion with Busy Waiting
• Strict Alternation
• Peterson’s Solution
• Mutual Exclusion without Busy Waiting
• Sleep and wakeup
• Semaphore
• Message Passing
• Monitor
• Barrier
• Mutexes
What is Sleep and Wakeup ?
Producer-Consumer Problem
-2 processes share a common buffer with fixed size
-Producer puts data in the buffer
-Consumer takes data from the buffer
-Producer goes to sleep when buffer is full
-Consumer goes to sleep when buffer is empty
-Both producer and consumer may go to sleep!

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 Message passing?


Message passing offers an efficient way to achieve mutual exclusion without busy waiting,
allowing processes to coordinate access to critical sections and improve overall system
performance.

"Message Passing" is a synchronization mechanism used in concurrent programming to achieve


mutual exclusion and coordinate the activities of processes or threads without the need for busy
waiting. In the context of mutual exclusion, message passing allows processes to communicate
and synchronize their actions by sending and receiving messages, thus avoiding the
inefficiencies and resource consumption associated with busy waiting.
Two methods
— send: send (destination, &message)
— receive: receive (source, &message)
Methods are system calls
Challenges:
— Packet loss
— Duplicate packets
— Authentication
What is Barrier?

-all process approaching a barrier


-all process but one blocked at barrier (hen the last one has not arrived yet)
- Last process arrived all are let through

Why is mutual exclusion necessary in critical regions?


Mutual exclusion is necessary in critical regions to prevent race conditions and ensure data
consistency. When multiple processes or threads access shared resources simultaneously without
mutual exclusion, they can interfere with each other, leading to unpredictable results and
corrupted data. By enforcing mutual exclusion, only one process or thread can enter the critical
region at a time, ensuring that operations on shared resources are performed safely and correctly.

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.

Basic Operations on Mutexes

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.

What is Dining philosophers problem?


The dining philosophers problem is a classic synchronization problem used to illustrate the
challenges of avoiding deadlock, ensuring mutual exclusion, and preventing resource starvation
in concurrent systems.

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 are Preemptive resource and non-preemptive resource?

a preemptive resource can be forcibly taken from a process if needed

A non-preemptive resource must be voluntarily released by the process holding it,

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.

What are the conditions of deadlock?


Four Conditions for Deadlock:
1. Mutual exclusion condition — Resources are NOT sharable .each resource assigned to 1
process or is available.
2. Hold and wait condition — process holding resources can request additional
3. No preemption condition — previously granted resources cannot forcibly taken away
4. Circular wait condition — must be a circular chain of 2 or more processes — each is waiting
for resource held by next member of the chain

What are the Strategy to deal with Deadlock?


1) Just ignore the problem
Ostrich algorithm : if deadlock occurs very rare or cost of prevention is very high
2) Detection and recovery
3) Prevention
4) Dynamic avoidance

What arte the Recovery Strategies for Deadlock?

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:

o If a cycle is found, kill one process in the cycle.


o If the cycle persists, repeat the process until the deadlock is resolved.

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.

How to prevent Deadlock ?


Avoid Circular Wait: Impose a strict ordering on resource acquisition to prevent circular wait.

Hold and Wait Prevention: Require processes to request all required resources at once, and block
the process until all resources can be allocated simultaneously.

No Preemption: Implement preemption by forcibly taking resources from other processes if


necessary.

Mutual Exclusion: Ensure that some resources are only allocated in a way that does not require
mutual exclusion.

Deadlock Avoidance Algorithms: Use algorithms such as Banker's algorithm to dynamically


examine resource-allocation states and ensure a safe state.

How to avoid Deadlock? (Deadlock avoidance/Dynamic avoidance)


Carefully analyze each resource request to see if it can safely granted. Bankers algorithm bt
Dijkstra mat do it.
Say total number of available resources are 10 .
State (a): used 3+2+2=7
Free= 10-7=3 [safe state]

State (b): used 3+4+2=7


Free= 10-9=1 [Not safe state]
……………..

How does the resource allocation graph find deadlock?

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.

What is Two-Phase Locking?

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.

How does the 2-phase locking system prevent deadlock?

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.

Solution of Starvation: To address starvation, implementing a first-come, first-served policy


ensures that all processes eventually receive their required resources without any process being
indefinitely postponed due to its lengthier execution requirements.

How does starvation help to solve deadlock?


Starvation can help solve deadlock by ensuring that processes periodically release resources they
hold, preventing indefinite resource blocking. This continuous resource turnover reduces the
likelihood of resource contention reaching deadlock conditions. By promoting fairness in
resource allocation, starvation indirectly mitigates the conditions that lead to deadlock,
improving system responsiveness and stability.

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

What type of memory the Programmer want?


Memory that should be:
-Fast
-Large
-non volatile

What is Basic Memory Management Mono-programming without Swapping or Paging?

What is Multiprogramming with Fixed Partitions?

Basic Memory Management

Monoprogramming without Swapping or Paging


What is Multiprogramming with Fixed Partitions?

Fixed memory partitions


– (a)separate input queues for each partition
– (b)single input queue

Explain swapping (fixed and non-fixed partition)

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.

Non-Fixed (Dynamic) Partition Swapping

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.

What is Memory Compaction?

Memory compaction is a technique used to eliminate fragmentation in physical memory.


Compaction rearranges the memory contents to combine these gaps into a single contiguous
block of free memory. This process can help optimize memory usage and improve system
performance by ensuring that larger blocks of memory are available for allocation.

Fragmentation occurs when memory is allocated and deallocated in an inefficient manner,


leaving small, unusable gaps between allocated memory blocks.
What is Virtual Memory?

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).

Function: Frees up physical memory by temporarily transferring inactive or less-used data to


disk.
What is Memory Management with Bit Maps?

Part of memory with 5 processes, 3 holes


–tick marks show allocation units
–shaded regions are free
•Corresponding bit map

•Same information as a list


While bitmap memory management offers simplicity and efficiency for managing fixed-size
memory allocations, it comes with challenges related to memory overhead, scalability with large
memory sizes, and potential fragmentation issues in actual memory usage.

What is Memory Management with Linked Lists?

Four neighbor combinations for the terminating process X

What is Virtual memory ?


• The basic idea behind virtual memory is that the combined size of the program may
exceed the amount of physical memory available for it.
• The OS keeps part of the program currently in use in main memory, and the rest on the
disk.
• For example
– A 16MB program can run on a 4MB memory
• Virtual memory also allows many programs in memory at once.
• Most virtual memory systems use a technique called paging
What is Paging?
Most virtual memory system use a technique called paging.
Paging allows the system to manage memory in fixed-size blocks, facilitating efficient memory
use and simplifying the handling of virtual and physical addresses.

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

Disk main memory

What is Virtual Memory Paging?


Virtual memory paging is a memory management technique where the operating system uses
disk storage as an extension of RAM. It allows programs to use more memory than physically
available by temporarily transferring data between RAM and disk. Pages of memory are
swapped in and out of RAM based on demand, optimizing memory usage and allowing multiple
programs to run concurrently without requiring all data to fit in physical memory at once.

The position and function of the MMU

The relation between virtual addresses and physical memory addresses given by page table
Internal operation of MMU with 16 4 KB pages

What is Translation Lookaside Buffer (TLB)?

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?

Fragmentation in an OS is the inefficient use of memory or disk space due to non-contiguous


allocation, resulting in wasted space.

What is External fragmentation?


Total memory space is enough to satisfy a request or to reside a process in it, but it is not
contiguous, so it cannot be used.
What is Internal fragmentation?
Memory block assigned to process is bigger. Some portion of memory is left unused, as it cannot
be used by another process.

What is valid bit?


When this bit is set to ‘valid’ this value indicate that the associated page is both legal and in
memory. If the bit is set ‘invalid’ this means this page is either NOT valid (no logical address for
this process) or is valid but currently on the disk (not in main memory)

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.

Describe memory management for dynamic allocation

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.

Define temporal locality and spatial locality

 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?

b) How many bits are there in the physical address?

Why virtual memory paging used for memory management?

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.

Explain logical address and physical address.

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.

Justify the memory management of a computer system.

Here's why memory management is crucial:

 Efficient Utilization: Limited physical memory needs to be divided efficiently among


running programs.
 Isolation: Protects programs from corrupting each other's memory.
 Virtualization: Allows programs to use more memory than physically available (virtual
memory).

What is Page Replacement Algorithms?


Page replacement algorithms in an OS decide which memory pages to swap out, or replace,
when a new page needs to be loaded into memory but the memory is already full.

•Page fault forces choice


–which page must be removed

–make room for incoming page


•Modified page must first be saved
–unmodified just overwritten

•Better not to choose an often used page


–will probably need to be brought back in soon

What is Optimal Page Replacement Algorithm?

•Replace page needed at the farthest point in future


–Optimal but unrealizable

•Estimate by …
–logging page use on previous runs of process

–although this is impractical

Example-2: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page


frame. Find number of page fault.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page
faults
0 is already there so —> 0 Page fault. when 3 came it will take the place of 7 because it is not
used for the longest duration of time in the future.—>1 Page fault. 0 is already there so —> 0
Page fault. 4 will takes place of 1 —> 1 Page Fault.

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.

What is Not Recently Used Page Replacement Algorithm?

•Each page has Reference bit, Modified bit


–bits are set when page is referenced, modified

•Pages are classified


1.not referenced, not modified

2.not referenced, modified

3.referenced, not modified

4.referenced, modified
•NRU removes page at random
–from lowest numbered non empty class

What is FIFO Page Replacement Algorithm?


•Maintain a linked list of all pages
–in order they came into memory

•Page at beginning of list replaced

•Disadvantage
–page in memory the longest may be often used

What is Second Chance Page Replacement Algorithm?


Operation of a second chance
–pages sorted in FIFO order
–Page list if fault occurs at time 20, A has R bit set(numbers above pages are loading times)

What is The Clock Page Replacement Algorithm?


What is Most Recently Used (MRU)?
In this algorithm, page will be replaced which has been used recently. Belady’s anomaly can
occur in this algorithm.

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

What is NRU (Not Recently Used)?

NRU is a simple page replacement algorithm that classifies pages into four categories based on
their recent access history:

1. Class 0: Not referenced, not modified.


2. Class 1: Not referenced, modified.
3. Class 2: Referenced, not modified.
4. Class 3: Referenced, modified.

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.

What is LRU (Least Recently Used)?

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):

page Loader Last ref. R M


0 126 280 1 0
1 230 230 0 1
a) Which page 2 140 140 0 0 will NRU replace?
b) Which page 3 110 110 1 1 will FIFO replace?
c) Which page will LRU replace?
d) Which page will second chance replace?

What is Copy back?


In operating systems, "copy back" refers to a caching mechanism where data written to a cache is
marked as "dirty" and not immediately written back to the main memory. The data is eventually
written back to the main memory during specific events like cache eviction. This improves
performance by reducing the number of write operations to the slower main memory.

What is dirty bit?


A dirty bit in an OS indicates that a memory page has been modified and needs to be written to
disk before being replaced.
What is Multilevel page tables?
Multilevel Paging consists of two or more levels of page tables in a hierarchical manner. It is
also known as hierarchical paging. The entries of the level 1 page table are pointers to a level 2
page table and entries of the level 2 page tables are pointers to a level 3 page table and so on.

How Speeding up paging is possible?

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.

Chapter: File and File Systems


Describe various file operations

Opening: Initiating access to a file for reading, writing, or both.

Reading: Retrieving data from a file into memory for processing or display.

Writing: Storing data from memory into a file for persistence.

Seeking: Moving the current position within a file, enabling random access.

Closing: Ending access to a file, ensuring resources are released properly.

Deleting: Removing a file from the file system, freeing allocated space.

Renaming: Changing the name of a file within the file system.

Write down possible "file attributes".

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.

Attributes: Additional metadata like encryption status, compression, or archive flags.

What is File and File Systems?


A file is a named collection of data or information stored on a storage device, representing text,
programs, or media.
A file system is the method by which files are organized, stored, and accessed on storage
devices, managing file metadata, storage allocation, and retrieval operations efficiently.
Examples include NTFS on Windows, ext4 on Linux, and HFS+ on macOS.

• 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

How File Access become possible?


• Sequential access- read from the beginning, can’t skip around
• Corresponds to magnetic tape
• Random access- start where you want to start
• Came into play with disks
• Necessary for many applications, e.g. airline reservation system

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?

A single-level directory system containing four files.

What is Hierarchical Directory Systems?

What are Directory


Operations?
• Create creates directory
• Delete directory has to be empty to delete it
• Opendir Must be done before any operations on directory
• Closedir
• Readdir returns next entry in open directory
• Rename
• Link links file to another directory
• Unlink Gets rid of directory entry

What is System calls for managing directories (from Unix)?


• Readdir-reads next entry in open directory
• Rename
• Link-links file to path. File can appear in multiple directories!
• Unlink-what it sounds like. Only unlinks from pathname specified in call

How to implement file (File Implementation)?


• Files stored on disks. Disks broken up into one or more partitions, with separate fs on
each partition
• Sector 0 of disk is the Master Boot Record
• Used to boot the computer
• End of MBR has partition table. Has starting and ending addresses of each partition.
• One of the partitions is marked active in the master boot table
• Boot computer => BIOS reads/executes MBR
• MBR finds active partition and reads in first block (boot block)
• Program in boot block locates the OS for that partition and reads it in
• All partitions start with a boot block
What is A Possible File System Layout?

What File System Layout?


• Superblock contains info about the fs (e.g. type of fs, number of blocks, …)
• i-nodes contain info about files

How to Allocating Blocks to files?

• Most important implementation issue


• Methods
• Contiguous allocation
• Linked list allocation
• Linked list using table
• I-nodes

What are the approach for Allocating Blocks to files?

The approaches for allocating blocks to files in an OS include:

1. Contiguous Allocation: Allocates consecutive blocks to a file.


2. Linked Allocation: Each file block points to the next block.
3. Indexed Allocation: Uses an index block to keep track of all the blocks allocated to a
file.
What is Contiguous Allocation of file?

(a) Contiguous allocation of disk space for 7 files.


(b) The state of the disk after files D and F have been removed
The good :
• Easy to implement
• Read performance is great. Only need one seek to locate the first block in the file. The
rest is easy.
The bad-disk becomes fragmented over time:
• CD-ROM’s use contiguous allocation because the fs size is known in advance
• DVD’s are stored in a few consecutive 1 GB files because standard for DVD only allows
a 1 GB file max
What is Linked List Allocation?

Storing a file as a linked list of disk blocks:


The good
• Gets rid of fragmentation
The bad
• Random access is slow. Need to chase pointers to get to a block

Linked lists using a table in memory


• Put pointers in table in memory
• File Allocation Table (FAT)
• Windows
What is The Solution-Linked List Allocation Using a Table in Memory?

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.

Advantages of a Large Block Size:

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.

Disadvantages of a Large Block Size:

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.

How are disk quotas managed in a multi-user file system?


In a multi-user file system, disk quotas are managed by setting limits on the amount of disk space
each user or group can utilize. This is typically enforced by the operating system, tracking usage
per user or group. Administrators can define quotas, monitor usage, and enforce limits to ensure
fair resource allocation and prevent individual users from consuming excessive disk space,
which helps maintain system performance and availability. When a user exceeds their quota,
further disk space allocations are typically restricted until space is freed up or quotas are
adjusted.

Explain different file system structures like FAT, NTFS, ext4.

FAT (File Allocation Table):

 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.

NTFS (New Technology File System):

 Windows native: Designed for Windows operating systems.


 Advanced features: Supports large files, permissions, encryption, and journaling for
better recovery.
 Less compatible: Not readily writable on Mac by default.

ext4 (Fourth Extended File System):

 Linux favorite: Developed for Linux environments.


 Scalable and efficient: Handles large drives and files well, minimizes fragmentation.
 Limited compatibility: Not natively writable on Windows by default.

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

Also consider Fairness, Workload Consideration, Throughput Maximization

First-Come, First-Served (FCFS):

 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.

Shortest Seek Time First (SSTF):

 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.

SCAN (Elevator) Algorithm:

 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.

Explain the concept of RAID and its different levels.

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:

1. RAID 0: Striping without redundancy, improves performance but offers no data


protection.
2. RAID 1: Mirroring for redundancy, duplicates data across drives for fault tolerance.
3. RAID 5: Striping with distributed parity, balances performance and redundancy using
parity for fault tolerance.
4. RAID 10 (RAID 1+0): Combines mirroring and striping, offering high performance and
fault tolerance through duplication and striping.
Chapter: Input/Output Systems

What is I/O and OS?

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.

What are the types of I/O devices?

I/O devices can be roughly divided into two categories:

• Block devices

• Stores information in fixed-size blocks, each one with its own address

• All transfers are in units of one or more entire (consecutive) blocks

• Each block can be written or read independently

• Hard disks, Blu-ray discs, and USB sticks

• Character devices

• Delivers or accepts a stream of characters, without any block structure

• Not addressable and does not have any seek operation

• Printers, network interfaces, keyboards

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.

What is Precise Interrupts?

A precise interrupt leaves the machine in a well-defined state with the following properties:

1. The Program Counter (PC) is saved in a known location.


2. All instructions before the one indicated by the PC have completed.
3. No instructions beyond the one indicated by the PC have finished.
4. The execution state of the instruction indicated by the PC is known.

What is Memory-Mapped I/O ?

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

• Device controllers have registers – to command to perform actions

• Devices have data buffers – where programs or OS can read/write

• Two approaches to manage this space:

a) address spaces for memory and I/O are different

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

Regulating transfers to multiple devices, often concurrently


What is the Goals of I/O Software?

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.

What are the Types of I/O methods?


1. Programmed I/O
2. Interrupt-driven I/O
3. I/O using DMA

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.

What is Interrupt-Driven I/O?

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?

In DMA (Direct Memory Access):

 DMA Controller Management: Handles entire I/O requests independently.


 CPU Uninterrupted: CPU remains free from interruptions during I/O operations.
 Reduced Interrupts: Decreases the frequency of interrupts, improving system
efficiency.
 Speed Considerations: DMA controllers are generally slower than the main CPU.
 Waiting Time: If the CPU is idle, it might wait longer for DMA completion compared to
handling I/O on its own.

What is Interrupt Handling Process?

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.

What is I/O Software Layers?

What is Device drivers


Device drivers act as interpreters, allowing programs to interact with hardware using simple
commands (read, write, seek) while the driver translates them into the specific language the
device understands.

You might also like