๐ ํ์ผ์์คํ
๐ทFile System
๐ธ File and File System
- File
- โA named collection of related informationโ
- ์ผ๋ฐ์ ์ผ๋ก ๋นํ๋ฐ์ฑ์ ๋ณด์กฐ ๊ธฐ์ต ์ฅ์น์ ์ ์ฅ
- ์ด์์ฒด์ ๋ ๋ค์ํ ๊ธฐ์ต ์ฅ์น๋ฅผ file์ด๋ผ๋ ๋์ผํ ๋ ผ๋ฆฌ์ ๋จ์๋ก ๋ณผ ์ ์๋๋ก ํด์ค
- Operation
- create, read, write, reposition (Iseek): ํ์ผ์ ์์น๋ฅผ ์์ ํด์ฃผ๋ ์ฐ์ฐ, delete, open, close ๋ฑ
- File attribute (ํน์ ํ์ผ์ ๋ฉํ ๋ฐ์ดํฐ)
- ํ์ผ ์์ฒด์ ๋ด์ฉ์ด ์๋๋ผ, ํ์ผ์ ๊ด๋ฆฌํ๊ธฐ ์ํ ๊ฐ์ข ์ ๋ณด๋ค
- ํ์ผ ์ด๋ฆ, ์ ํ, ์ ์ฅ๋ ์์น, ํ์ผ ์ฌ์ด์ฆ
- ์ ๊ทผ ๊ถํ(์ฝ๊ธฐ/์ฐ๊ธฐ/์คํ), ์๊ฐ(์์ฑ/๋ณ๊ฒฝ/์ฌ์ฉ์), ์์ ์
- File System
- ์ด์์ฒด์ ์์ ํ์ผ์ ๊ด๋ฆฌํ๋ ๋ถ๋ถ
- ํ์ผ ๋ฐ ํ์ผ์ ๋ฉํ๋ฐ์ดํฐ, ๋๋ ํ ๋ฆฌ ์ ๋ณด ๋ฑ์ ๊ด๋ฆฌ
- ํ์ผ ์ ์ฅ ๋ฐฉ๋ฒ ๊ฒฐ์
- ํ์ผ ๋ณดํธ ๋ฑ
๐บ Directory and Logical Directory
- Directory
- ํ์ผ์ ๋ฉํ๋ฐ์ดํฐ ์ค ์ผ๋ถ๋ฅผ ๋ณด๊ดํ๊ณ ์๋ ์ผ์ข ์ ํน๋ณํ ํ์ผ
- ๊ทธ ๋๋ ํ ๋ฆฌ์ ์ํ ํ์ผ ์ด๋ฆ ๋ฐ ํ์ผ attribute๋ค
- operation
- Search for a file, create for a file, delete for a file
- list a directory, rename a file, traverse the file system
- Partition (=Logical Disk)
- ํ๋์ ํํฐ์ ์์ ์ฌ๋ฌ๊ฐ์ ํํฐ์ ์ ๋๋๊ฒ ์ผ๋ฐ์ ์
- ์ฌ๋ฌ ๊ฐ์ ๋ฌผ๋ฆฌ์ ๋์คํฌ๋ฅผ ํ๋์ ํํฐ์ ์ผ๋ก ๊ตฌ์ฑํ๊ธฐ๋ ํจ
- ๋ฌผ๋ฆฌ์ ๋์คํฌ๋ฅผ ํํฐ์ ์ผ๋ก ๊ตฌ์ฑํ ๋ค ๊ฐ๊ฐ์ ํํฐ์ ์ file system์ ๊น๊ฑฐ๋ swapping ๋ฑ ๋ค๋ฅธ ์ฉ๋๋ก ์ด์ฉํ ์ ์์
โ๏ธ open()
์ ๊ณผ์
Retrieves metadata from disk to main memory
- open(/a/b/c)
- ๋์คํฌ๋ก๋ถํฐ ํ์ผ c์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ๋ก ๊ฐ์ ธ์ด
- ์ด๋ฅผ ์ํ์ฌ directory path๋ฅผ search
- ๋ฃจํธ ๋๋ ํ ๋ฆฌ โ/โ๋ฅผ openํ๊ณ ๊ทธ ์์์ ํ์ผ โaโ์ ์์น ํ๋
- ํ์ผ โaโ๋ฅผ openํ ํ readํ์ฌ ๊ทธ ์์ ํ์ผ โbโ์ ์์น ํ๋
- ํ์ผ โbโ๋ฅผ openํ ํ readํ์ฌ ๊ทธ ์์ ํ์ผ โcโ์ ์์น ํ๋
- ํ์ผ โcโ๋ฅผ openํ๋ค.
- Directory path์ search์ ๋๋ฌด ๋ง์ ์๊ฐ ์์
- Open์ read์ write์ ๋ณ๋๋ก ๋๋ ์ด์ ์
- ํ ๋ฒ openํ ํ์ผ์ read / write ์ directory search ๋ถํ์
- Open file table
- ํ์ฌ open๋ ํ์ผ๋ค์ ๋ฉํ๋ฐ์ดํฐ ๋ณด๊ด์ (in memory)
- ๋์คํฌ์ ๋ฉํ๋ฐ์ดํฐ๋ณด๋ค ๋ช ๊ฐ์ง ์ ๋ณด๊ฐ ์ถ๊ฐ
- Openํ ํ๋ก์ธ์ค์ ์
- File-Offset : ํ์ผ ์ด๋ ์์น์ ์ ๊ทผ ์ค์ธ์ง ํ์ (๋ณ๋ ํ ์ด๋ธ ํ์)
- file director(file handle, file control block)
- Open file table์ ๋ํ ์์น ์ ๋ณด (ํ๋ก์ธ์ค ๋ณ)
- kernel ์์ญ per-process file descriptor table, system-wide open file table ์ด ๋ ๊ฐ ๋ชจ๋ ์ฌ๋ผ๊ฐ (process A์ PCB)
- ์ฌ์ฉ์ ๋ฉ๋ชจ๋ฆฌ ์์ญ
๐ณ File Protection
- ๊ฐ ํ์ผ์ ๋ํด ๋๊ตฌ์๊ฒ ์ด๋ค ์ ๊ทผ(read/write/execution)์ ํ์ฉํ ๊ฒ์ธ๊ฐ?
- Access Control ๋ฐฉ๋ฒ
- Access control Matrix
- Access control list: ํ์ผ๋ณ๋ก ๋๊ตฌ์๊ฒ ์ด๋ค ๊ถํ์ด ์๋์ง ํ์
- Capability: ์ฌ์ฉ์๋ณ๋ก ์์ ์ด ์ ๊ทผ ๊ถํ์ ๊ฐ์ง ํ์ผ ๋ฐ ํด๋น ๊ถํ ํ์
- Grouping
- ์ ์ฒด user๋ฅผ owner, group, public์ ์ธ ๊ทธ๋ฃน์ผ๋ก ๊ตฌ๋ถ
- ๊ฐ ํ์ผ์ ๋ํด ์ธ ๊ทธ๋ฃน์ ์ ๊ทผ ๊ถํ(rwx)์ 3๋นํธ์ฉ ํ์
- ex) UNIX owner / group / other
- Password
- ํ์ผ๋ง๋ค password๋ฅผ ๋๋ ๋ฐฉ๋ฒ (๋๋ ํ ๋ฆฌ ํ์ผ์ ๋๋ ๋ฐฉ๋ฒ๋ ๊ฐ๋ฅ)
- ๋ชจ๋ ์ ๊ทผ ๊ถํ์ ๋ํด ํ๋์ password: all-or-nothing
- ์ ๊ทผ ๊ถํ๋ณ password: ์๊ธฐ๋ฌธ์ , ๊ด๋ฆฌ๋ฌธ์
- Access control Matrix
๐ Access Methods
- ์์คํ
์ด ์ ๊ณตํ๋ ํ์ผ ์ ๋ณด์ ์ ๊ทผ ๋ฐฉ์
- ์์ฐจ ์ ๊ทผ (Sequensial Access)
- ์นด์ธํธ ํ ์ดํ๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์์ฒ๋ผ ์ ๊ทผ
- ์ฝ๊ฑฐ๋ ์ฐ๋ฉด offset์ด ์๋์ผ๋ก ์ฆ๊ฐ
- ์ง์ ์ ๊ทผ (direct access, random access)
- LP ๋ ์ฝ๋ ํ๊ณผ ๊ฐ์ด ์ ๊ทผํ๋๋ก ํจ
- ํ์ผ์ ๊ตฌ์ฑํ๋ ๋ ์ฝ๋๋ฅผ ์์์ ์์๋ก ์ ๊ทผํ ์ ์์
- ์์ฐจ ์ ๊ทผ (Sequensial Access)
๐ผ File System์ implementation
Allocation of File Data in Disk
-
Continuous Allocation
- ๋จ์
- externel fragmentation (์ค๊ฐ ์ค๊ฐ์ hole์ด ์๊ธฐ๋ ๊ฒฝ์ฐ)
- file grow๊ฐ ์ด๋ ค์
- file ์์ฑ์ ์ผ๋ง๋ ํฐ hole์ ์ ๊ณตํ ๊ฒ์ธ๊ฐ?
- grow ๊ฐ๋ฅ vs ๋ญ๋น (internal fragmentation)
- ์ฅ์
- Fast I/O
- ํ๋ฒ์ seek/location์ผ๋ก ๋ง์ ๋ฐ์ดํธ transfer
- realtime file์ฉ์ผ๋ก, ๋๋ ์ด๋ฏธ run ์ค์ด๋ process์ swapping์ฉ์ผ๋ก ์ ์ ํจ
- Direct Access(random Access) ๊ฐ๋ฅ
- Fast I/O
- ๋จ์
-
Linked Allocation
- ์ฅ์
- External Fragmentation์ด ๋ฐ์ํ์ง ์์
- ๋จ์
- No random access
- Reliabilityํ ๋ฌธ์ ์
- ํ sector๊ฐ ๊ณ ์ฅ๋ pointer๊ฐ ์ ์ค๋๋ฉด ๋ง์ ๋ถ๋ถ์ ์์
- Pointer๋ฅผ ์ํ ๊ณต๊ฐ์ด block์ ์ผ๋ถ๋ถ์ด ๋์ด ๊ณต๊ฐ ํจ์จ์ฑ์ ๋จ์ดํธ๋ฆผ
- 512Bytes Sector, 4Bytes Pointer
- ๋ณํ
- File Allocation System (FAT) ํ์ผ์์คํ
- ํฌ์ธํฐ๋ฅผ ๋ณ๋์ ์์น์ ๋ณด๊ดํ์ฌ reliability์ ๊ณต๊ฐ ํจ์จ์ฑ ๋ฌธ์ ํด๊ฒฐ
- File Allocation System (FAT) ํ์ผ์์คํ
- ์ฅ์
-
Indexed Allocation
- ์ฅ์
- External fragmentation์ด ๋ฐ์ํ์ง ์์
- Direct Access ๊ฐ๋ฅ
- ๋จ์
- Small file์ ๊ฒฝ์ฐ ๊ณต๊ฐ ๋ญ๋น๊ฐ ์์(๊ทผ๋ฐ๋ก ์ค์ ๋ก ๋๋ถ๋ถ์ ํ์ผ์ small์)
- Too large file์ ๊ฒฝ์ฐ ํ๋์ Block์ผ๋ก index๋ฅผ ์ ์ฅํ๊ธฐ ๋ถ์กฑํจ
- ํด๊ฒฐ๋ฐฉ์
- Linked scheme
- Multi-level index โ ์ธ๋ฑ์ค ๊ณต๊ฐ ๋ญ๋น๋ ์ด์ฉ ์ ์์
- ํด๊ฒฐ๋ฐฉ์
- ์ฅ์
๐ฑ UNIX ํ์ผ ์์คํ ์ ๊ตฌ์กฐ
- Partition์ ๊ตฌ์กฐ (=Logical Disk) / ์ ๋์ค ํ์ผ ์์คํ
์ ์ฃผ์ ๊ฐ๋
- Boot block (์ด๋ค ํ์ผ ์์คํ
์ด๋ boot block์ด ์ ์ผ ์์์ ๋์ด)
- ๋ถํ ์ ํ์ํ ์ ๋ณด(BootStrap Loader)
- Super block
- ํ์ผ ์์คํ ์ ๋ํ ์ด์ฒด์ ์ธ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ค.
- Inode list
- ํ์ผ ์ด๋ฆ์ ์ ์ธํ ํ์ผ์ ๋ชจ๋ ๋ฉํ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ค.
- Data block
- ํ์ผ์ ์ค์ ๋ด์ฉ์ ์ ์ฅํ๋ค.
- Boot block (์ด๋ค ํ์ผ ์์คํ
์ด๋ boot block์ด ์ ์ผ ์์์ ๋์ด)
๐ต FATํ์ผ ์์คํ (์ง์ ์ ๊ทผ์ด ๊ฐ๋ฅํจ)
- MS๊ฐ MS๋ด์ ๋ง๋ค์์ ๋ ๋ง๋ File System์
- Partition์ ๊ตฌ์กฐ (=Logical Disk)
- Boot block
- FAT (Data-block์ ํฌ๊ธฐ๋งํผ FAT์์ ๋ฐฐ์ด์ ํฌ๊ธฐ๊ฐ ์ ํด์ง)
- Root Directory
- Data-block
๐ป Free-Space Management
- Bit map or bit vector (continuous Allocation์์ hole๋ก ์ธํด ๋น์ด์๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ)
- Bit map์ ์ถ๊ฐ์ ์ธ ๊ณต๊ฐ์ ํ์๋กํจ
- ์ฐ์์ ์ธ n๊ฐ์ free block์ ์ฐพ๋๋ฐ ํจ๊ณผ์
- Linked List
- ๋ชจ๋ Free block์ ๋งํฌ๋ก ์ฐ๊ฒฐ
- ์ฐ์์ ์ธ ๊ฐ์ฉ๊ณต๊ฐ์ ์ฐพ๋ ๊ฒ์ ์ฝ์ง ์๋ค
- ๊ณต๊ฐ์ ๋ญ๋น๊ฐ ์๋ค
- Grouping
- Linked List ๋ฐฉ๋ฒ์ ๋ณํ
- ์ฒซ๋ฒ์งธ free block์ด n๊ฐ์ pointer๋ฅผ ๊ฐ๋ฆฌํด
- n-1 ํฌ์ธํฐ๋ free data block์ ๊ฐ๋ฆฌํด
- ๋ง์ง๋ง pointer๊ฐ ๊ฐ๋ฆฌํค๋ block์ ๋ ๋ค์ n pointer๋ฅผ ๊ฐ์ง
- Counting
- ํ๋ก๊ทธ๋จ๋ค์ด ์ข ์ข ์ฌ๋ฌ ๊ฐ์ ์ข ์์ ์ธ block์ ํ ๋นํ๊ณ ๋ฐ๋ฉํ๋ค๋ ์ฑ์ง์ ์ฐฉ์
- First Free Block, of continuous free blocks๋ฅผ ์ ์ง
๐ฅ Directory Implememtation
- Linear List
- <file name, file์ metadata>์ List
- ๊ตฌํ์ด ๊ฐ๋จ
- ๋๋ ํ ๋ฆฌ ๋ด์ ํ์ผ์ด ์๋์ง ์ฐพ๊ธฐ ์ํด์๋ linear search๊ฐ ํ์(timing consuming)
- Hash Table
- linear list + hasing
- Hash table์ file name์ ์ด ํ์ผ์ linear list์ ์์น๋ก ๋ฐ๊ฟ์ค
- search time์ ์์ฐ
- Collision ๋ฐ์ ๊ฐ๋ฅ
- File์ metadata์ ๋ณด๊ด ์์น
- ๋๋ ํ ๋ฆฌ ๋ด์ ์ง์ ๋ณด๊ด
- ๋๋ ํ ๋ฆฌ์๋ ํฌ์ธํฐ๋ฅผ ๋๊ณ ๋ค๋ฅธ ๊ณณ์ ์ ์ฅ
- inode, FAT ๋ฑ
- Long file name์ ์ง์
-
์ list์์ ๊ฐ entry๋ ์ผ๋ฐ์ ์ผ๋ก ๊ณ ์ ํฌ๊ธฐ - file name์ด ๊ณ ์ ํฌ๊ธฐ์ entry ๊ธธ์ด๋ณด๋ค ๊ธธ์ด์ง๋ ๊ฒฝ์ฐ, entry์ ๋ง์ง๋ง ๋ถ๋ถ์ ์ด๋ฆ์ ๋ท๋ถ๋ถ์ ์์นํ pointer๋ฅผ ๋๋ ๋ฐฉ๋ฒ
- ์ด๋ฆ์ ๋๋จธ์ง ๋ถ๋ถ์ ๋์ผํ directory file์ ์ผ๋ถ์ ์กด์ฌ
-
๐ VFS ์ NFS
- Virtual File System
- ์๋ก ๋ค๋ฅธ ๋ค์ํ ํ์ผ ์์คํ ์ ๋ํด ๋์ผํ ์์คํ ์ฝ ์ธํฐํ์ด์ค(API)๋ฅผ ํตํด ์ ๊ทผํ ์ ์๊ฒ ํด์ฃผ๋ OS์ Layer
- Network File System
- ๋ถ์ฐ ์์คํ ์์๋ ๋คํธ์ํฌ๋ฅผ ํตํด ํ์ผ์ด ๊ณต์ ๋ ์ ์์
- NFS๋ ๋ถ์ฐ ํ๊ฒฝ์์์ ๋ํ์ ์ธ ํ์ผ ๊ณต์ ๋ฐฉ๋ฒ์
๐ณ Page Cache And Buffer Cache
- Page Cache
- Virtual memory์ paging system์์ ์ฌ์ฉํ๋ page frame์ caching์ ๊ด์ ์์ ์ค๋ช ํ๋ ์ฉ์ด
- Memory Mapped I/O์ ์ฐ๋ ๊ฒฝ์ฐ, file์ I/O์์๋ page cache ์ฌ์ฉ
- Memory Mapped I/O
- File์ ์ผ๋ถ๋ถ์ virtual memory์ mapping ์ํด
- ๋งคํ ์ํจ ์์ญ์ ๋ํ ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผ ์ฐ์ฐ์ ํ์ผ์ ์ ์ถ๋ ฅ์ ์ํํ๊ฒ ํจ
- Buffered Cache
- ํ์ผ ์์คํ ์ ํตํ I/O ์ฐ์ฐ์ ๋ฉ๋ชจ๋ฆฌ์ ํน์ ์์ญ์ด Buffer cache ์ฌ์ฉ
- File ํ์ฉ์ locality์ฌ์ฉ
- ํ๋ฒ ์ฝ์ด์จ block์ ๋ํ ํ์ ์์ฒญ์ buffer cache์์ ์ฆ์ ์ ๋ฌ
- ๋ชจ๋ ํ๋ก์ธ์ค๊ฐ ๊ณตํต์ผ๋ก ์ฌ์ฉ
- Replacement algorithm ํ์(LRU, LFU)
- Unified Buffer Cache
- ์ต๊ทผ์ OS์์ Buffer cache๊ฐ page cache๋ก ํตํฉ๋จ