Operating Systems
#os
- 4 minutes read - 657 words
Operating System
- Abstraction over hardware for user processes.
- Main task of OS is to allocate computing resources (disk, ram, cpu cycles)
- The kernel is part OS code which runs in privileged mode.
Privileged Instruction
- Supported hardwares categorize instruction as privileged and non-pribileged
- User mode code can’t issue privileged instructions, like timer interrupt
- Kerned mode code can execute privileges instructions.
System Calls
- Interface provided by kernel for user mode to run allowed privileged instruction and access hardware
- every syscall has a number
Process
- An instance of code loaded in memory and executed by OS
- Process components: Text segment, data segment, BSS, stack and PCB
- Process States: Running, Blocked, Ready
Thread & Child process
- Thread arr unit of execution that belong to a process and share the same addr space
- child process are spawned by another process and have thier own addr space
Scheduling
- A timer interrupts gives control back to OS/kernel from a running process
- Scheduler is responsible for moving a ready process to running state
- Context switch is used to save the state of yielded process and resume the execution of running process.
Concurrency
A race condition occurs when the computation depends on the relative speed of two or more processes.
- Mutex
A locking mechanism to synchronize access to resource. A single lock that a process need to acquire before it can access a critical resource
- Semaphore
Pretty much same as mutex but instead of just one binary state a semaphore can have multiple. It is a signalling mechanism where the process holding the lock signals when it is done.
These are just theoretical definitions and looking at implementation gives more clarity
not handling concurrency control correctly may lead to deadlock situations.
File System
- File systems provide an abstraction of the physical disk
- iNode
Memory
- Virtual memory and Physical Memory
- From a Process perspective it has access to the whole address space
- Process memory map contains segment for each type of memory, like, kernel reserved, stack , heap, BSS, data, text.
- Process memory map contains virtual address and a translation action converts it to actual physical address which is accessed via MMU
Page Table
- PTE: Page Table Entry (a single entry in page table)
- Page Size: size of memory block to be considered a page
- In physical memory that block is called frame
- Kernel Data Structure in main memory that maps virtual memory addr to physical memory addr
- PTE can map to a disk block as well in case of swap or partial memoey load
- Request to access memeory from process is handled using this PTE
- Page table has to be in the main memory
Page Hit
Reference to VM address that is in physical memory (RAM hit)
Page Fault
- Reference to VM address that is not in physical memory (RAM miss), but it is there in disk
- Page miss causes page fault (an exception)
- Page fault handler selects a victim to be evicted (from the main memory)
- and loads new page into freed frame
- Offending instruction is restarted: page hit!
Page Table Size
- Page Size: 4 KB
- Address Space: 64 bit
- PTE Size: 8 bytes
- Page Table Size: 2^64 * 2^-12 * 2^3 => 2^55 bytes
Hierarchical page table
- Two level page table to reduce the size of table to be kept in main memory
Page Translation Overhead
- Memory IO, Disk IO and CPU cycles spent of bringing a page into memory after a page fault
TLB
- Translation Lookaside Buffer
Input Output
- Programmed I/O (polling or busy waiting)
- Interrupt Driven I/O
- Processor is interrupted when I/O module (controller) is ready to exchange data
- Consumes processor time because every read and write goes through the processor
- Direct Memory Access (DMA)
- Processor sent interrupt at start and end, but is free to work on other things while the device is transferring data directly to memory.
Scheduling
- The scheduler decides which task to run next
Multiprocessor Systems
- Uniform Memory access : UMA
- Non Uniform Memory Access: NUMA
- CPU affinity