Dulranga's Notes
Semester 3Operating Systems

Terminology

Multi Level Feedback Queues

  • Used for optimizing CPU Criteria
  • Several queues available and CPU Scheduler pick job from the highest priority queue
  • Jobs may move between queues based on mathematically defined metrics automatically.
  • Priority is inferred not user defined.

Multi Level Queues

  • has Multiple Queues, but one process will only live in one queue for the whole execution timeline.
  • low priority queues may suffer from starvation if the high priority queues are busy for longer periods
  • not as good as MLFQs
  • Require prior knowledge to place the job in correct queue. usually OS or user does it

Scheduling Algorithms

  1. Round Robin Gives constant CPU burst time (Quantum) for all processes in the ready queue one after other in a loop. If the process exits before RR Quantum finishes, Next ready process is executed with new Quantum begin.

  2. FCFS (First Come, First Served) Can starve later processes if first one takes longer

  3. SJF (Shortest Job First) Need to guess the execution time required by each job Uses a Burst Prediction model called **exponential averaging (EWMA)

\tau_{n+1} = \alpha t_n + (1−\alpha)\tau_n $$ - tₙ = the actual length of the most recent (n-th) CPU burst — a measured fact - τₙ = the predicted length of the n-th burst — our guess - τₙ₊₁ = prediction for the next burst — what we're computing - α = weight, 0 ≤ α ≤ 1 (usually ½) 4. SRTF (Shortest Remaining time First) Also uses Burst Prediction. Remaining time need to be calculated for all processes after each cycle.

Process-contention scope (PCS)

a thread scheduling model where user-level threads compete against other threads within the same process for CPU or lightweight process (LWP) resource.

FeatureProcess Contention Scope (PCS)System Contention Scope (SCS)
Contention LevelWithin a single process onlyAcross the entire operating system
Thread MappingMany-to-one or many-to-many (N:1 or N:M)One-to-one (1:1) with a kernel thread
SchedulerUser-level thread libraryOS kernel scheduler
Context SwitchFast (no kernel intervention)Slower (requires kernel calls)
Multicore UseLimited to the assigned LWP/coreTrue system-wide multicore use

Symmetric multiprocessing scheduling

A computer architecture where multiple identical processors are interconnected to a single shared main memory, with full accessibility to all the I/O devices, unlike asymmetric MP. In other words, all the processors have common shared(common) memory and same data path or I/O bus as shown in the figure.SMP

Affinity

This lets a Process to run on an specific CPU Core rather than randomly gets one.

TypeBehavior
Soft affinityThe OS prefers to keep a task on the same core, but may migrate it if needed (this is the default behavior).
Hard affinityThe task is restricted to an explicit set of cores and will never run elsewhere (set explicitly by the user/app).

NUMA (Non-Uniform Memory Access)

In a NUMA system, memory is split into nodes. Each CPU (or group of cores) has its own memory controller and its own bank of RAM directly attached to it:

  • Accessing your own node's RAM = fast (local access).
  • Accessing the other node's RAM = slower (remote access), because it has to travel over the inter-socket interconnect (e.g., Intel's UPI, AMD's Infinity Fabric).

This is why it is "Non Uniform", the time it takes to access memory depends on where it is

In a NUMA system, you usually want affinity too. This is because the process must be running in the same CPU Node as the Memory is allocated to it. This makes it faster.

Memory Fragmentation

Internal Fragmentation

wasted space inside the block that was given to a process. The memory is allocated but unused, and no one else can use it.

  • Memory is handed into processes in fixed chunks so some can be not fully used by program

External Fragmentation

wasted space outside any allocation: free memory exists in total, but is scattered in non-adjacent pieces, so it can't satisfy a request that needs a contiguous chunk.

  • Happens with variable-size allocations in contiguous memory: every process gets exactly what it asks for, but departures leave irregular holes.

PTBR and PTLR

Page Table Base Register - physical base address of the page table Page Table Length Register - number of valid entries in it (addresses valid until base+length)

Effective Access Time (ETA) - Memory

EAT=h(t+m)⏟Cache Hit+(1−h)(t+2m)⏟Cache Miss=t+m(2−h)\text{EAT} = \underbrace{h(t+m)}_\text{Cache Hit} + \underbrace{(1-h)(t+2m)}_\text{Cache Miss} = t + m(2-h)

This is the average time for memory access in a processor with virtualization enabled.

  • hh - Hit Ratio
  • tt - Time for the cache hit
  • mm - Time for memory read

Thrashing

when a system spends more time swapping pages in and out than executing useful work. Processes keep faulting because they don't have enough frames for the pages they actively use. The CPU sits mostly idle, waiting for the disk.

thrashing-cpu-utilization.png

Why thrashing occurs

∑size of locality>total memory size\sum \text{size of locality} > \text{total memory size}

Data vs Task Parallelism

ways to speed things up by parallelizing through multiple cores

Data parallelismTask parallelism
What is dividedThe dataThe tasks/functions
Operation per coreSameDifferent
Scales withAmount of data, which is often very largeNumber of independent tasks, which is often limited
ExampleEach core sums part of an arrayEach core computes a different statistic

PCB - Process Control Block

Contains these:

  • process state
  • program counter
  • CPU registers
  • CPU-scheduling information
  • memory-management information
  • accounting information
  • I/O status information pcb.png

On this page