Resources | Revision Questions | Computer Science
Click on a question to view the answer
Discuss how an operating system can employ techniques such as memory pooling and shared libraries to improve resource utilisation. Provide specific examples of each technique and explain the benefits they offer.
Operating systems can significantly improve resource utilisation through techniques like memory pooling and shared libraries. These techniques reduce memory fragmentation and improve code reuse, leading to more efficient use of system resources.
Memory pooling is a memory allocation technique where a pre-allocated block of memory is divided into smaller, fixed-size blocks. Instead of allocating and deallocating memory for each request, the OS allocates blocks from the pool. This reduces the overhead associated with dynamic memory allocation (e.g., malloc
and free
in C/C++), which can lead to memory fragmentation.
Example: A web server might use a memory pool to store frequently accessed data structures, such as connection buffers. This avoids the overhead of repeatedly allocating and freeing memory for each incoming connection.
Benefits: Reduced memory fragmentation, faster allocation and deallocation, improved performance, and better predictability of memory usage.
Shared libraries (also known as dynamic libraries) are libraries that can be used by multiple processes simultaneously. Instead of each process having its own copy of the library code in memory, they all share a single copy. This reduces the overall memory footprint of the system and saves disk space.
Example: Many applications on a Linux system use the same shared libraries, such as libc
(the C standard library). This means that only one copy of libc
needs to be loaded into memory, regardless of how many applications are running.
Benefits: Reduced memory usage, reduced disk space usage, easier software updates (only the library needs to be updated), and improved system stability.
Trade-offs: Shared libraries can introduce potential security vulnerabilities if a compromised library is used by multiple processes. Versioning issues can also arise if different applications require different versions of the same library.
Describe the purpose of virtual memory and explain how it allows an operating system to maximise resource utilisation. Include in your answer a discussion of page tables and the concept of swapping.
Virtual memory is a memory management technique that gives processes the illusion of having more memory than is physically available. It allows the OS to run programs that are larger than the available RAM. This is achieved by using a combination of physical memory (RAM) and secondary storage (e.g., hard disk).
Virtual memory allows multiple processes to share the same physical memory. This reduces the overall memory footprint of the system. Furthermore, it enables processes to access memory locations that are not currently in RAM, storing them on disk. This increases the effective memory available to each process.
A page table is a data structure used by the OS to map virtual addresses (used by the process) to physical addresses (in RAM). Each process has its own page table. The page table contains entries that indicate whether a page is in RAM, on disk, or invalid. If a page is on disk, a page fault occurs, and the OS retrieves the page from disk and loads it into RAM.
Swapping is the process of moving pages between RAM and disk. When RAM is full, the OS selects pages to be swapped out to disk, making space for new pages. The selection of pages to swap out is based on various algorithms (e.g., Least Recently Used - LRU). Swapping can significantly impact performance due to the slow access time of disk compared to RAM. However, it allows the system to run more processes than would otherwise be possible.
Table: Page Table Entry
Page Number | Present in RAM? (Yes/No) | Physical Frame Number |
Trade-offs: While virtual memory increases resource utilisation by allowing larger processes and enabling multitasking, swapping can lead to performance degradation if excessive swapping occurs (thrashing). The OS must carefully manage the swapping process to minimise this impact.
Describe the ways in which the user interface hides the complexities of the hardware from the user. Your answer should consider different types of user interfaces and provide specific examples.
The user interface (UI) plays a crucial role in abstracting the complexities of the underlying hardware from the user. Without a UI, users would need to understand intricate details about memory management, input/output operations, and processor architecture to interact with a computer. A well-designed UI presents a simplified and intuitive way to interact with these complex systems. Here are several ways this abstraction is achieved:
ls
, copy
, mkdir
). The shell (a command interpreter) translates these commands into system calls that interact with the hardware. The user doesn't need to know the underlying assembly language or hardware specifications.In summary, the UI hides hardware complexities by providing simplified representations, translating user actions into low-level commands, and using intermediary layers (like APIs and device drivers) to manage hardware interactions. This allows users to focus on tasks rather than the underlying hardware details.