File System (Implementation) Ch. 11 SISTIM OPERASI (Operating System) IKI-20230 Johny Moningka (moningka@cs.ui.ac.id) Fakultas Ilmu Komputer Universitas Indonesia Semester 2000/2001 File-System Implementation File-System Structure Allocation Methods Free-Space Management File System JM-2000/v1.1/2 1
Review Storage management (server): Performance management (secara global): File sharing (server), potensi user akses yang sangat banyak. Bottleneck pada I/O dari server => dedicated komputer untuk disk storage => management mudah (centralized). Teknologi: SAN (storage area network). Capacity management: Strategi untuk mendukung memori hirarkis: kapan data harus di migrasi dari storage cost/byte mahal ke storage cost/byte lebih murah => Backup dan pengarsipan. Quota dan alokasi disk high speed untuk aplikasi penting. Availability: Termasuk solusi RAID, network restore etc. Bad blocks (disk)? Hardware or software recovery. File System JM-2000/v1.1/3 File-System Structure File structure Isi file: kumpulan byte yang berhubungan dengan informasi. Logical storage unit: urutan byte, dengan akses address secara logical (offset:1 s/d sizeof file). Bagaimana layout file => disk (sektor) Data file disimpan dalam blok (kelipatan besarnya sector). Logical address disk: urutan blok data. Implementasi: Mengurangi overhead mendapatkan data (seek, rotation). Manajemen blok yang bebas (free list). File System JM-2000/v1.1/4 2
Disk Management Alokasi struktur blok disk: Contiguous allocation Linked allocation. Indexed allocation. Manajemen free list dari blok storage. Manajemen volume, partisi disk. File System JM-2000/v1.1/5 Workloads Bagaimana cara user menggunakan file? Sequential access: data besar dan berurut. Random access: data kecil dan lokasi blok tidak berurut. Hal yang menjadi dasar design file structure: Umumnya file ukurannya kecil (pengamatan). Sebagian dari blok disk digunakan oleh file yang besar (porsi terbesar). Jadi perlu dukungan untuk kedua model akses : akses random (file kecil yang banyak) dan sequential (file yang besar dan aktifitas tinggi) => trade off yang sulit dipenuhi. File System JM-2000/v1.1/6 3
Contiguous Allocation Setiap file menempati sekumpulan blok yang contiguous (sinambung) pada disk. Umumnya max. besar file telah tetap (user menentukan). Pro s: Manajemen blok yang dialokasikan sederhana. Informasi awal lokasi nomor blok dan panjang blok yang dialokasikan. Con s: Space terbuang percuma, belum tentu sebesar data/isi file (dynamic storage-allocation problem). Sulit memperbesar (demand, grow) dari file. File System JM-2000/v1.1/7 Simple mechanism Example: IBM OS/360 When creating a file, make the user specify pre-specify its length and allocate all space at once File descriptor contents: location and size Pro: simple, fast access, both sequential and random. Masalah: fragementasi => perlu penggabungan blok yang kecil menjadi contiguous blok besar what happens if file c needs 2 blok??? file a (base=1,len=3) file b (base=5,len=2) File System JM-2000/v1.1/8 4
Simple mechanism Extent-based : allocate files like segmented memory file a (base=1,len=3) file b (base=5,len=2) what happens if file c needs 2 sectors??? File System JM-2000/v1.1/9 Linked files Basically a linked list on disk. Keep a linked list of all free blocks Variably Variably sized, sized, flexibly flexibly laid laid out out files files how do you find the last block in a? file a (base=1) file b (base=5) pro: easy dynamic growth & sequential access, no fragmentation con? Examples (sort-of): Alto, TOPS-10, DOS FAT File System JM-2000/v1.1/10 5
Linked Allocation Setiap file terdiri dari linked list dari blok disk: Mekanisme pengurutan blok yang dialokasikan untuk suatu file. Blok yang dialokasikan dapat tersebar (scattered): Tidak perlu fixed allocation => menjawab dynamic allocation problem. File descriptor: a pointer to file s first block Setiap blok menyimpan pointer yang menunjuk ke blok yang berikut. block = pointer ke alokasi blok berikutnya Data File System JM-2000/v1.1/11 Linked List Allocate as needed, link together; e.g., file starts at block 9 Bagaimana melakukan random access? Follow the link, overhead besar (read blok disk; linked list) => banyak seek) File System JM-2000/v1.1/12 6
Example: DOS FS (simplified) Performance: Link dikumpulkan pada fixed-sized file allocation table (FAT) => tidak disebarkan pada setiap blok. Directory (5) 0 1 a: 6 b: 2 2 3 4 5 6 FAT (16-bit entries) free eof 1 eof 3 eof 4... file a 6 4 3 file b 2 1 FAT cukup kecil dapat disimpan cache disk => akses tanpa melakukan seek. File System JM-2000/v1.1/13 FAT discussion Entry size = 16 bits nomor blok Berapa maksimum ukuran FAT? Jika 512 byte per blok, what s the maximum size of FS yang dapat dikenal? Solusi sederhana: memperbesar ukuran blok. Reliability: how to protect against errors? FAT menempati satu area tertentu (contiguous sector) => what happen if corrupt? Buat duplikat FAT on disk. Bootstrapping: where is root directory? Fixed location on disk: FAT (opt) FAT 64k* 64k* 2 = 128K 128K 64K*.5k 64K*.5k = 32M 32M FS FS root dir File System JM-2000/v1.1/14 7
Indexed files Kumpulkan pointer blok ke dalam satu indexed block. Implementasi: array pointer => max. ukuran file yang dapat ditampung oleh array tersebut. Create file: alokasikan blok pertama untuk menyimpan array pointer, blok akan diberikan on demand oleh user (dynamic). file a file b Pro: mendukung sequential access dan random (read the first block, and scan the array pointer). File System JM-2000/v1.1/15 Example of Indexed Allocation File System JM-2000/v1.1/16 8
Indexed files Issues (sama seperti masalah page table besar) 2^20 entries! 4K 4K block block size, size, 4GB 4GB file file = 1M 1M entries entries (4MB!) (4MB!) idle 2^32 file size 4K blocks Ukuran file kecil = lots of unused entries Mendukung file besar? table array menempati banyak blok yang contiguous. File System JM-2000/v1.1/17 Multi-leve indexed Pembagian struktur index hirarkis: region dengan index array (1 st level), menunjuk ke index array (2 nd level) dst. Masalah: akses ke index array => overhead idle File System JM-2000/v1.1/18 9
Indexed Allocation Mapping M outer-index index table file File System JM-2000/v1.1/19 Example UNIX: inode Untuk file kecil: 1 blok data Size: 4 Kbytes/blok Ukuran inode: 100 bytes Overhead: 2,5% File System JM-2000/v1.1/20 10
Multi-level indexed files File descriptor (inode) = 14 block pointers stuff Ptr 1 ptr 2 ptr 3 ptr 4... ptr 13 ptr 14 data blocks Indirect block Ptr 1 ptr 2 ptr 128 Ptr 1 ptr 2 ptr 128 File System JM-2000/v1.1/21 Indirect blks Double indirect block UNIX: inodes Inodes disimpan pada array (fixed) Besarnya array inode ditentuk saat disk di format (initialized) dan menempati lokasi tertentu (awal atau tersebar). Array inode tidak dapat diubah (kecuali melakuk reformat). Inode array file blocks... File system menyimpan (direktori) index yang menunjuk ke i-node (OS Unix menyebut i-number). Saat file dibuka, maka I-number diambil dari direktori dan i-node disimpan ke memori (bagian dari referensi PCB proses tsb). File System JM-2000/v1.1/22 11
Example: Unix file system Want to modify byte 4 in /a/b.c:. : 10 : dir a: 12: dir. :12 dir.. :10:dir b.c :13:inode Root directory read root directory (blk 10) refcnt=1 lookup a (blk 12); read lookup inode for b.c (13); read 14 0 0 int main() { Gunakan inode mencari byte 4 (blksize = 4KB, so offset = 0 gives blk 14); read File System JM-2000/v1.1/23 Block: OS view Berapa besar blok data suatu file system? Sistim lama (disk kecil): 512 Bytes => saat ini 4 KB. Contoh: Unix (V7) => Unix 4.2 BSD (Berkeley) Analisa performance response time FS, meningkat 4 x lebih cepat (sequential access). Why? Makin kecil ukuran block => makin banyak blok yang yang harus ditransfer atau makin banyak I/O operation yang harus dilakukan. Setiap I/O operation: faktor waktu latency sampai data dapat ditransfer. Mengapa tidak membuat blok menjadi sangat besar? Internal fragmentation (ingat: umumnya ukuran file kecil): waste of space. Notes: Windows mengenal istilah cluster untuk blok. File System JM-2000/v1.1/24 12
Free-Space Management Bit vector (n blocks) 0 1 2 n-1 bit[i] = 678 0 block[i] free 1 block[i] occupied Free list: model pembagian daftar blok yang bebas dalam linked list. Pointer (next) disimpan pada blok yang bebas. Umumnya tidak satu linked list tunggal, tapi di pilah dalam sekumpulan linked list. File System JM-2000/v1.1/25 Free-Space Management (Cont.) Bit map requires extra space. Example: block size = 2^12 bytes (4 K) disk size = 2^30 bytes (1 gigabyte) n = 2^30/2^12 = 2^18 bits (or 32K bytes) Need to protect: Pointer to free list Bit map Must be kept on disk Copy in memory and disk may differ. Solution (konsistensi check) Set bit[i] = 1 in disk. Allocate block[i] Set bit[i] = 1 in memory File System JM-2000/v1.1/26 13