📝 Input and Output system in Linux (9 MCQs)
Linux I/O Architecture and Device Abstraction
The Linux I/O system manages communication between applications, kernel subsystems, and physical devices. It combines system calls, the VFS, device drivers, interrupt handling, DMA, and device-specific interfaces. Common abstractions allow programs to access files, terminals, storage devices, and network connections without directly programming the underlying controller hardware.
Why Device Differences Need Layered Management
Linux supports devices with different transfer sizes, access patterns, speeds, and control mechanisms. A single application-level interface cannot describe every hardware detail. The kernel separates device-independent services from driver-specific operations, enabling shared request handling while allowing individual drivers to manage controller registers, interrupts, and transfer requirements.
System Calls, Drivers and I/O Completion
An application issues an operation such as open, read, or write. The kernel validates the request and routes it to the relevant subsystem. A driver prepares the device operation using registers, buffers, or DMA. Completion may be reported through interrupts, after which the kernel updates request state and returns a result.
Example of Reading from a Linux Device
A process reads 1024 bytes from a device file. The kernel locates the registered character or block device interface and invokes its file operations. The driver coordinates the hardware transfer or returns available buffered data, then reports the number of bytes transferred or an appropriate error.
Performance, Device Types and Protection
Linux I/O combines buffering, caching, scheduling, interrupts, and DMA to improve throughput and reduce unnecessary CPU work. Block and character devices provide different access models. Device permissions restrict unauthorised use, while driver errors and hardware faults must be handled carefully to prevent corruption, service disruption, or kernel instability.
Misconceptions About Linux I/O
'Every device is accessed through the same driver interface' ignores subsystem-specific operations. 'DMA means the CPU never participates' overlooks request setup and completion handling. 'A successful write always means data is physically stored' ignores buffering and delayed writeback.
Exam Focus: Linux I/O Request Processing
Trace a read or write from a system call through the relevant kernel subsystem and device driver. Distinguish block devices from character devices and explain interrupts, DMA, buffering, and caching. Questions may examine device files, driver operations, permissions, and the difference between completed writes and durable storage.
Key Terms of Linux I/O
- Device driver - Kernel software controlling hardware.
- DMA - Hardware-assisted memory transfer.
- Interrupt - Notification of a device event.
- Buffer - Temporary storage during data transfer.
- Device file - Filesystem interface to a device.
📝 All Input and Output system in Linux MCQs
Q1. What is the primary purpose of the page cache in Linux I/O?
📖 Explanation: The page cache is a memory area that keeps full pages of file data, allowing subsequent reads to be served from RAM instead of disk. Option B describes this exactly. Option A confuses the cache with inode metadata, which is not cached here. Option C refers to networking, unrelated to file caching. Option D describes CPU scheduling, which the page cache does not affect. By keeping pages in memory, the system reduces I/O latency and improves overall performance.
Q2. How does the virtual memory system interact with the page cache when a process reads a file?
📖 Explanation: When a file is read, the kernel first loads the needed page into the page cache. The virtual memory subsystem then creates a mapping so the process can access that cached page via its address space. Option C captures this two‑step interaction. Option A is false because writes go through the cache, not directly to disk. Option B misstates the role of registers. Option D is incorrect; pages remain cached for reuse.
Q3. A web server reads a large static file repeatedly. Which configuration change most directly reduces disk I/O for subsequent reads?
📖 Explanation: Expanding the page cache gives the kernel more RAM to retain file pages, so later reads can be satisfied from memory without hitting the disk. This directly cuts I/O. Disabling NFS (option B) is irrelevant if the file is local. Changing permissions (option C) does not affect caching. Raising CPU speed (option D) may speed processing but does not eliminate disk accesses. Hence, option A is the correct performance‑focused tweak.
Q4. When a client accesses a file over NFS, which mechanism allows cached network data to be reused without re‑fetching from the server?
📖 Explanation: NFS data can be stored in the same page cache used for local files; pages that contain networked file data remain in RAM and can be reused, avoiding another network round‑trip. Option C describes this behavior. Inode revalidation (option A) checks metadata, not data reuse. Write‑through caching (option B) forces writes to disk immediately, not relevant for reads. Swap space (option D) is for paging out memory, not caching remote file data.
Q5. A program calls mmap() to map a 4 KB file region. Which sequence correctly describes what happens inside the kernel?
📖 Explanation: When mmap() is used, the kernel first ensures a page exists in the page cache, copies the file's contents if needed, then updates the process's page tables to point to that page, and finally records the region in a vm_area_struct node linked in a balanced tree. This full sequence matches option A. Direct disk writes (option B) ignore caching, which is not how mmap works. Option C describes network I/O, unrelated to memory mapping. Option D would remove the mapping, not create it.
Q6. Why are vm_area_struct objects linked in a balanced binary tree rather than a simple list?
📖 Explanation: A balanced binary tree provides logarithmic search time, so the kernel can quickly locate the region that contains a given virtual address during a page fault. This efficiency is essential for performance. Option B captures this reason. Option A is inaccurate; locking is still required. Option C confuses the structure with data storage, which it does not do. Option D is unrelated; swapping concerns pages, not the organization of vm_area_struct nodes.
Q7. A system under memory pressure decides to swap out pages belonging to a process's anonymous region. Which characteristic of those pages makes them eligible for swapping?
📖 Explanation: Anonymous pages have no backing store on disk; when they are not referenced, the kernel can write their contents to swap space to free RAM. This matches option C. Pages mapped to a file (option A) can be dropped because the file provides the data. Dirty pages (option B) must be written back before swapping, not a direct eligibility criterion. Kernel page tables (option D) are not swapped; they remain in memory.
Q8. When defining a new memory region for a process, why must the region be page‑aligned?
📖 Explanation: Memory management hardware works with pages, typically 4 KB in size. Page tables store entries that describe entire pages, so any region must start at a page boundary to be represented correctly. Option B states this requirement. The other options describe unrelated effects: CPU alignment is finer than page size (option A), network latency (option C) and disk scheduling (option D) are not determined by alignment of virtual regions.
Q9. If a process reads a file page that is not present in the page cache, what is the immediate effect on the page cache?
📖 Explanation: When a miss occurs, the kernel brings the missing page into the page cache by allocating a fresh page frame and reading the data from storage. This is exactly what option A describes. Clearing all pages (option B) would be wasteful and never happens on a miss. Sending a network signal (option C) is unrelated unless the file is remote, which is not implied. Disabling reads (option D) would halt I/O, which is not the kernel's behavior.