🎓 BookMCQ
← Back to 18. The Linux System

📝 Block devices in The Linux System (9 MCQs)

Addressable Storage Devices in Linux

Linux block devices transfer data in addressable units called blocks and commonly support random access to logical storage locations. Hard disks, solid-state drives, and virtual disks are typical examples. The block layer provides request management between filesystems and device drivers, allowing storage operations to be queued, merged, scheduled, and dispatched efficiently.

Why Storage Needs Block Based Access

Filesystems require predictable access to logical storage regions rather than a continuous byte stream. Block devices provide addressable units that can be read or written independently. Separating block requests from particular hardware controllers allows Linux to support different storage technologies through common interfaces and device drivers.

Request Queues and Block Device Interfaces

A filesystem translates file operations into block requests that specify logical sectors, direction, and transfer length. The block layer manages requests and dispatches them through the device driver. Modern Linux storage paths use multi-queue mechanisms where supported, allowing requests to be distributed across hardware and software queues.

Example of Reading a Logical Block

A filesystem needs data from logical block 1200 of a storage device. It submits a read request containing the required sector range. The block layer places the request into an appropriate queue, and the driver instructs the storage controller to retrieve the data into a memory buffer.

Throughput, Scheduling and Storage Reliability

Block devices support filesystems, databases, swap, and virtual machine storage. Request merging and queue management can improve efficiency, although mechanical disks and SSDs have different performance characteristics. Device failures, bad sectors, queue saturation, and storage latency can affect applications, so filesystems and drivers need error handling and recovery.

Misconceptions About Linux Block Devices

'A block device can access only sequential locations' is false because logical blocks are addressable. 'Every block request transfers exactly one block' ignores multi-block requests. 'An SSD requires the same mechanical seek scheduling as a hard disk' overlooks the absence of a moving read-write head.

Exam Focus: Logical Blocks and Request Queues

Explain how filesystem operations become block requests and how the block layer dispatches them. Distinguish logical block addresses from physical disk locations. Questions may examine request merging, multi-queue processing, disk scheduling, and differences between hard disk and SSD performance.

Key Terms of Linux Block Devices

  • Block device - Device supporting addressable storage units.
  • Logical sector - Addressable unit presented by a device.
  • Block layer - Manages and dispatches storage requests.
  • Request queue - Holds pending block operations.
  • Multi-queue - Parallel request queue architecture.
2
Easy
4
Medium
3
Hard

📝 All Block devices in The Linux System MCQs

Q1. What unit of storage does the Linux page cache use to hold file data?

A.Byte
B.Kilobyte
C.Page ✅
D.Block
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The page cache works with whole pages, typically 4 KiB4\,\text{KiB} on x86 systems, so it stores data in page‑sized chunks. Therefore the correct answer is Page. Byte is too small; the cache does not manage individual bytes. Kilobyte is a size unit but not the fundamental cache unit. Block refers to block devices and is unrelated to the cache’s internal granularity. Understanding that the cache uses pages helps developers predict memory usage when reading large files, especially on systems with limited RAM.

Q2. Why does the Linux kernel store vm_area_struct objects in a balanced binary tree?

A.To minimize memory consumption
B.To allow fast lookup of a region by virtual address ✅
C.To enable parallel processing
D.To simplify page swapping
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The kernel must locate the region containing a given virtual address quickly, because address translations happen on every memory access. A balanced binary tree guarantees O(log n) search time, which is far faster than scanning a linear list. This makes option B correct. Option A is wrong because the tree adds some overhead rather than reducing memory. Option C is incorrect; the structure is not intended for parallel processing. Option D is unrelated, as page swapping uses different data structures. Fast region lookup is essential in real‑world programs that allocate many memory regions, such as just‑in‑time compilers.

Q3. A program reads a large file sequentially. Which mechanism ensures that subsequent reads are fast?

A.Page cache ✅
B.Direct I/O
C.Swap space
D.Network buffering
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When a file is read, the kernel first loads the needed pages into the page cache. Subsequent sequential reads can then be satisfied from memory, avoiding disk access and dramatically reducing latency. This makes the page cache the correct choice. Direct I/O bypasses the cache, which would slow repeated reads. Swap space is used for memory pressure, not for speeding file reads. Network buffering applies to network sockets, not local disk files. In practice, developers rely on the page cache to accelerate bulk file processing.

