HW 1 Flashcards
What are the meanings of virtualizing CPU
) Virtualizing the CPU: the ability of the OS to abstract away the CPU hardware limitations to give the illusion that a single CPU is actually multiple virtual CPUs. Creating the illusion that each operating system has its own exclusive CPU allows multiple programs to run on the same machine without interfering.
So in summary, virtualizing the CPU refers to the OS ability to abstract away the real CPU hardware limitations, and present a virtualized environment that can run many concurrent programs on a small number of physical CPUs.
What are the meanings virtualizing memory?
b)Virtualizing memory refers to an operating system abstraction that provides each running program with the illusion of having its own private memory address space, isolated from other programs. The OS manages physical RAM in a way that makes each program operate as if it has its own dedicated piece of memory, even though programs may access the same underlying physical memory
So in summary, virtualizing memory refers to the OS abstraction that provides per-program virtual address spaces, and transparently maps virtual addresses to physical RAM, enabling private isolated memory for programs while efficiently utilizing shared physical memory resources.
What are the benefits of virtualizing CPU?
a)Virtualizing the CPU allows multiple applications to run concurrently without interfering with each other, ensuring that one application’s issues do not affect another. The OS provides the illusion of multiple virtual CPUs to maximize utilization of the physical CPUs. This saves energy and cost. CPU virtualization also allows easy scaling of applications and workloads by adding virtual CPUs without changing the hardware.
What are the benefits of virtualizing memory?
b)Virtualizing memory isolates each application’s memory space, preventing one application from accessing or affecting the memory of another application. This improves security and reliability. Memory virtualization also enables the OS to optimize memory usage by flexibly mapping virtual to physical memory as needed. The isolation of virtual memory spaces enables smooth multitasking by allowing concurrent execution of multiple programs even if they share the same physical memory resources.
When a parent process creates a child process using the fork() operation, is there any part of memory in principle (not in practice) shared between the parent process and the child process during their ongoing executions? Explain it.
Parent and child processes initially share memory pages after fork(). This sharing is done as a copy-on-write. If either process writes to a shared page, the kernel makes a private copy. Those unchanged pages can continue to be shared. There is no guaranteed sharing of memory between parent and child processes after fork(). The kernel facilitates copy-on-write so that the process has private memory spaces. processes operate independently on private copies.
In principle, there is no sharing of memory between parent and child processes after fork(). When fork() is called, the parent process makes a duplicate copy of its entire virtual memory space, including code segments. This copying creates a separate and isolated memory space for the new child process. The parent and child processes operate independently on their own private copies of memory. There is no region of memory that is shared between them during ongoing execution. This ensures isolation and protection, as the processes cannot access each other’s memory.
In principle, the parent process
makes a duplicate copy of its memory (including code
segment) into another memory location for the child process.
* So the child process will have the same code, but in a different
location for protection so that they can’t access each other’s
memory.
* In practice, since the child won’t change its code until “exec()”
is called, the child will share the code with its parent until
“exec()” is called.
Explain how the separation of fork() and exec() helps the shell implement some functions.
Explain why the “spin”’s initial name is “sh” in P1.
1) The separation of fork() and exec() is critical in building a UNIX shell because it allows the shell to customize the environment of a new child process before executing the desired program in that process. the shell has the flexibility to modify the child process’s environment, set environment variables, change permissions, configure resource limits, and establish communication channels such as pipes for data exchange between processes enabling customization. Separation lets the shell run another code after the call to fork() but before the call to exec(). Meaning the shell can run additional code or perform actions after forking a new process but before that process executes a different program using exec() useful for handling errors managing resources before new program starts running.
2)When the initial shell process (sh) forks a new process, like spin, the child process inherits “sh” as its initial name until it becomes its own program through exec(). This is done so that sh is registered as the parent process for spin and any other processes created by the shell.
Compare the single-queue scheduling with the multi-queue scheduling for the multi-processor scheduler design. Describe the pros and cons for each.
Single-queue scheduling; Instead of having separate queues for each CPU, SQMS simplifies things by maintaining a single queue for all CPUs to choose tasks from. SQMS tries to achieve fairness and simplicity in multiprocessor scheduling but may not be the most efficient solution for all scenarios due to drawbacks.
Pros of SQMS:
Simplicity: it extends a single-processor scheduling policy to handle multiple CPUs with minimal changes. It keeps all tasks in one queue for all CPUs to access. Example: Imagine you have a scheduling algorithm for a single-CPU system that selects the next task based on priority. In SQMS, you can use the same algorithm for a multiprocessor system, but now you’re picking the top tasks for each CPU from a shared queue.
Cons of SQMS:
Lack of Scalability: SQMS can become less efficient as the number of CPUs in the system increases. This is because synchronization mechanisms like locks are often used to prevent multiple CPUs from accessing the shared queue simultaneously. As more CPUs contend for these locks, performance can degrade. the system spends more time managing locks than performing useful work. This is a Concurrency issue: multiple CPUs contend for access to a shared queue,
Cache Affinity Issues: involves keeping a process running on the same CPU, so it can take advantage of cached data for better performance. SQMS doesn’t naturally preserve cache affinity because tasks are picked from a shared queue, leading to tasks bouncing between different CPUs.
“locks” ensure that shared resources are accessed by only one CPU at a time. While they are essential for data consistency, they can introduce performance overhead, especially in systems with many CPUs.
Multiprocessor scheduling: is an alternative approach to multiprocessor scheduling that addresses some of the issues found in single-queue schedulers like SQMS. In MQMS, the scheduling framework consists of multiple scheduling queues, typically one queue per CPU. Each queue follows a specific scheduling discipline, such as round-robin. When a job enters the system, it is placed on one of these scheduling queues, usually based on a heuristic or policy ((e.g., random, or picking one with fewer jobs than others). Then it is scheduled essentially independently, thus avoiding the concurrency issue found in the single-queue approach each CPU or processing core can make its own scheduling decisions based on the tasks available in its respective queue.
Pros of MQMS:
Scalability: MQMS can be inherently more scalable than single-queue approaches like SQMS. As the number of CPUs increases, so does the number of queues, reducing contention for locks and caches.
Cache Affinity: MQMS naturally provides cache affinity because jobs tend to stay on the same CPU. This means that jobs can take advantage of cached data, improving performance.
Cons of MQMS:
Load Imbalance: Achieving load balance in MQMS can be challenging, especially when jobs have varying execution times. Continuous migration may be required to maintain balance.
Migration: To achieve load balance, MQMS employs a technique known as migration, where jobs are moved or “migrated” between CPUs as needed to balance the load.
Complexity: Implementing migration mechanisms and load balancing strategies adds complexity to the scheduler.
Overhead: Techniques like work stealing, used to achieve load balance, can introduce overhead if not implemented carefully, potentially impacting system performance.
(Load Balancing: One of the primary objectives of MQMS is load balancing. It aims to distribute the workload evenly across CPUs to maximize resource utilization.
Work stealing: It allows CPUs to share and balance their workloads by periodically stealing tasks from other CPUs with fuller queues, ensuring that all CPUs contribute to the overall system’s efficiency.)
Explain how the OS regains control of the CPU in a non-cooperative way in order to switch processes.
Timer interrupts: A timer device can be programmed to raise an interrupt at specified intervals. When this interrupt is raised, the currently running process is halted, and control is transferred to a pre-configured interrupt handler in the operating system. When the timer interrupt occurs, the OS’s interrupt handler runs, giving the OS control. This enables the OS to perform actions like stopping the current process and starting a different one.
Multi-Level-Feedback-Queue (MLFQ) is one of CPU scheduling policies with some great features. As we discussed in class, it can be used to shoot four hawks which represent the problems in many scheduling policies. Briefly describe each of four hawks. Also briefly explain how MLFQ shoots each.
1st Hawk: (short turn around/waiting time): same policies allow processes to monopolize CPU time in the long run. MLFQ bumps processes to lower-priority queues if they use too much time in a given queue.
2 Hawk (short response time): processes can take over the CPU in a short burst, denying fair shore. MLFQ: time slicing within each queue using round robin with a short quantum size. Allows short jobs to be completed quickly and prevents them from taking over CPU. Ensuring that short jobs receive the responsibilities and CPU time they need without being unfairly delayed by longer processes
3rd Hawk: (avoiding starvation): Same processes might never get CPU time. MLFQ lower-priority queues ensure all processes eventually get a run.
4th Hawk (avoiding gaming the schedule): Processes manipulate their behavior to unfairly get more CPU. MLFQ aims to prevent processes from unfairly influencing scheduling decisions. Observes the actual behavior of processes in terms of CPU usage and responsiveness; this ensures that processes are assigned priorities and queue positions based on their observed behavior, promoting fair and accurate scheduling without allowing processes to game the system.