From 2fea81b28b7dc5a4fa07ca25108a94ac44cf4e5a Mon Sep 17 00:00:00 2001 From: Maria Lusardi Date: Tue, 3 Dec 2024 15:16:21 -0600 Subject: [PATCH 1/4] Fixed questions for sec 1 and 2 --- _slides/lovable_linux.md | 92 +++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 21 deletions(-) diff --git a/_slides/lovable_linux.md b/_slides/lovable_linux.md index 2e1f9d81e..e88ea4f96 100644 --- a/_slides/lovable_linux.md +++ b/_slides/lovable_linux.md @@ -3,48 +3,98 @@ layout: slide title: Review --- +## C + + + +How are C strings represented in memory? + +What is wrong with malloc(strlen(s)) when copying strings? + + + +```"hello" = [h][e][l][l][o][```**\0**```]``` + +A C string is just an array of characters with a null terminator (\0) at the end. + + + +```strlen("hello") == 5``` + +```strlen()``` **does not** count the null terminator. + +If used with malloc, there won't be enough memory allocated for the null terminator! + + + ## Virtual Memory -2.1 Explain how a virtual address is converted into a physical address using a multi-level page table. You may use a concrete example e.g. a 64bit machine with 4KB pages. +Explain how a virtual address is converted into a physical address using a multi-level page table. You may use a concrete example e.g. a 64bit machine with 4KB pages. -* How long is the offset? -* Page size: 4KB = 2^12B -> offset bits points to each Byte -> need 2^12 different address from offset bits -> offset is log_2⁡〖2^12〗 = 12 bits +### How long is the offset? + +* How many addresses do you need? One per Byte in the page + +Page size: ```4 KB = 2^12 B``` + +* How many bits do you need to define 2^12 addresses? + +```log_2⁡ (2^12⁡)``` = 12 bits + * You take the rest of the bits and split it up evenly among the level of page tables. - |--------VPN1--------|--------VPN2--------|--------VPN3--------|--------Offset--------| -> top_level = top_levels[process] -> level1 = top_level[VPN1] -> level2 = level1[VPN2] -> level3 = level2[VPN3] -> address = level3 + Offset +```|-VPN1-|-VPN2-|-VPN3-|-Offset-|``` + +> level_1 = top_level[VPN1] + +> level_2 = level_1[VPN2] + +> level_3 = level_2[VPN3] + +> physical_address = level_3 + Offset -2.5 What is a page fault? When is it an error? When is it not an error? +What is a page fault? When is it an error? When is it not an error? -* Page fault – When a running program tries to access some virtual memory in its address space that is not mapped to physical memory. There are three types +Page fault – program attempts access to virtual memory that is not mapped to physical memory. + +There are three types + * Major - The page is on disk and needs to be loaded into memory (disk I/O) * Minor – No mapping for the page, but valid address (no disk I/O) -* Invalid - If the memory that is trying to be accessed is not part of the memory mapping (virtual address space), meaning there cannot be a page in memory corresponding to it, then this kind of error is generated. The operating system usually segfault -* When it’s an Error - Invalid -* When it’s not an Error - Major or Minor +* Invalid - Memory being accessed is not part of the virtual address space. There cannot be a page corresponding to it. + + + +When it’s an Error - Invalid (The operating system usually segfaults) + +When it’s not an Error - Major or Minor -2.6 What is Spatial and Temporal Locality? Swapping? Swap file? Demand Paging? +What is Spatial and Temporal Locality? Swapping? Swap file? Demand Paging? + + + +Spatial Locality - Objects in adjacent memory addresses get used (think arrays). That is why a page table is a certain size. + +Temporal Locality - Objects used more recently get used. The TLB takes advantage of that + + + +Swapping - Taking a page in memory and burning to disk. + +Swap File - specific file on disk that the pages get written to. Another solution is a swap space partition. + +Demand Paging - Only allocate pages as the process requests them -* Spatial Locality - Objects in adjacent memory addresses get used (think arrays). That is why a page table is a certain size. -* Temporal Locality - Objects get used over time the TLB is where takes advantage of that -* Swapping - Taking a page in memory and burns to disk. -* Swap File - It is a specific file on disk that the pages get written to. Another solution is to have swap space partition. -* Demand Paging - Only allocate pages as the process requests them -* From 4c97816ea22aea27227a22473960bc71cf758757 Mon Sep 17 00:00:00 2001 From: Maria Lusardi Date: Wed, 4 Dec 2024 11:18:14 -0600 Subject: [PATCH 2/4] Added questions for everything except file systems --- _slides/lovable_linux.md | 198 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) diff --git a/_slides/lovable_linux.md b/_slides/lovable_linux.md index e88ea4f96..22f1f62b4 100644 --- a/_slides/lovable_linux.md +++ b/_slides/lovable_linux.md @@ -98,3 +98,201 @@ Swap File - specific file on disk that the pages get written to. Another solutio Demand Paging - Only allocate pages as the process requests them + + +Processes and Threads + + + +Explain the operating system actions required to perform a process context switch. + + + +1. Save state in process control block(pcb) + +This includes: +* Program Counter +* Registers +* Priority +* Stack Pointer / Address Space +* Open Files + + + +2. Flush Translation Lookaside Buffer (TLB) +**BUT** with ASID or PCID (intel) may not be necessary +* Used to identify which process an entry is from +* Address space identifiers (ASID) assigned dynamically +* interactive processes don't get ASIDs +* ASID's are short, too short to identify all processes +* stored in a data structure and optimized for cache usage + + +3. Choose next process (scheduler's job) + +4. Load process state from control block + +5. Pop program counter, resume task + + + +Explain the actions required to perform a thread context switch (to a thread in the same process) + + + +Same as above **EXCEPT** +* Only need to save Thread Control Block (TCB) instead of PCB + +(i.e. not whole address space, just the stack) + +* Don't need to flush TLB +* Scheduler could be the OS for kernel threads (so just like process scheduling) or the scheduler could be the CPU for user-level threads (so a library handles it) + + + +Scheduling + + + +Which scheduling algorithm results the smallest average wait time? + + + +Round Robin (**IF** new processes sent to the back of the queue) +* wait time \leq (x number of processes on queue) + + +Why not any other scheduler? + +FCFS: wait time = sum of runtime of all processes on queue + +SJF/PSJF: wait time = /inf if shorter jobs keep arriving + +Priority: waittime = /inf if higher priority jobs keep arriving + + + +What scheduling algorithm has the longest average response time? + + + +Priority +* process can always be pushed lower on the queue by higher priority processes +* priority doesn't correspond to runtime + + +Why not any other scheduler? + +FCFS: response \leq runtime of processes ahead of it on the queue +SJF/PSJF: \inf, but at least all jobs ahead of a process on the queue have shorter runtimes. Priority doesn't guarantee this. +RR: response \leq time quantum x number of processes ahead on the queue. + + + +Synchronization and Deadlock + + + +Define circular wait, mutual exclusion, hold and wait, and no-preemption. How are these related to deadlock? + + + +### Coffman Conditions + +Circular wait: There exists a cycle in the Resource Allocation graph + +* P1 is waiting for resources from P2 +* P2 is waiting for resources from P3 +* ect... +* PN is waiting for resources from P1 + +Mutual Exclusion: no two processes can hold the same resources at the same time + +Hold and Wait: Once a resources is obtained, process holds it until finished + +No pre-emption: Nothing can make a process give up a resource + + + +What is the difference between Deadlock Prevention, Deadlock Detection and Deadlock Avoidance? + + + +Deadlock Prevention: Eliminate a Coffman conditions. Deadlocks become impossible. + +Deadlock Avoidance: Avoid by allocating resources in a safe manner. The OS implements concurrency control. + +Deadlock Detection: When deadlock occurs, OS can detect and resolve it. + +(i.e. use a Resource Allocation Graph to detect deadlocks. kill processes or preempt resources to resolve) + + + +IPC and signals + + + +Give an example of kernel generated signal. List 2 calls that can a process can use to generate a ```SIGUSR1```. + + + +Kernel generated signals: +* ```SIGSEGV``` +* ```SIGILL``` +* ```SIGXCPU``` + +Try running ```kill -l``` to see all signals + + + +```raise(int signal)``` signals yourself + +```kill(pid_t pid, int signal)``` signal other processes + + + +What signals can be caught and ignored? What signals cannot be caught? + + + +You can catch anything except ```SIGKILL``` and ```SIGSTOP``` + +See man page for ```signal(2)``` on how to set signal disposition. + + + +Networking + + + +Describe the services provided by TCP but not UDP. + + + +* TCP performs flow control, UDP does not +* TCP guarantees delivery, UDP is “best effort” +* TCP has a notion of a connection, UDP is connectionless +* TCP has 3-way (SYN - SYN/ACK - ACK) handshake + +TCP is used for web browsing, email, file transfers, etc. UDP is used when data becomes stale quickly (e.g. audio/video streaming and DNS). + + + +Files + + + +Briefly explain permission bits (including sticky and setuid bits) for files and directories. + + + +```drwxrwxr-x``` + +```d``` or ```-``` : directory or file +```rwx``` : What the owner of the file is allowed to do (read, write, execute) +```rwx```: What users in the owner's group are allowed to do (read, write, execute) +```r-x```: What everyone else is allowed to od (read and execute, but not write) + + + +File System \ No newline at end of file From 791eb4c9b2257f8713ae31a23722f6a97b30f176 Mon Sep 17 00:00:00 2001 From: Maria Lusardi Date: Wed, 4 Dec 2024 14:45:33 -0600 Subject: [PATCH 3/4] finished review slides --- _slides/lovable_linux.md | 130 ++++++++++++++++++++++++++------------- 1 file changed, 87 insertions(+), 43 deletions(-) diff --git a/_slides/lovable_linux.md b/_slides/lovable_linux.md index 22f1f62b4..8ba57c30f 100644 --- a/_slides/lovable_linux.md +++ b/_slides/lovable_linux.md @@ -7,9 +7,9 @@ title: Review -How are C strings represented in memory? +*How are C strings represented in memory?* -What is wrong with malloc(strlen(s)) when copying strings? +*What is wrong with malloc(strlen(s)) when copying strings?* @@ -31,8 +31,7 @@ If used with malloc, there won't be enough memory allocated for the null termina -Explain how a virtual address is converted into a physical address using a multi-level page table. You may use a concrete example e.g. a 64bit machine with 4KB pages. - +*Explain how a virtual address is converted into a physical address using a multi-level page table. You may use a concrete example e.g. a 64bit machine with 4KB pages.* @@ -62,12 +61,14 @@ Page size: ```4 KB = 2^12 B``` -What is a page fault? When is it an error? When is it not an error? +*What is a page fault? When is it an error? When is it not an error?* Page fault – program attempts access to virtual memory that is not mapped to physical memory. + + There are three types * Major - The page is on disk and needs to be loaded into memory (disk I/O) @@ -82,7 +83,7 @@ When it’s not an Error - Major or Minor -What is Spatial and Temporal Locality? Swapping? Swap file? Demand Paging? +*What is Spatial and Temporal Locality? Swapping? Swap file? Demand Paging?* @@ -100,15 +101,15 @@ Demand Paging - Only allocate pages as the process requests them -Processes and Threads +## Processes and Threads -Explain the operating system actions required to perform a process context switch. +*Explain the operating system actions required to perform a process context switch.* -1. Save state in process control block(pcb) +Step 1: Save state in process control block(pcb) This includes: * Program Counter @@ -119,7 +120,8 @@ This includes: -2. Flush Translation Lookaside Buffer (TLB) +Step 2: Flush Translation Lookaside Buffer (TLB) + **BUT** with ASID or PCID (intel) may not be necessary * Used to identify which process an entry is from * Address space identifiers (ASID) assigned dynamically @@ -128,15 +130,15 @@ This includes: * stored in a data structure and optimized for cache usage -3. Choose next process (scheduler's job) +Step 3: Choose next process (scheduler's job) -4. Load process state from control block +Step 4: Load process state from control block -5. Pop program counter, resume task +Step 5: Pop program counter, resume task -Explain the actions required to perform a thread context switch (to a thread in the same process) +*Explain the actions required to perform a thread context switch (to a thread in the same process)* @@ -146,33 +148,35 @@ Same as above **EXCEPT** (i.e. not whole address space, just the stack) * Don't need to flush TLB -* Scheduler could be the OS for kernel threads (so just like process scheduling) or the scheduler could be the CPU for user-level threads (so a library handles it) +* Different Scheduler: + * kernel threads: OS handles it (so just like process scheduling) + * user-level threads: CPU handles it (so a library handles it) -Scheduling +## Scheduling -Which scheduling algorithm results the smallest average wait time? +*Which scheduling algorithm results the smallest average wait time?* Round Robin (**IF** new processes sent to the back of the queue) -* wait time \leq (x number of processes on queue) +* wait time ≤ (x number of processes on queue) Why not any other scheduler? FCFS: wait time = sum of runtime of all processes on queue -SJF/PSJF: wait time = /inf if shorter jobs keep arriving +SJF/PSJF: wait time = ∞ if shorter jobs keep arriving -Priority: waittime = /inf if higher priority jobs keep arriving +Priority: waittime = ∞ if higher priority jobs keep arriving -What scheduling algorithm has the longest average response time? +*What scheduling algorithm has the longest average response time?* @@ -183,17 +187,19 @@ Priority Why not any other scheduler? -FCFS: response \leq runtime of processes ahead of it on the queue -SJF/PSJF: \inf, but at least all jobs ahead of a process on the queue have shorter runtimes. Priority doesn't guarantee this. -RR: response \leq time quantum x number of processes ahead on the queue. +FCFS: response ≤ runtime of processes ahead of it on the queue + +SJF/PSJF: ∞, but at least all jobs ahead of a process on the queue have shorter runtimes. Priority doesn't guarantee this. + +RR: response ≤ time quantum x number of processes ahead on the queue. -Synchronization and Deadlock +## Synchronization and Deadlock -Define circular wait, mutual exclusion, hold and wait, and no-preemption. How are these related to deadlock? +*Define circular wait, mutual exclusion, hold and wait, and no-preemption. How are these related to deadlock?* @@ -206,6 +212,10 @@ Circular wait: There exists a cycle in the Resource Allocation graph * ect... * PN is waiting for resources from P1 + + +### Coffman Conditions Cont. + Mutual Exclusion: no two processes can hold the same resources at the same time Hold and Wait: Once a resources is obtained, process holds it until finished @@ -214,25 +224,29 @@ No pre-emption: Nothing can make a process give up a resource -What is the difference between Deadlock Prevention, Deadlock Detection and Deadlock Avoidance? +*What is the difference between Deadlock Prevention, Deadlock Detection and Deadlock Avoidance?* + + + +**Deadlock Prevention**: Eliminate a Coffman conditions. Deadlocks become impossible. -Deadlock Prevention: Eliminate a Coffman conditions. Deadlocks become impossible. +**Deadlock Avoidance**: Avoid by allocating resources in a safe manner. The OS implements concurrency control. -Deadlock Avoidance: Avoid by allocating resources in a safe manner. The OS implements concurrency control. + -Deadlock Detection: When deadlock occurs, OS can detect and resolve it. +**Deadlock Detection**: When deadlock occurs, OS can detect and resolve it. (i.e. use a Resource Allocation Graph to detect deadlocks. kill processes or preempt resources to resolve) -IPC and signals +## IPC and signals -Give an example of kernel generated signal. List 2 calls that can a process can use to generate a ```SIGUSR1```. +*Give an example of kernel generated signal. List 2 calls that can a process can use to generate a ```SIGUSR1```.* @@ -251,7 +265,7 @@ Try running ```kill -l``` to see all signals -What signals can be caught and ignored? What signals cannot be caught? +*What signals can be caught and ignored? What signals cannot be caught?* @@ -261,11 +275,11 @@ See man page for ```signal(2)``` on how to set signal disposition. -Networking +## Networking -Describe the services provided by TCP but not UDP. +*Describe the services provided by TCP but not UDP. What applications use TCP? What applications use UDP?* @@ -274,25 +288,55 @@ Describe the services provided by TCP but not UDP. * TCP has a notion of a connection, UDP is connectionless * TCP has 3-way (SYN - SYN/ACK - ACK) handshake -TCP is used for web browsing, email, file transfers, etc. UDP is used when data becomes stale quickly (e.g. audio/video streaming and DNS). + + +TCP is used for web browsing, email, file transfers, etc. + +UDP is used when data becomes stale quickly (e.g. audio/video streaming and DNS). -Files +## Files -Briefly explain permission bits (including sticky and setuid bits) for files and directories. +*Briefly explain permission bits (including sticky and setuid bits) for files and directories.* ```drwxrwxr-x``` -```d``` or ```-``` : directory or file -```rwx``` : What the owner of the file is allowed to do (read, write, execute) -```rwx```: What users in the owner's group are allowed to do (read, write, execute) -```r-x```: What everyone else is allowed to od (read and execute, but not write) +* ```d``` or ```-``` : directory or file + +* ```rwx``` : What the owner of the file is allowed to do (read, write, execute) + +* ```rwx```: What users in the owner's group are allowed to do (read, write, execute) + +* ```r-x```: What everyone else is allowed to od (read and execute, but not write) -File System \ No newline at end of file +## File System + + + +*What information is stored in an i-node? What file system information is not?* + + + +* ```uid```: user ID of the inode owner. +* ```gid```: the ID of the inode group (does not have to include the owner). +* ```mode```: a bitmask. Bottom 9 bits are read-write-execute for owner-group-others. Bits 11-10 are the type of the file. +* ```nlink```: hard link count. The number of directories that the file is linked to from (directories can’t be hard linked). + + + +* ```atim```: access time. Time of last access or the last time a file was read(2). +* ```mtim```: last modification time. Last time the file was changed with write(2). +* ```ctim```: last change time. Last time the file’s metadata was changed. +* ```size```: size of the file in bytes + + + +* ```direct```: an array. ```direct[i]``` is the ith data block’s offset (```data_block_number```) from the data_root. +* ```indirect```: the offset number (```data_block_number```) of a data block, which contains ```NUM_INDIRECT_BLOCKS``` number of ```data_block_number```’s. \ No newline at end of file From 8567cb75782c5bc5bee85af051f103069424938b Mon Sep 17 00:00:00 2001 From: Maria Lusardi Date: Thu, 5 Dec 2024 09:02:19 -0600 Subject: [PATCH 4/4] Fixed Rishabh's comments --- _slides/lovable_linux.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/_slides/lovable_linux.md b/_slides/lovable_linux.md index 8ba57c30f..bd176d8b2 100644 --- a/_slides/lovable_linux.md +++ b/_slides/lovable_linux.md @@ -43,7 +43,7 @@ Page size: ```4 KB = 2^12 B``` * How many bits do you need to define 2^12 addresses? -```log_2⁡ (2^12⁡)``` = 12 bits +```log2⁡ (2^12⁡)``` = 12 bits * You take the rest of the bits and split it up evenly among the level of page tables. @@ -51,7 +51,7 @@ Page size: ```4 KB = 2^12 B``` ```|-VPN1-|-VPN2-|-VPN3-|-Offset-|``` -> level_1 = top_level[VPN1] +> level_1 = page_table_base_register[VPN1] > level_2 = level_1[VPN2] @@ -65,7 +65,7 @@ Page size: ```4 KB = 2^12 B``` -Page fault – program attempts access to virtual memory that is not mapped to physical memory. +Page fault – program attempts access to virtual memory that is not mapped to up-to-date physical memory. @@ -93,7 +93,7 @@ Temporal Locality - Objects used more recently get used. The TLB takes advantage -Swapping - Taking a page in memory and burning to disk. +Swapping - Taking a page in memory and writing to disk. Swap File - specific file on disk that the pages get written to. Another solution is a swap space partition. @@ -125,9 +125,9 @@ Step 2: Flush Translation Lookaside Buffer (TLB) **BUT** with ASID or PCID (intel) may not be necessary * Used to identify which process an entry is from * Address space identifiers (ASID) assigned dynamically -* interactive processes don't get ASIDs +* Interactive processes don't get ASIDs * ASID's are short, too short to identify all processes -* stored in a data structure and optimized for cache usage +* Stored in a data structure and optimized for cache usage Step 3: Choose next process (scheduler's job) @@ -168,11 +168,11 @@ Round Robin (**IF** new processes sent to the back of the queue) Why not any other scheduler? -FCFS: wait time = sum of runtime of all processes on queue +FCFS: wait time ≤ sum of runtime of all processes on queue -SJF/PSJF: wait time = ∞ if shorter jobs keep arriving +SJF/PSJF: wait time ≤ ∞ if shorter jobs keep arriving -Priority: waittime = ∞ if higher priority jobs keep arriving +Priority: waittime ≤ ∞ if higher priority jobs keep arriving @@ -216,9 +216,9 @@ Circular wait: There exists a cycle in the Resource Allocation graph ### Coffman Conditions Cont. -Mutual Exclusion: no two processes can hold the same resources at the same time +Mutual Exclusion: no two processes can hold the same resource at the same time -Hold and Wait: Once a resources is obtained, process holds it until finished +Hold and Wait: Once a resource is obtained, process holds it until finished No pre-emption: Nothing can make a process give up a resource @@ -320,7 +320,7 @@ UDP is used when data becomes stale quickly (e.g. audio/video streaming and DNS) -*What information is stored in an i-node? What file system information is not?* +*What information is stored in an inode? What file system information is not?*