Richard Yang

Logo

My Personal Site

- About
- Coursework
- Resources
- Essays
- Recommendations
View My GitHub Profile

Operating Systems

Week 1

Concepts that will be repeatedly mentioned in the future

Generic Computer Architecture

Architectural Features Motivated by OS Services

Protection

System calls

Memory protection

Programs shouldn’t be able to access memory of other programs

Memory Hierarchy

Process Layout in Memory

When a program is running, it becomes a process. The OS creates a region of memory for that process that can’t be touched by other programs.

Components:

To implement this, there are three special registers: stack pointer, frame pointer, program counter

What if you run multiple programs at once? Current state of registers is saved; context switch

Caches

The cache policy decides what units of memory are stored in the caches. Commonly, entire lines are moved into cache; this is because of spatial locality. What is spatial locality? Very often we are accessing units of memory close by (like consecutive elements of array)

Traps

I/O

Week 2

When you run an exe file, OS creates process, or a running program

What is a process?

State of a process

Process state transitions:

OS data structures

OS maintains a data structure (e.g. a linked list) of all active processes information about process stored in process control block (PCB)

In Linux, you can see process information in directory proc/<pid>

Process APIs

Should we rewrite programs for each OS?

Process related system calls (UNIX):

Example:

int main() {
  pid = fork();
  if (pid < 0) printf("Error"); // child process failed to be created
  else if (pid == 0) printf("this is child process"); // in the child process, fork() returns 0
  else printf("this is parent process); // in the parent process, fork() will return PID of child process
}

Process Execution Mechanism

How are processes executed by CPU?

Function call vs System call

How is system call different?

Mechanism of system call

Trap instructions

Return from trap

Possible for CPU to not return to same process

OS Scheduler

How the OS decides what processes to run at any time

Two types of schedulers: non preemptive, preemptive

Example of context switch:

Scheduling Policies

What are we trying to optimize?

Policies:

Week 4

Virtual Memory

Why virtualize memory?

Virtual address space:

How to translate between real and virtual memory addresses?

MMU

Memory management unit

Design Goals

Memory Allocation

Mechanism of Address Translation

Base and bound registers

Segmentation

Paging

typical size of page table

Demand Paging

Not neccessary for pages of active processes to always be in main memory; OS uses part of disk (swap space) to store pages not in active use

Page fault

Page fault handling

Summary

How does TLB work?

More in page faulting

Page replacement policy

Week 5

Demand paging comtinued

Pre-paging

OS guesses in advance which page to move back to memory

What happens when page removed from memory?

At any given time, page of virtual memory can exist in one or more of

Locality of reference:

This is why demand paging can work!

Let p be probability of page fault

Transparent page faults

LRU Policy

Works well because of locality of references

All implementations and approximations require hardware assistance

Possible implementations:

These implementations are perfect; we can try to find approximation that is less expensive

Second Chance Policy

Essentially, pages can have one of two age values: 0 or 1

Enhanced Second Chance

Inter Process Communication

Shared memory:

Signals

Sockets

Message Queues

Blocking vs non-blocking communication

Multiprogramming and Thrashing

Week 7?

Threads and Concurrency

So far we have looked at single threaded programs

What’s a thread?

Process vs threads

Parallelism: single process can effectively utilize multiple CPU cores

Concurrency: running multiple threads/processes at same time, even on single CPU core, by interleaving execution

Question: if there is no parallelism in system, is concurrency still useful?

Scheduling Threads

Race Conditions

Week 8?

Locks

Consider update of variable shared between threads

Goals of lock implementation

Condition Variable: