diff --git "a/W11D1/W11D1\346\235\216\347\243\212\346\231\272.md" "b/W11D1/W11D1\346\235\216\347\243\212\346\231\272.md" new file mode 100644 index 0000000..ae952a1 --- /dev/null +++ "b/W11D1/W11D1\346\235\216\347\243\212\346\231\272.md" @@ -0,0 +1,30 @@ +# Virtual Machine +## Two Types Of VM: + ### Type1(Xen): +These types of virtual machines gives us complete system platform and gives the execution of the complete virtual operating system. Just like virtual box, system virtual machine is providing an environment for an OS to be installed completely. We can see in below image that our hardware of Real Machine is being distributed between two simulated operating systems by Virtual machine monitor. And then some programs, processes are going on in that distributed hardware of simulated machines separately. + + ### Type2(VMware): + While process virtual machines, unlike system virtual machine, does not provide us with the facility to install the virtual operating system completely. Rather it creates virtual environment of that OS while using some app or program and this environment will be destroyed as soon as we exit from that app. Like in below image, there are some apps running on main OS as well some virtual machines are created to run other apps. This shows that as those programs required different OS, process virtual machine provided them with that for the time being those programs are running. Example – Wine software in Linux helps to run Windows applications. + +## VM Security +### Previledged Instrctions: +privileged instructions just refers to the set of instructions that your ISA defines as privileged. That is, these instructions must be executed by a process running in ring 0. +### Sensitive Instrections: +Sensitive instructions are those that the hypervisor or virtual machine monitor (VMM) wants to trap and emulate to give an unmodified OS the illusion it owns its hardware resources, +i.e. to successfully virtualize and run an OS. + +Ideally, we want the set of sensitive instructions to equal that of privileged instructions, this allows us to trap and emulate using the existing hardware. + +## VM Memory +Bottleneck in VM: Have to do multiple pagetable translation in User OS can be done in software or in hardware. +### Shadow Page table (SPT) +Shadow page tables are used by the hypervisor to keep track of the state in which the guest "thinks" its page tables should be. The guest can't be allowed access to the hardware page tables because then it would essentially have control of the machine. So, the hypervisor keeps the "real" mappings (guest virtual -> host physical) in the hardware when the relevant guest is executing, and keeps a representation of the page tables that the guest thinks it's using "in the shadows," or at least that's how I like to think about it. +### Nested Page table(NPT) +Second Level Address Translation (SLAT), also known as nested paging, is a hardware-assisted virtualization technology which makes it possible to avoid the overhead associated with software-managed shadow page tables. + +## Other Implement of VM +### Para-virtualization (Syscall) +In computing, paravirtualization or para-virtualization is a virtualization technique that presents a software interface to the virtual machines which is similar, yet not identical, + to the underlying hardware–software interface. +### Full-virtualization +In this scenario, data is completely abstracted from the underlying hardware by the virtualization layer. In this technique guest, OS is unaware that it is a guest and hypervisor translate all OS calls on-the-fly. It provides flexibility and no hardware assistance or modification is required. \ No newline at end of file diff --git "a/W3D1/W3D1\346\235\216\347\243\212\346\231\272.md" "b/W3D1/W3D1\346\235\216\347\243\212\346\231\272.md" new file mode 100644 index 0000000..4e9a832 --- /dev/null +++ "b/W3D1/W3D1\346\235\216\347\243\212\346\231\272.md" @@ -0,0 +1,44 @@ +# Topic: Race Conditions +>Situations where two or more processes are reading or writing some shared data and the final result depends on who runs precisely when, are called **race conditions**. +The part of the program where the shared memory is accessed is called the **critical region** or critical section. +### Four conditions to hold to have a good solution: +1. No two processes may be simultaneously inside their critical regions. +2. No assumptions may be made about speeds or the number of CPUs. +3. No process running outside its critical region may block any process. +4. No process should have to wait forever to enter its critical reg +## Race Condistions Managing Strategies: +### 1. Disabling Interrupts +>**Disableing interrupts** solution is to have each process disable all interrupts just after entering its critical region and re-enable them just before leaving it. With interrupts disabled, no clock interrupts can occur and with interrupts turned off the CPU will not be switched to another process. + +Limitations: +- dangerous +- single-processor only +- not available in user mode + +### 2. Busy Waiting +>Continuously testing a variable until some value appears is called **busy waiting**. It should usually be avoided, since it wastes CPU time. Only when there is a reasonable expectation that the wait will be short is busy waiting used. A lock that uses busy waiting is called a **spin lock**. +#### Examples: +1. Strict Alternation +![strict](./src/Critical.png) +Limitation: +Violating condition 3 when a process hold the lock while not touching critical region and block other progress +2. Peterson's Solution +![peterson](./src/Peterson.png) +3. TSL +>TSL instruction reads the contents of the memory +word lock into register RX and then stores a nonzero value at the memory address +lock. The operations of reading the word and storing into it are guaranteed to be +indivisible—no other processor can access the memory word until the instruction is +finished. The CPU executing the TSL instruction locks the memory bus to prohibit +other CPUs from accessing memory until it is done. It is an implemetation supported by hardware. + +![TSL](./src/TSL.png) +### 3. Sleep and Wake +>Sleep is a system call that causes the caller to block, that is, be suspended until another process wakes it up. The wakeup call has one parameter, the process to be awakened. Alternatively, both sleep and wakeup each have one parameter, a memory address used to match up sleeps with wakeups. Still, the sleep and wake can still encounter race condition as it does in the case of the Produder-Consumer promblem : + +![pro&con](./src/pro%26con.png) +Race condition can occur because access to *count* is unconstrained. The buffer is empty and the consumer has just read count to see if it is 0. At that instant, the scheduler decides to stop running the consumer temporarily and start running the producer. The producer inserts an item in the buffer, increments count, and notices that it is now 1. Reasoning that count was just 0, and thus the consumer must be sleeping, the producer calls wakeup to wake the consumer up. +Unfortunately, the consumer is not yet logically asleep, so the wakeup signal is +lost. When the consumer next runs, it will test the value of count it previously read, +find it to be 0, and go to sleep. Sooner or later the producer will fill up the buffer +and also go to sleep. Both will sleep forever. diff --git a/W3D1/src/Critical.png b/W3D1/src/Critical.png new file mode 100644 index 0000000..7f536b6 Binary files /dev/null and b/W3D1/src/Critical.png differ diff --git a/W3D1/src/Peterson.png b/W3D1/src/Peterson.png new file mode 100644 index 0000000..f71e1c9 Binary files /dev/null and b/W3D1/src/Peterson.png differ diff --git a/W3D1/src/TSL.png b/W3D1/src/TSL.png new file mode 100644 index 0000000..bdabc9c Binary files /dev/null and b/W3D1/src/TSL.png differ diff --git a/W3D1/src/pro&con.png b/W3D1/src/pro&con.png new file mode 100644 index 0000000..22a53bb Binary files /dev/null and b/W3D1/src/pro&con.png differ diff --git "a/W7D1/W7D1\346\235\216\347\243\212\346\231\272.md" "b/W7D1/W7D1\346\235\216\347\243\212\346\231\272.md" new file mode 100644 index 0000000..06be095 --- /dev/null +++ "b/W7D1/W7D1\346\235\216\347\243\212\346\231\272.md" @@ -0,0 +1,35 @@ +# File System's Challenges + +## Limitation of speed of disks + - Solution: block cache, page cache (both in memory) + + ### block cache: + Disk blocks act like a file system and store data as blocks in memory. (hash: facility + block id) + + ### page cache: + A page cache is a transparent cache for the pages originating from a secondary storage device. The operating system keeps a page cache in otherwise unused portions of the main memory (RAM), resulting in quicker access to the contents of cached pages and overall performance improvements. + +- Adaptability + +- Virtualization + + +## Task struct + +- file struct + + - meta data + + - fd + +### Inner Struct: +> Dentry (directory entry): + A dentry is the glue that holds inodes and files together by relating inode numbers to file names. Dentries also play a role in directory caching which, ideally, keeps the most frequently used files on-hand for faster access. File system traversal is another aspect of the dentry as it maintains a relationship between directories and their files. + +> d_inode: + Accelarate mapping from file path + name to i_node in memory + +> f_inode, i_sb ( Points to superblock) + + +