Resource Allocation - aryanjoshi0823/5143-Operating-System GitHub Wiki
Resource Allocation in Operating Systems
Resource allocation is a core function of an operating system (OS). It involves managing and distributing hardware and software resources such as CPU, memory, I/O devices, and storage to various processes effectively. The goal is to optimize resource usage while ensuring fairness, efficiency, and system stability.
Resource Allocation Strategies
1. Static Allocation: Resources are allocated at compile time or process creation.
2. Dynamic Allocation Resources are allocated during process execution.
3. Preemptive Allocation
- Resources can be forcibly reclaimed by the OS for allocation to another process.
- Time-sharing systems.
- CPU preemption using a round-robin scheduler.
4. Non-Preemptive Allocation
- Once allocated, resources cannot be reclaimed until the process releases them.
- I/O operations and critical sections.
Resource Allocation Techniques
1. Resource Scheduling
- CPU Scheduling:
- Algorithms include First-Come-First-Serve (FCFS), Shortest Job Next (SJN), Round Robin (RR), and Priority Scheduling.
- Ensures fairness and efficiency in CPU usage.
- I/O Scheduling:
- Algorithms like Shortest Seek Time First (SSTF) and Elevator Algorithm manage disk I/O requests.
- Memory Scheduling:
- Virtual memory techniques allocate memory pages dynamically.
2. Resource Partitioning
- Divides resources into fixed or variable partitions.
- Example:
- Disk partitions.
- Fixed-size memory blocks.
3. Resource Allocation Graphs (RAG)
- A graph-based method to detect and avoid deadlocks.
- Nodes: Represent processes and resources.
- Edges:
- Request edge (P → R): Process requests a resource.
- Assignment edge (R → P): Resource is allocated to a process.
4. Priority-Based Allocation
- Processes are assigned priorities, and resources are allocated based on these priorities.
- Can lead to priority inversion, where low-priority processes block high-priority ones.
5. Banker's Algorithm
- Purpose: Avoid deadlocks.
- Process:
- Check if a resource request can be safely granted without entering a deadlock state.
- Allocate resources only if the system remains in a safe state.