Q4. How does the virtual memory system interact with the page cache when loading a file page?

A.It bypasses the page cache entirely
B.It copies the page into a separate buffer
C.It maps the page into the page cache using page tables ✅
D.It stores the page in swap first
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: When a file page is needed, the virtual memory manager maps that page into the process’s address space, and the page cache holds the actual data. This mapping uses page‑table entries, linking the cache page to the virtual address. Therefore option C correctly describes the interaction. Option A is false because the cache is essential for performance. Option B is inaccurate; the system does not duplicate the page. Option D is wrong because swap is only used when memory is scarce, not during normal page loading. This mechanism enables applications to access files as if they were in memory, improving real‑world I/O efficiency.

Q5. If a Linux system runs low on free pages, what does the kernel typically do with the page cache?

A.Write dirty pages to disk ✅
B.Drop clean pages from the cache
C.Increase swap size
D.Disable the page cache
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When free memory becomes scarce, the kernel first writes any dirty (modified) pages in the cache back to their backing storage to free those pages. This action directly matches option A, making it correct. Dropping clean pages (option B) may happen later, but writing dirty pages is the primary step. Increasing swap size (option C) does not immediately reclaim pages. Disabling the page cache (option D) would hurt performance and is not a standard response. Understanding this behavior helps administrators anticipate I/O bursts during memory pressure.

Q6. A device driver for a new block device wants to bypass the page cache for low‑latency writes. Which flag should it use when opening the file?

A.O_DIRECT ✅
B.O_SYNC
C.O_RDONLY
D.O_TRUNC
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: O_DIRECT tells the kernel to perform I/O directly between user buffers and the storage device, avoiding the page cache. This reduces latency for time‑critical writes, making option A the correct choice. O_SYNC forces writes to be flushed to disk but still uses the cache, so it does not meet the bypass requirement. O_RDONLY opens the file read‑only, irrelevant for writes. O_TRUNC truncates the file size, unrelated to caching behavior. Using O_DIRECT is common in high‑performance database or logging systems where deterministic write timing is essential.

Q7. What is the primary difference between block devices and character devices regarding page cache usage?

A.Both are always cached
B.Block devices can be cached while character devices are not ✅
C.Character devices use a larger cache
D.Block devices never use the page cache
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Block devices represent storage that can be accessed in fixed‑size blocks, allowing the kernel to cache those blocks in the page cache for faster reuse. Character devices, such as terminals or serial ports, deliver a stream of data and are not cached in the page cache, so option B is correct. Option A is wrong because character devices are not cached. Option C is inaccurate; character devices do not have a larger cache. Option D is false because block devices frequently use the page cache. Recognizing this distinction helps developers choose the right I/O strategy for different hardware.

Q8. A system administrator sees high I/O latency on a database stored on an NFS mount. Which change would most likely reduce latency by affecting the page cache?

A.Increase NFS read‑ahead size
B.Mount with direct I/O to bypass the page cache ✅
C.Reduce swap usage
D.Increase the dirty‑page write‑back interval
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Mounting the NFS share with the direct I/O option forces reads and writes to go straight to the remote server, bypassing the local page cache and eliminating cache‑coherency delays that can cause latency. This matches option B. Increasing read‑ahead (option A) may improve sequential access but does not address cache contention. Reducing swap (option C) does not directly impact NFS latency. Extending the dirty‑page write‑back interval (option D) could worsen latency by delaying writes. Direct I/O is a common technique for databases that require predictable response times.

Q9. What structure represents a region of a process's address space in the Linux kernel?

A.vm_area_struct ✅
B.inode
C.superblock
D.task_struct
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The kernel uses the vm_area_struct to describe each contiguous, page‑aligned region of a process’s virtual address space, storing permissions and file associations. Hence option A is correct. An inode (option B) describes a file on disk, not a memory region. A superblock (option C) holds filesystem metadata. The task_struct (option D) represents the process itself, not individual memory regions. Knowing the role of vm_area_struct helps developers understand how the kernel organizes memory mappings, which is essential when debugging memory‑related issues.

🔗 Related Topics (MCQs)