# 111-2 NTU-OS Note
## Chapter 4 - Thread
### - Thread
- The smallest sequence of programmed instructions that can be handled independently by the scheduler.
---
### - Concurrent System
- Supports more than 1 task by allowing all the tasks to make progress.
### - Parallel Sysyem
- Performs more than 1 task simultaneously.
---
### - Data Parallelism
- Splits data into smaller portions -> Each process performs the <font color="blue">same task</font>
### - Task Parallelism
- Splits tasks into smaller portions -> Each process performs a <font color="blue">diffenent task</font>.
---
### - User Thread
- Supported above the kernel and managed without kernel support.
### - Kernel Thread
- Supported and managed directly by the kernel.
---
### - Many-to-One Model (User-Level Threading)
- Thread management is done by the thread library -> <font color="blue">Efficient</font>.
- Thread block will cause the entire process to **block**.
- Threads **cannot run** in parallel on multiprocessors.
### - One-to-One Model (eg. Linux) (Kernel-Level Threading)
- Large number of kernel threads -> <font color="blue">Overhead</font>
- Thread block will **not** cause the entire process to block.
- Threads **can run** in parallel on multiprocessors.
### - Many-to-Many Model (Hybrid threading)
- User threads ≤ kernel threads.
- Limiting the number of threads -> <font color="blue">Less Overhead</font>
- Thread block will not cause the entire process to block.
---
### - Thread Library
- Provides an API for creating and managing threads.
User-Level -> Local function
Kernel-Level -> System call
---
### - Impliciting Threading
- An threading enviroment that programmers only design function logics but **do not manage the threads**.
### - Expliciting Threading
- An threading enviroment that programmers design function logics and **also manage the threads**.
---
### - Thread Pool
- Threads already exist. -> <font color="blue">Efficient</font>
- Limit the # of threads.
- Customize the way to run a task.
### - Fork-Join
- Synchronous model -> Explicit Threading
- Candidate for implicit threading
### - OpenMP
- A set of computer directives.
- Parallel programming in shared memort env.
- Create as many threads as there are.
### - Grand Central Dispatch (GCD)
- macOS / iOS
- Dispatch queue (Serial / Concurrent)
### - Intel Threading Building Blocks (TBB)
- Template Library
---
### - Signal
- Synchronous signal -> deliver to itself
- Asynchronous signal -> diliver to other process
----
### - Thread Cancellation
- Asnychronous cancellation -> Immediate terminate (May not free its resources well)
- Deferred cancellation -> Wait for **cancellation point**
---
### - Thread Local Stroage (TLS)
- Each thread has its own copy of certain data.
- Visible across functions (≠ Local var.)
- Unique to each threads (≠ static var.)
---
### - Lightweight Process (LWP)
- An intermediate data structure places between user and kernel threads, acting as a virtual processor.
### - Upcall
- A procedure that the kernel inform an application about certain events.
- Handled by **upcall handler**
- Must run on a virtual processor
---
## Chapter 9 - Main Memory
### - Address Protection
- Base Register -> min. legal physical addr.
- Limit Register -> size of the range
- Register can **only be loaded by the OS**
### - Address Binding
- Source program -> symbolic addr.
- Compiler -> relocatable addr.
- Linker/Loader -> absolute addr.
---
### - Logical Address (Virtual Address)
- An address generated by the CPU
### - Physical Address
- An address seen by the memory unit (the one loaded into the memory-address register)
### - Logical Address space
- Set of all logical address generated by a program
### - Physical Address space
- Set of all physical address corresponding to these logical address
---
### - Memory-Management Unit (MMU)
- A **hardware device** performing run-time mapping from virtual to physical addr.
- Relocation register (old: base register)
---
### - Dynamic Loading
- A routine is not loaded until it is called. -> **Better memory-space utilization**
- All routine are kept on a disk in a relocatable load form.
- **No special support** from the OS
### - Dynamic Linking
- Linking is postponed until execution time -> **decrease size**, enable **sharing**/**updating**
- **Dynamically Linked libraries(DLLs/shared lib.)**: System lib. that are linked to user programs when programs are runnning.
- **Require special support** from the OS
---
### - Memory Allocation
- [x] First Fit: First hole that is big enough
- [x] Best Fit: Smallest hole that is big enough
- [ ] Worst Fit: Largest hole
---
### - Internal Fragmentation
- The size difference between the allocated memory and the requested memory.
### - External Fragmentation
- The total space is enough for the request but the space is not contiguous.
### - 50% rule
- Given N allocated blocks, 0.5N will be lost to fragmentation.
### - Solution to fragmentation
- Compaction: Shuffle the memory.
- **Paging**: Permits the physical address space to be noncontiguous.
---
### - Pages
- Fixed-sized blocks of logical memory
### - Frames
- Fixed-sized blocks of physical memory
### - Frame Table
- A single, system-wide data structure having 1 entry for each physical frame.
### - Page Table
- A per-process data structure.
- Implmentation:
- [ ] A set of reg. -> Efficient, but longer context switch
- [X] **Page-table base reg.(PTBR)** -> Points to page table stored in main memory
---
### - Translation Look-Aside Buffer (TLB / Associative memory)
- A special, small, fast-lookup hardware cache.
- **Address-space identifiers(ASIDs)** -> Identify each process, allowing TLB to contain entries of multiple processes.
### - Effective Memory-Acess Time
- $t \times \text{Hit Ratio} + 2t*(1-\text{Hit Ratio})$
---
### - Paging Protection
- Valid-Invalid Bit
- Page-table length reg.(PTLR)
---
### - Paging Structure
- **Hierarchical Paging**: Divide the page number and page the page table, contaning the associated *physical address*.
- **Hashed Page Table**: Each entry contians a linked list of elements.
- **Inverted Page Table**: One entry for each real frame of memory contaning the associated *virtual address*.
- **Solaris on SPARC**: 2 hashed page table.
---
### - Swapping
- **Standard swapping**: Move **entire process** between memory and backing store.
- Make total virtual address space $>$ physical memory space possible.
### - Paging
- **Swapping with paging**.
---
## Chapter 5 - CPU scheduling
### - CPU-burst distribution
- CPU Burst
- computation
- I/O Burst
- wait for I/O
- I/O-bound program
- more I/O event
- has many short CPU bursts
- read memory by DMA (no CPU intervene)
- CPU-bound program
- more CPU event
- have a few long CPU bursts
---
### - Preemptive vs Nonpreemptive
- nonpreemptive scheduling
- only when a process terminated or be changed to waiting state, scheduler select new process
- preemptive scheduling
- when a process switching to ready state, also trigger scheduling.
- may result in race condiction when data are shared
---
### - Dispatcher
- definition
- who give control of the CPU to the process selected,involving
- switch context
- switch to user mode
- jump to proper location to restart that program
- Dispatcher latency
- time for stopping previous process and start another running
- = Save state in $PCB_0$ + Restore state from $PCB_1$
---
### - Scheduling Criteria
- Maximize CPU utilization
- Maximize throughtput
- Number of processes complete their execution per time unit
- Minimize turnaround time
- Amount of time to execute a particular process (finished)
- Minimize waiting time
- Amount of time a process in ready queue
- Minimize response time
- from a request was submitted until response is produced
---
### -Scheduling Algorithm
- FCFS
- **Convoy effect** : All other process wait one big process
- One CPU bound with many I/O bound processes
- Nonpreemptive
- SJF
- Nonpreemptive
- find min(the length of its next CPU birst)
- optimal for **minimizing avg. waiting time**
- preemptive version called shortest-remaining-time-first
- Difficulty : can't predict next CPU burst
- Prediction : exponential averaging
- $\alpha$ 越大,越相信 last actual length
- Shortest-Remaining-Time-First
- Premmptive version of SJF
- RR
- Each process gets **time quantum** q
- q large = FCFS
- q small : too many context switches
- better response time, worse turnaround time than SJF
- q should be large compared to context switch
- 80% of CPU bursts $\le q$
- Priority Scheduling
- Every process has priority number, small means high priority
- Starvation : low priority one may never execute
- Aging : As time progresses, increase the priority of the process waiting
- w/ RR
- same priority run round-robin
- Multilevel Queue Sccheduling
- Have separate queue for each priority
- Prioritization based upon process type
- Each queue might have its own scheduling algorithm
- Multilevel Feedback Queue Sccheduling
- A process can move between queues
- should define when to upgrade/demote
- Aging can be implemented using multilevel feedback queue
---
### - Thread Scheduling
- Process-contention scope(PCS)
- user thread 搶 LWP
- scheduling competition is within per process
- System-contention scope(SCS)
- kernel thread 搶 CPU
- scheduling competition is among all threads in the system
- one-to-one model using SCS only
---
### - Multiple-Processor Scheduling
- Multiprocess may be
- Multicore CPUs
- Multithreaded cores
- Non-Uniform Memory Access system (NUMA)
- Heterogeneous multiprocessing
### - Asymmetric Multiprocessing
- All scheduling decision, system activities are handled by a **single processor (master server)**
- the other processors execute only user code
- Advantage
- No need for data sharing
- Disadvantage
- master server becomes a potential bottleneck
### - Symmetric Multiprocessing (SMP)
- Each process is self scheduling
- Two strategies
- All thread in a common ready queue
- Race condition -> locking
- Processor have its own private queue
- Workloads unbalance -> balancing algorithm
---
### - Multithreaded Multicore System
- Multicore processor place multiple processor cores on same physical chip
- faster
- consume less power
- memory stall : when access memory, should wait for the data become avalible, cost time
- Multithreaded Multicore System
- each core has more than 1 **hardware threads**
- if one thread has a **memory stall**, switch to another
- CMT(chip multithreading)
- assigns each core multiple hardware threads
- increase performance through parallel processing
- Two levels of scheduling
- First L(OS) choose which software thread to run on each hardware thread(logical CPU)
- Second L choose which hardware thread to run on each core
- Not necessarily mutually exclusive
---
### - Load Balancing
- Push migration
- A specific task periodically check the load on each processor
- moving thread from busy to idle processors
- Pull migration
- idle processor pulls task from busy processor
### - Processor Affinity
- change processor may lose contents in the cache
- Soft affinity
- Attempt to keep a thread running on same processor
- No guarantee
- Hard affinity
- Allow a process to specify a set of processors it may run on
- NUMA
- assign memory close to the CPU the thread is running on
---
### - HMP(Heterogeneous Multiprocessing)
- Incorporating different types of cores and/or specialized hardware in a single system
- Big cores consume greater energy, sholud only be used for short periods of time
- Little cores use less energy, can used for longer period
---
### - Real Time CPU Scheduling
- Soft real time system
- critical real time task have high priority
- no guarantee when task will be scheduled
- Hard real time system
- task must be serviced before deadline
### - Minimizing Latency
- Event latency
- time from an event occurs to when it's servuced
- Interrupt latency
- Dispatch latency
- dispatch phase
- conflict phase
- Preemption of any process running in kernel mode
- Release by low-priority process of resources needed by high-priority processes
### - Rate-Monotonic Scheduling
- $priority = 1/period$
- shorter period, higher priority
- Not optimal solutuion
### - EDF(Earliest Deadline First) Scheduling
- The earlier the dealine, the higher the priority
### - Proportional Share Scheduling
- A process may receive $(N_{i}/T)$ shares where $N_{i}<T$
- if $\Sigma N_{i} + N_{new} > T$, the new process will be rejected
---
### - Linux Scheduling
- Default Scheduling
- use Completely Fair Scheduler
- priority 100~139(nice value -20~19)
- CFS identifies a **targeted latency**
- the time interval make every task run at least once
- CFS record how long each task has run in `vruntime`
- use vruntime as the value in RBtree
- Real time Scheduling
- priority 0~99(higher priority)
- NUMA-Aware Load Balancing
- Scheduling domain
- A set of cores can be balanced against one another
- organized by what they share(i.e., cache memory)
### - Windows Scheduling
- vaiable class:1~15
- realtime class:16~31
- memory-management thread:0
- UMS(user mode scheduling)
- Allow aplications to create and manage threas independently of the kernel
### - Solaris Scheduling
- Six classes
- RR for same priority threads
---
### - Algorithm Evaluation
### - Deterministic Modeling
- Analytic evaluation
- Calculate minimum avg waiting time for each algorithm
- Require exact number for input and apply only to those input
### - Queueing Models
- Describe the arrival of processes as well as CPU and I/O bursts probabilistically
- Little’s law : average queue length = arrival rate * waiting time in queue
### - Simulation
- Random testcase and do dimulation to analyze
### - Implemetation
- High cost, high risk, Environments vary
---
## Chapter 11 - Mass-Storage Systems
### - Hard Disk Drives (HDD)
- Component
- platter
- track
- sector: Smallest unit of transder
- cylinder
- Access time
- Seek time + Rotational latency
- I/O time
- Access time + transfer time + controller overhead
- Head crash
- Disk head making contact with the disk surface
---
### - Nonvolatile Memory (NVM)
- Solid-state Disk (SSD) : Flash-memory based NVM
- Pros
- More reliable: no moving parts
- Faster: no rotational time
- Less power consumption
- Cons
- Expensive
- Less capacity
- Read/Write in 'page' increment
- Data cannot be overwritten
- Have to be erased first
- Occur in a "block" increment that is serveral pages in size
- Slow
- Drive writes per day (DWPD)
- Flash translation layer (FTL)
- Track which logical blocks contain valid data
- Garbage collection
- Copy good data away to free blocks for writing
- Allocate **overprovisioning space** to provid space for garbage collection
- Helps **wear leveling**
- Place data on less-erased blocks so that subsequent erases will happen on these blocks
---
### - Volatile Memory
- RAM drives
- Carves out a section of the system's DRAM
- Used as raw block devices
- File systems are created on them
- High-speed temp. space
- Why RAM since having buffer&cache?
- RAM drives allows user to place data (Buffer/Cache allocated by programmer/OS)
---
### - Connection method
- System bus or I/O bus
- Attach secondary storage device to a computer
- ATA, SATA, SAS, USB, FC, NVM...
- NVMe directly connects the device to the system PCI bus
- Controllers (HBA: host-bus adapters)
- Special electonic processors carry out data transfer on a bus
- host controller: at the computer end of the bus
- Computer place command to it using memory-mapped I/O ports
- device controller: built into each storage device
- Have bulit-in cache
- Data transfer
- At the drive: cache <-> storage media
- To the host: cache <-> host DRAM via DMA(Direct memory-access)
---
### - Address Mapping
- Logical Blocks
- Storage device addressed as 1-D array of logical block
- Smallest unit of transfer
- Mapping order:
1. Through that track
2. Through the rest of the tracks on that cylinder
3. Through the rest of the cylinders from outermost to innermost
- Logical block address (LBA)
- Algo. friendly
---
### - HDD Scheduling
- Bandwidth
- B = Total number of bytes transferred
- T = Total time between the first request for service and the completion of the last transfer
- $Bandwidth = B / T$
- No knowledge of head location and physical block location
- Assume LBAs close together equate to physical block proximity
- FCFS
- SCAN
- Elevator algo.
- Start from one end to another, then reverse
- Heavier density of req. is at the other end of the disk -> More wait time
- C-SCAN
- Start from one end to another, then return to beginning
- More uniform wait time than SCAN
---
### - NVM Scheduling
- Simple FCFS commonly
- Fast Random-access I/O
- **IOPS** (I/O operations per second)
- HDD: hundreds IOPS
- SSD: hundreds of thousands IOPS
- Write aplicfication
- 1 write cause garbage collection and many writes
---
### - Error Detection/Correction
- Error detection
- Parity bit
- Checksum
- Mask/Modular on fixed length words
- Cyclic redundancy check (CRC)
- common in networking
- use hash function to dectect multiple-bit error
- Error-correction code (ECC
- Not only detect but correct
- soft error: recoverable
- hard error: signaled but noncorrectable
---
### - Storage Device Management
- Low level formatting
- Divide disk into sectors(choose size)
- 出廠時已完成
- OS work:
- Partition
- Partition the device into groups of blocks/pages
- Mounting make the file system available for system/user
- Volume
- C槽, D槽
- 其實都在同一顆disk
- Logical Formatting
- or creation of a file system
- store the initial file system data structures on to device
- group blocks into "cluster" for efficiency
- Device I/O: via blocks
- file system I/O : via clusters
- Boot block
- Bootstrap
- stored in NVM flash memory firmware
- mapped to a known memory location
- bootstrap loader program bring in full bootstrap program from secondary device
- Boot blocks
- store full bootstrap preogram at a fixed location
- Boot disk (System disk)
- device tha thas a boot partition
- Master boot record (MBR)
- Contain
- boot code
- A table listing partitions of the drive
- A flag indicatin which partition the system is to be booted from
- Steps:
1. Run the code in the system's firmware
2. Direct to read the boot code from MBR
3. Read the first sector/page from the boot partition which directs to the kernel
- Bad blocks
- Sector sparsing
- 替換
- Sector slipping
- 平移
---
### - Swap Sapce Management
- Swapping(process) or Paging(pages) from DRAM to secondary device
- OS's management:
- Can be in raw partition or a file within a file system
- slower than DRAM
- placed on separate storage devices
---
### - Storage Attachment
- Host-Attached Storage
- storage accessed through local I/O ports
- SATA
- USB / Thunderbolt
- Fibre Channel (FC)
- High-end worstations and servers
- Network-Attached Storage (NAS)
- storage accessed across network
- via remote-procedure-call interface
- Raw block device
- Cloud Storage
- storage accessed across network
- API based
- Data center
- Storage Area Networks and Storage Arrays
- A network connecting servers and storage units
- Client <-(LAN/WAN)-> Server <-(SAN)-> Storage Array
- Flexible
- FC is the most common SAN interconnect
---
### - RAID Structure
- Redundant arrays of independent(inexpensive) disks (RAID)
- Provide reliability via redundancy with multiple disk drives
- Incresase **mean time to data lost**
- Mean time between failures (MTBF)
- Mean time to repair (MTTR)
- If n-mirroed drive system:
- Mean time to data lost = $(MTBF)^n$ / $(n!*(MTTR))$
- Improve perfomance via parallelism
- Data striping: splitting across multiple drives
- bit-level striping
- block-level striping
- Goals
- increase throughput of multiple small accesses by load balancing
- resuce response time of large accesses
- RAID levels
- RAID 0: Non-Redundant Striping
- RAID 1: Mirrored(Shadowing) disk
- RAID 4: 一個disk專門記parity
- RAID 5: parity分散至多個disk
- RAID 6: parity+Q(other information)分散至多個disk
- RAID 0+1: 先 Stripe 再 Mirror
- RAID 1+0: 先 Mirror 再 Stripe
- Other Feature
- Snapshot
- a view of the file system before last update took place
- Replication
- automatic duplication wirtes between separate sites for redundancy and disater recovery
- Hot spare
- 備用drive
- Problem
- Does not always assure the data are available
- Lack flexibility
- ZFS involves pools of storage
- Object storage
- start with a storage pool and place objects in that pool
- computer-oriented
- A typical sequence:
- Create an object within the pool and recieve an ID
- Access the object via the ID
- Delete the object via the ID
- Management software determing where to store object
- Horizontally scalable
- easy to add capacity
- Content addressable
- stores unstructured data
---
## Chapter 12 - File-System Interface
### - File
- **Logical storage unit** defined by the OS, is an abstract data type
- File Attribute
- Name, Identifier, type, size, location, protection, timestamps, user identification, extended file attributes...
---
### - Open File
- Open-file table
- contain information about all open files
- Components
- File pointer (Current-file-position pointer)
- The last read-write location
- file-open count
- Location of the file
- Access rights
---
### - Locking Open Files
- Share lock
- reader lock
- Exclusive lock
- writer lock
- Mandatory file-locking
- Force using the lock
- Advisory file-locking
- up to developers
---
### - File Structure
- Example
- None
- Sequence of words, bytes
- Simple record structure
- Lines, fixed length, variable length
- Complex Structure
- Formatted socument, relocatable load file
- Who decides
- OS
- Program
---
### - Access method
- Sequential Access:
- information is processed in order
- read_next()
- write_next()
- reset()
- Direct Access (Relative Access)
- A file is made up of fixed-length **logical records**
- Allow programs to read/write records in no order
- read(n)
- write(n)
- position(n)
- n = **relative block number**
- Usage of relative block number allows OS to decide where the file should be placed
- Allocation problem
- Other:
- Indexed Sequential-access
- Construction of an index for the file
---
### - Directory Structure
- Contain information about all files
- Directory entry
- consists of file's "name" and its "unique identifier"
- Single-Level Directory
- All file are contained in the same directory
- Naming problem
- Two-Level Directory
- A separate directory for each user
- **Path name**
- UserName + FileName
- Search procedure and path
- Tree-Structured Directories
- A directory contains a set of file or subdirectories
- use bit to identify type (0:file, 1:dir)
- Current working directory
- Absolute/Relative path name
- Handle Deletion of a directory?
1. No deletion unless directrory is empty
2. Delete all files and sub-directories
- Acylic-Graph Directories
- Allow to share sub-directories and files
- Link
- A pointer to another file or sub-directory
- Distinct file name may refer to same file
- Removing file may leave dangling pointer
- Preserve the file until all references to it are deleted
- General Graph Directory
- Might result in infinite loop
- reference count may not be 0 even when it is no longer possible to refer to
---
### - Protection
- Access-control list (ACL)
- specifies user names and the types of access allowed
- Linux classification
- Owner, group, other
- 3 bits: RWX
---
### - Memory-mapped Files
- Allow a part of the virtual address space to be logically associated with the file
- Step1 - Page fault to bring in the page
- Step2 - Subsequent reads/writes treated as routine memory access
- Step3 - When the file is closed, all the memory-mapped data are written back to the file on secondary storage
- Allow multiple processed to map the same file to allow sharing of data
- Modifying shared data can be seen by others
- Support copy-on-write
---
## Chapter 14 - File-System Implementation
### - File-System Structure
- Layered File System

- Structure:
- **Devices**: Secondary裝置
- Hardware Controller
- **I/O control**: 接收Basic File System的指令然後轉換成hardware controller的指令
- Devive driver
- translator
- interrupt handler
- **Basic File System**: 向device driver發指令讀寫blocks
- Issue commands to the drive based on logical block address
- Manage memory buffers and caches
- **File-organization module**: 做logical block跟physical block的mapping
- Knows file with its logical blocks (numbered from 0(1) ~ N)
- free-space manager
- **Logical file system**: 中介站,只知道metadata
- Handle metadata which includes all of the strucutre except the actual data
- Manage the directory structure
- Maintain via **FCB** (file-control blocks (i-node))
- **Application Program**
- Pros:
- Minimize duplication of codes
- Can share **Basic File System** and **I/O control**
- Each file system can have its own **Logical file system** and **file-organization module**
- Cons:
- More OS overhead
---
### - Structures on File System
- Boot control block(per volume)
- Contains info to boot an OS from that volume
- If the disk doesn't contain an OS, this block may be empty
- Typically the first block of a volume
- UFS: boot block
- NTFS: partition boot sector
- Volume control block(per volume)
- Contains volume detail
- \# of blocks, size of blocks, free-block count, free-block pointers, free-FCB count, FCB pointers
- UFS: Superblock
- NTFS: master file table
- Directory Structure(per file system)
- Organize the file
- UFS: include file names and associated inode numbers
- NTFS: stored in master file table
- FCB(per file)
- Contains many details about the file
- Has an unique identifier number to associate with a directory entry
- UFS: i-node
- NTFS: stored within master file table
---
### - In-Memory File-System Structures

- Mount table
- Contains information about each mounted volume
- Directory-structure cache
- Hold the directory info of recently accessed directory
- System-wide open-file table
- Contains copy of the FCB of each open file
- Per-process open-file table
- Contains pointer to the entries in the system-wide open-file table
- Buffers
- Hold file-system blocks when they are being read/write to a file system
---
### - Directory Impementation
- Linear List
- Slow
- Sorted List allows Binary-Search
- Hash table
- Faster
- Need provision for collisions
---
### - Allocation Method
- Contiguous Allocation
- 
- External fragmentation
- One strategy: copy an entire FS away then copy it back
- Compaction
- Extent-Based System
- Overestimate the amoung of the space needed
- If not big enough, another chunk of contiguous space(extent) is added
- Location of a file:
- A location
- A block count
- A link to the first block of the next extent
- Linked Allocation
- 
- File is a linked list of storage blocks
- Directory contains a pointer to the first block and last block
- Each block contains a pointer to next block
- No externam fragmentation
- Inefficient to find i-th block
- Need extra space for pointer
- File-Allocation Table (FAT)
- 
- A section of storage at the beginning of each volume is set asideto contain the table
- Save all links(pointers) in a table
- The table has one entry for each block and is indexed by block number
- Pros
- Less direct-access time
- Cons
- Probably more disk head seeks
- Indexed Allocation
- 
- Bring all pointers into the index block
- Pros
- No external fragmentation
- Cons
- More space than linked allocation
- Schemes of Index Blocks
- Multilevel Index

---
## Chapter 15 - File-System Internals
### - File System Mounting
- mount point
- the location within the file structure where the file system is to be attached
- operation
- The OS is given the device name and the mount poin
- The OS verifies that the device contains a valid file system
- Ask the device driver to read the device dir
- Verify that the directory has the expected format
- The OS notes in its directory structure that a file system is mounted
### - Partition
- raw : having no file system
- cooked : having a file system
- root partiotin
- selected by the boot loader
- mounted at boot time
- Contain the operating-system kernel and sometimes other system file
---
### - File Sharing
- The owner and group IDs of a given file (or directory) are stored with the other file attributes
---
### - Virtual File System
- Separate file-system-generic operations from their implementation by defining a clean VFS interface
- Provide a mechanism for uniquely representing a file throughout a network
- vnode contains a numerical designator for a network-wide unique file
- uniqueness is important
- Four object types
- inode object: represents an individual file
- File object: represent an open file
- Superblock object: represent an entire file system
- Dentry object: represent an individual directory entry
---
### - Remote File Systems
- Networking allows the sharing of data in the form of files
- ftp(File Transfer Protocol)
- used for both anonymous and authenticated access
- DFS(distributed file system)
- Remote directories are visible from a local machine
- World Wide Web
- A browser is needed to gain access to the remote files
- google drive...
### - Client - Server Model
- The machine containing the files is the server
- The machine seeking access to the files is the clien
- Security result in many challenge
- File operation requests are sent on behalf of the user across the network to the server via the DFS protocol
### - Distributed Information System
- Also known as **distributed naming services**
- Provide unified access to the information needed for remote computing
- DNS
- NIS
- CIFS
- LDAP
### - Failure Models
- Local
- drive, directory structure
- Disk-controller, cable, or host adapter
- User or system-administrator failure
- Remote
- Network or server failure
- Networking implementation issues
- Recover
- If both ends maintain **state information**
---
### - UNIX Semantics
- writes are visible immediately to others
- causes delay
- allows users to share the pointer of current location into the file
### - Session Semantics
- writes are not visible immediately to others
- Once a file is closed, the changes made to it are visible only in sessions starting later
### - Immutable-Shared-Files Semantics
- Once a file is declared as shared by its creator, it cannot be modified
- file name may not be reused
- file contents may not be altered
---
### - Cascading mounts

### - The Mount Protocal
- Establish the initial logical connection between a server and a client
- changes only the user's view and does not affect the server side
### - The NFS Protocal
- Provide a set of RPCs for remote file operations

---