SlideShare a Scribd company logo
1 of 48
การใช้ง านระบบแฟ้ม
File-System Implementation
Chapter 12: File System Implementation


                    File System Structure
                    File System Implementation
                    Directory Implementation
                    Allocation Methods
                    Free-Space Management
                    Efficiency and Performance
                    Recovery
                    Log-Structured File Systems
                    NFS




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 2
                            ั
โครงสร้า งระบบแฟ้ม
                                         File-System Structure

                    File structure
                       หน่วยของหน่วยเก็บเชิงตรรกะ (Logical storage unit)
                       หน่วยรวมของข้อมูลที่เกี่ยวข้องกัน
                    ระบบแฟ้มเก็บอยูบนหน่วยเก็บรอง-ดิสก์ (secondary storage-
                                     ่
                    disks)
                    ระบบแฟ้มถูกจัดเก็บเป็นเลเยอร์
                    File control block – โครงสร้างของหน่วยเก็บประกอบด้วย
                    ข้อมูลเกี่ยวกับแฟ้ม




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 3
                            ั
Layered File System




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 4
                            ั
A Typical File Control Block




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 5
                            ั
โครงสร้า งระบบแฟ้ม ในหน่ว ยความจำา
                   In-Memory File System Structures
                    ภาพต่อไปนี้ใช้แสดงถึงโครงสร้างที่จำาเป็นของระบบแฟ้มที่จัด
                    เตรียมไว้โดย OS

                    Figure 12-3(a) อ้างถึงการเปิดแฟ้ม

                    Figure 12-3(b) อ้างถึงการอ่านแฟ้ม




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 6
                            ั
In-Memory File System Structures




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 7
                            ั
ระบบแฟ้ม เสมือ น
                                     Virtual File Systems
                    Virtual File Systems (VFS) เป็นวิธีการใช้งานระบบแฟ้มเชิง
                    วัตถุ

                    VFS อนุญาตให้ระบบที่เหมือนกันสามารถเรียกส่วนต่อประสาน
                    (Application Program Interface-API) ที่ใช้สำาหรับระบบแฟ้ม
                    ประเภทที่แตกต่างกันได้

                    API ถือเป็นส่วนต่อประสานแบบระบบแฟ้มเสมือน (VFS
                    interface), มากกว่าจะระบุให้เป็นระบบแฟ้มชนิดใดๆ




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 8
                            ั
Schematic View of Virtual File
                                    System




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 9
                            ั
Directory Implementation

                    รายการแบบเส้นตรง (Linear list) ของชื่อแฟ้มพร้อมพอยน์เตอร์
                    ที่ชี้ไปยังบล็อกข้อมูล (data blocks)
                       โปรแกรมอย่างง่าย
                       ใช้เวลาในการ execute


                    ตารางแฮช (Hash Table) – รยการแบบเส้นตรงพร้อมโครงสร้าง
                    ข้อมูลแบบแฮช (hash data structure)
                       ลดเวลาค้นหา directory
                       การชนกัน (collisions) – สถานการณ์ที่ 2 แฟ้ม มีชื่อแฮชอยู่
                        ตำาแหน่งเดียวกัน
                       ขนาดคงที่ (fixed size)




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 10
                            ั
วิธ ก ารจัด สรร
                                                      ี
                                              Allocation Methods
                    วิธีการจัดสรร หมายถึง บล็อกของดิสก์จะถูกจัดสรรสำาหรับแฟ้ม
                    ต่างๆ ได้อย่างไร

                    การจัดสรรแบบต่อเนื่อง (Contiguous allocation)

                    การจัดสรรแบบเชื่อมโยง (Linked allocation)

                    การจัดสรรแบบดัชนี (Indexed allocation)




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 11
                            ั
การจัด สรรแบบต่อ เนือ ง
                                                             ่
                                         Contiguous Allocation

                 แต่ละแฟ้มจะอยูกันเป็นชุดของบล็อกที่เรียงต่อเนื่องกันบนดิสก์
                               ่

                 ง่าย – ต้องการเพียงบล็อกตำาแหน่งเริ่มต้น (block #) และความ
                 ยาวของบล็อก (number of blocks) เท่านั้น

                 การเข้าถึงแบบสุ่ม (Random access)

                 จะมีพื้นที่ใช้การไม่ได้มาก เกิดปัญหาการจัดสรรหน่วยเก็บแบบ
                 พลวัต (dynamic storage-allocation problem)

                 แฟ้มไม่สามารถขยายได้ (Files cannot grow)




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 12
                            ั
Contiguous Allocation of Disk
                                      Space




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 13
                            ั
ระบบขยาย
                                       Extent-Based Systems

                    มีระบบแฟ้มใหม่ๆ จำานวนมาก (I.e. Veritas File System) ใช้
                    โครงสร้างการจัดสรรแบบต่อเนื่อง

                    Extent-based file systems จัดสรรบล็อกของดิสก์แบบขยาย
                    (extents)

                    ส่วนขยาย (extent) คือขยายบล็อกของดิสก์แบบต่อเนื่อง โดย
                    ส่วนที่ถกขยายคือการจัดสรรแฟ้ม แฟ้มจะประกอบด้วยส่วนขยาย
                            ู
                    (extents) จำานวนหนึ่งหรือมากกว่าหนึ่ง




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 14
                            ั
การจัด สรรแบบเชือ มโยง
                                                         ่
                                           Linked Allocation
                    แต่ละแฟ้มจะมีรายการเชื่อมโยง (linked list) ของบล็อกดิสก์
                    โดยที่บล็อกอาจเป็นการแบ่งส่วนใดๆก็ได้บนดิสก์


                                         block          =          pointer




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 15
                            ั
Linked Allocation (Cont.)

                   ง่าย– ต้องการเพียงที่อยูเริ่มต้น (starting address)
                                            ่
                   ระบบการจัดการพื้นที่ว่าง (Free-space management
                   system) – ไม่มีพื้นที่ว่างโดยเปล่าประโยชน์
                   ไม่รองรับการเข้าแบบสุ่ม (random access)
                   ต้องแปลงส่ง (Mapping)
                                                                                  Q
                                                                 LA/511
                                                                                  R

                  บล็อกที่เข้าถึงคือ Qth block ในสายโยงใยของบล็อกที่แทนแฟ้ม
                  Displacement into block = R + 1
             File-allocation table (FAT) – การจัดสรรพื้นที่ว่างดิสก์ (disk-space
                 allocation) ดังกล่าวนี้มีใช้โดย MS-DOS และ OS/2.


วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 16
                            ั
Linked Allocation




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 17
                            ั
File-Allocation Table




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 18
                            ั
การจัด สรรแบบดัช นี
                                               Indexed Allocation
                    นำา pointers ทั้งหมดเข้าไปเก็บไว้ด้วยกันใน index block.
                    มุมมองเชิงตรรกะ (Logical view)




                                                 index table




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 19
                            ั
Example of Indexed Allocation




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 20
                            ั
Indexed Allocation (Cont.)

                   ต้องมีตารางดัชนี (index table)
                   เข้าถึงแบบสุ่ม (Random access)
                   การเข้าถึงแบบพลวัต (Dynamic access) โดยไม่มีการแตก
                   กระจายแบบภายนอก (external fragmentation), แต่จะ
                   มีoverhead ของ index block
                   การ Mapping จากเชิงตรรกะเป็นเชิงกายภาพในแฟ้มหนึ่งๆ
                   สูงสุดขนาดไม่เกิน 256K words และ block size of 512 words
                    ต้องใช้เพียง 1 block สำาหรับ index table
                                                                                     Q
                                                                     LA/512
                                                                                     R
              Q = displacement into index table
              R = displacement into block



วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 21
                            ั
Indexed Allocation – Mapping
                                      (Cont.)

                   Mapping จากเชิงตรรกะเป็นเชิงกายภาพในแฟ้มหนึ่งๆ นั้นไม่ผูก
                   ติดกับความยาว (block size of 512 words)
                   โครงสร้างแบบโยง (Linked scheme) – Link blocks ของ
                   index table (ไม่จำากัดขนาด)
                                                                                   Q1
                                                  LA / (512 x 511)
                                                                                   R1
                   Q1 = block of index table
                   R1 is used as follows:                                     Q2
                                                          R1 / 512
                                                                              R2

                   Q2 = displacement into block of index table
                   R2 displacement into block of file:


วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 22
                            ั
Indexed Allocation – Mapping
                                      (Cont.)

                    ดัชนีแบบ 2 ระดับ (Two-level index) ขนาดไฟล์สูงสุดคือ 5123

                                                                                    Q1
                                                   LA / (512 x 512)
                                                                                    R1


                  Q1 = displacement into outer-index
                  R1 is used as follows:
                                                                              Q2
                                                          R1 / 512
                                                                              R2

                   Q2 = displacement into block of index table
                   R2 displacement into block of file:


วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 23
                            ั
Indexed Allocation – Mapping
                                      (Cont.)




                                                




                                        outer-index


                                                                        index table                                 file



วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 24
                            ั
Combined Scheme: UNIX (4K bytes per
                               block)




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 25
                            ั
การจัด การพื้น ที่ว ่า ง
                                   Free-Space Management
                    Bit vector (n blocks)
                                             0 1          2                                     n-1
                                                                                    …



                                                    
                                                           0 ⇒ block[i] free
                                         bit[i] =
                                                           1 ⇒ block[i] occupied


             Block number calculation

                                         (number of bits per word) *
                                         (number of 0-value words) +
                                         offset of first 1 bit




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 26
                            ั
Free-Space Management (Cont.)

                    Bit map ต้องการพื้นที่เพิ่มเติม Example:
                             block size = 212 bytes
                             disk size = 230 bytes (1 gigabyte)
                             n = 230/212 = 218 bits (or 32K bytes)
                    ง่ายต่อแฟ้มแบบต่อเนื่อง
                    Linked list (free list)
                       หาพืนที่ต่อเนื่องได้ยาก
                             ้
                       ไม่มีพนทีไร้ประโยชน์
                               ื้ ่
                    Grouping
                    Counting




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 27
                            ั
Free-Space Management (Cont.)


                    ต้องมีการป้องกัน (protect)
                       Pointer ไปยังรายการที่ว่าง (free list)
                       Bit map
                              ต้องเก็บบนดิสก์
                              สำาเนาบนหน่วยความจำาและบนดิสก์อาจคนละชุด
                              ไม่ยนยอมให้เกิดสถานการณ์สำาหรับ block[i] โดยที่ bit[i] = 1
                                   ิ
                            ในหน่วยความจำา และ bit[i] = 0 บนดิสก์
                       Solution:
                          Set bit[i] = 1 in disk.
                          Allocate block[i]
                          Set bit[i] = 1 in memory




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 28
                            ั
Linked Free Space List on Disk




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 29
                            ั
ความสะดวกและประสิท ธิภ าพ
                               Efficiency and Performance
                    ความสะดวก (Efficiency) ขึนอยู่กับ:
                                             ้
                       อัลกอริธึมในการจัดสรรดิสก์และไดเรกทอรี
                       ชนิดของข้อมูลที่เก็บในรายการไดเรกทอรของแฟ้ม (file’s
                           directory entry)

                    ประสิทธิภาพ (Performance)
                       ดิสก์แคช (disk cache) – แยกส่วนของหน่วยความจำาสำาหรับบล็อก
                        ที่ถกใช้งานบ่อย
                            ู
                       free-behind and read-ahead – เป็นเทคนิคในการเข้าแบบลำาดับ
                        ได้เหมาะทีสุด (optimize sequential access)
                                  ่
                       การปรับปรุงประสิทธิภาพของพีซโดยสร้าง dedicating section
                                                      ี
                        ของหน่วยความจำาเหมือนกับดิสก์เสมือน หรือแรมดิสก์ (virtual
                        disk, or RAM disk)




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 30
                            ั
Various Disk-Caching Locations




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 31
                            ั
Page Cache

                    เพจแคช (page cache) ใช้มากกว่าบล็อกดิสก์โดยใช้
                    เทคนิคvirtual memory

                    Memory-mapped I/O ใช้ page cache

                    Routine I/O ผ่าน file system ใช้ buffer (disk) cache

                    จะนำาไปสู่ภาพในหน้าถัดไป




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 32
                            ั
I/O Without a Unified Buffer Cache




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 33
                            ั
Unified Buffer Cache

                    A unified buffer cache ใช้เพจแคชเดียวกันสำาหรับเป็นแคชทั้ง
                    หน่วยความจำา memory-mapped pages และ ordinary file
                    system I/O




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 34
                            ั
I/O Using a Unified Buffer Cache




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 35
                            ั
การกู้ค น
                                                                       ื
                                                              Recovery
                    การตรวจสอบความสอดคล้องกัน (Consistency checking) –
                    เปรียบเทียบข้อมูลในโครงสร้างไดเรกทอรีด้วยบล็อกข้อมูลบน
                    ดิสก์ และพยายามแก้ไขความไม่สอดคล้องกัน

                    ใช้ system programs ในการ back up สำารองข้อมูลจากดิสก์
                    ไปยังอุปกรณ์หน่วยเก็บอื่นๆ (floppy disk, magnetic tape).

                    กู้แฟ้มหรือดิสก์ที่เสียหาย โดยเรียกคืน restoring ข้อมูลจาก
                    ระบบสำารอง




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 36
                            ั
Log Structured File Systems

                    Log structured (หรือ journaling) ทำาการบันทึกระบบแฟ้มที่
                    ถูกปรับปรุงแต่ละครั้งไปยังระบบแฟ้มในลักษณะของธุร กรรม
                    (transaction)

                    ทุกธุรกรรมจะถูกเขียนลงบน log ธุรกรรมหนึ่งๆ จะบันทึกว่า
                    สำา เร็จ (committed) หลังจากที่ถูกเขียนบน log เสร็จแล้ว
                    อย่างไรก็ตาม file system อาจปรับปรุงยังไม่แล้วเสร็จก็ได้

                    ธุรกรรมใน log เป็นถูกเขียนแบบไม่พร้อมกัน (asynchronously
                    written) บน file system เมื่อ file system ถูกแก้ไข ธุรกรรมก็จะ
                    ถูกลบออกจาก log

                    ถ้าระบบแฟ้มล่ม (crashes) ธุรกรรมที่ยังเหลืออยูใน log จต้องยัง
                                                                  ่
                    คงใช้การต่อได้



วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 37
                            ั
The Sun Network File System
                                     (NFS)

                    An implementation and a specification of a software
                    system for accessing remote files across LANs (or
                    WANs).

                    The implementation is part of the Solaris and SunOS
                    operating systems running on Sun workstations using an
                    unreliable datagram protocol (UDP/IP protocol and
                    Ethernet.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 38
                            ั
NFS (Cont.)

                    Interconnected workstations viewed as a set of
                    independent machines with independent file systems,
                    which allows sharing among these file systems in a
                    transparent manner.
                       A remote directory is mounted over a local file system
                        directory. The mounted directory looks like an integral
                        subtree of the local file system, replacing the subtree
                        descending from the local directory.
                       Specification of the remote directory for the mount operation
                        is nontransparent; the host name of the remote directory
                        has to be provided. Files in the remote directory can then
                        be accessed in a transparent manner.
                       Subject to access-rights accreditation, potentially any file
                        system (or directory within a file system), can be mounted
                        remotely on top of any local directory.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 39
                            ั
NFS (Cont.)

                    NFS is designed to operate in a heterogeneous
                    environment of different machines, operating systems,
                    and network architectures; the NFS specifications
                    independent of these media.
                    This independence is achieved through the use of RPC
                    primitives built on top of an External Data Representation
                    (XDR) protocol used between two implementation-
                    independent interfaces.
                    The NFS specification distinguishes between the services
                    provided by a mount mechanism and the actual remote-
                    file-access services.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 40
                            ั
Three Independent File Systems




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 41
                            ั
Mounting in NFS




                                      Mounts                                       Cascading mounts

วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 42
                            ั
NFS Mount Protocol
                         Establishes initial logical connection between server and
                         client.
                         Mount operation includes name of remote directory to be
                         mounted and name of server machine storing it.
                            Mount request is mapped to corresponding RPC and forwarded
                             to mount server running on server machine.
                            Export list – specifies local file systems that server exports for
                             mounting, along with names of machines that are permitted to
                             mount them.
                         Following a mount request that conforms to its export list,
                         the server returns a file handle—a key for further accesses.
                         File handle – a file-system identifier, and an inode number to
                         identify the mounted directory within the exported file
                         system.
                         The mount operation changes only the user’s view and does
                         not affect the server side.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 43
                            ั
NFS Protocol

                    Provides a set of remote procedure calls for remote file
                    operations. The procedures support the following operations:
                          searching for a file within a directory
                          reading a set of directory entries
                          manipulating links and directories
                          accessing file attributes
                          reading and writing files
                    NFS servers are stateless; each request has to provide a full set
                    of arguments.
                    Modified data must be committed to the server’s disk before
                    results are returned to the client (lose advantages of caching).
                    The NFS protocol does not provide concurrency-control
                    mechanisms.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 44
                            ั
Three Major Layers of NFS
                                      Architecture

                    UNIX file-system interface (based on the open, read,
                    write, and close calls, and file descriptors).

                    Virtual File System (VFS) layer – distinguishes local files
                    from remote ones, and local files are further distinguished
                    according to their file-system types.
                       The VFS activates file-system-specific operations to handle
                        local requests according to their file-system types.
                       Calls the NFS protocol procedures for remote requests.


                    NFS service layer – bottom layer of the architecture;
                    implements the NFS protocol.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 45
                            ั
Schematic View of NFS
                                          Architecture




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 46
                            ั
NFS Path-Name Translation

                    Performed by breaking the path into component names
                    and performing a separate NFS lookup call for every pair
                    of component name and directory vnode.

                    To make lookup faster, a directory name lookup cache on
                    the client’s side holds the vnodes for remote directory
                    names.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 47
                            ั
NFS Remote Operations

                    Nearly one-to-one correspondence between regular UNIX
                    system calls and the NFS protocol RPCs (except opening and
                    closing files).
                    NFS adheres to the remote-service paradigm, but employs
                    buffering and caching techniques for the sake of performance.
                    File-blocks cache – when a file is opened, the kernel checks
                    with the remote server whether to fetch or revalidate the cached
                    attributes. Cached file blocks are used only if the corresponding
                    cached attributes are up to date.
                    File-attribute cache – the attribute cache is updated whenever
                    new attributes arrive from the server.
                    Clients do not free delayed-write blocks until the server confirms
                    that the data have been written to disk.




วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 48
                            ั

More Related Content

What's hot

Operating System Chapter 4
Operating System Chapter 4Operating System Chapter 4
Operating System Chapter 4Nuth Otanasap
 
1 ระบบคอมพิวเตอร์และระบบปฏิบัติการ
1 ระบบคอมพิวเตอร์และระบบปฏิบัติการ1 ระบบคอมพิวเตอร์และระบบปฏิบัติการ
1 ระบบคอมพิวเตอร์และระบบปฏิบัติการkanlayarat
 
Operating System Chapter 1
Operating System Chapter 1Operating System Chapter 1
Operating System Chapter 1Nuth Otanasap
 
Srs document for identity based secure distributed data storage schemes
Srs document for identity based secure distributed data storage schemesSrs document for identity based secure distributed data storage schemes
Srs document for identity based secure distributed data storage schemesSahithi Naraparaju
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System ImplementationWayne Jones Jnr
 
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)krissapat
 
ระบบปฏิบัติการ MS-DOS
ระบบปฏิบัติการ MS-DOSระบบปฏิบัติการ MS-DOS
ระบบปฏิบัติการ MS-DOSssuseraa96d2
 
แนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้น
แนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้นแนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้น
แนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้นPhusit Konsurin
 
Advanced data modeling
Advanced data modelingAdvanced data modeling
Advanced data modelingDhani Ahmad
 
แผนคอมฯ ม.2 1
แผนคอมฯ ม.2 1แผนคอมฯ ม.2 1
แผนคอมฯ ม.2 1Surapong Jakang
 
บทบาทหน้าที่ของทีมผลิตภาพยนตร์
บทบาทหน้าที่ของทีมผลิตภาพยนตร์บทบาทหน้าที่ของทีมผลิตภาพยนตร์
บทบาทหน้าที่ของทีมผลิตภาพยนตร์ณัฐพล บัวพันธ์
 

What's hot (20)

Operating System Chapter 4
Operating System Chapter 4Operating System Chapter 4
Operating System Chapter 4
 
Ch08th
Ch08thCh08th
Ch08th
 
1 ระบบคอมพิวเตอร์และระบบปฏิบัติการ
1 ระบบคอมพิวเตอร์และระบบปฏิบัติการ1 ระบบคอมพิวเตอร์และระบบปฏิบัติการ
1 ระบบคอมพิวเตอร์และระบบปฏิบัติการ
 
Data-Persistency
Data-PersistencyData-Persistency
Data-Persistency
 
Operating System Chapter 1
Operating System Chapter 1Operating System Chapter 1
Operating System Chapter 1
 
ระบบสารสนเทศเพื่อประกอบการตัดสินใจ
ระบบสารสนเทศเพื่อประกอบการตัดสินใจระบบสารสนเทศเพื่อประกอบการตัดสินใจ
ระบบสารสนเทศเพื่อประกอบการตัดสินใจ
 
Srs document for identity based secure distributed data storage schemes
Srs document for identity based secure distributed data storage schemesSrs document for identity based secure distributed data storage schemes
Srs document for identity based secure distributed data storage schemes
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
 
Ch10th
Ch10thCh10th
Ch10th
 
An Introduction to Operating Systems
An Introduction to Operating SystemsAn Introduction to Operating Systems
An Introduction to Operating Systems
 
ระบบปฏิบัติการ MS-DOS
ระบบปฏิบัติการ MS-DOSระบบปฏิบัติการ MS-DOS
ระบบปฏิบัติการ MS-DOS
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
แนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้น
แนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้นแนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้น
แนะนำการเขียนโปรแกรมภาษาแอสเซมลีเบื้องต้น
 
Advanced data modeling
Advanced data modelingAdvanced data modeling
Advanced data modeling
 
10. compute-part-1
10. compute-part-110. compute-part-1
10. compute-part-1
 
แผนคอมฯ ม.2 1
แผนคอมฯ ม.2 1แผนคอมฯ ม.2 1
แผนคอมฯ ม.2 1
 
บทบาทหน้าที่ของทีมผลิตภาพยนตร์
บทบาทหน้าที่ของทีมผลิตภาพยนตร์บทบาทหน้าที่ของทีมผลิตภาพยนตร์
บทบาทหน้าที่ของทีมผลิตภาพยนตร์
 
Swapping | Computer Science
Swapping | Computer ScienceSwapping | Computer Science
Swapping | Computer Science
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 

Similar to 8 ca-file system implementation (wichet p.'s conflicted copy 2012-12-17)

7 ca-file-system management
7 ca-file-system management7 ca-file-system management
7 ca-file-system managementkrissapat
 
10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)
10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)
10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)krissapat
 
Database basic new
Database basic newDatabase basic new
Database basic newQoo Kratai
 
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูลความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูลwarathip-por
 
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูลความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูลwarathip-por
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1ninewnilubon
 
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5palmyZommanow
 
หน่วยที่ 1
หน่วยที่ 1หน่วยที่ 1
หน่วยที่ 1palmyZommanow
 
เรื่องระบบปฏิบัติการ
เรื่องระบบปฏิบัติการเรื่องระบบปฏิบัติการ
เรื่องระบบปฏิบัติการพัน พัน
 
4 ca-process structure
4 ca-process structure4 ca-process structure
4 ca-process structurekrissapat
 

Similar to 8 ca-file system implementation (wichet p.'s conflicted copy 2012-12-17) (12)

7 ca-file-system management
7 ca-file-system management7 ca-file-system management
7 ca-file-system management
 
10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)
10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)
10 ca-mass-storage system structure (wichet p.'s conflicted copy 2012-12-17)
 
Database basic new
Database basic newDatabase basic new
Database basic new
 
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูลความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
 
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูลความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
ความรู้พื้นฐานเกี่ยวกับฐานข้อมูล
 
Work3 26
Work3 26Work3 26
Work3 26
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1
 
Unix Operation System
Unix Operation SystemUnix Operation System
Unix Operation System
 
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์  น่านกร ม.5
หน่วยที่ 1เรื่อง การจัดการข้อมูล ธนพงษ์ น่านกร ม.5
 
หน่วยที่ 1
หน่วยที่ 1หน่วยที่ 1
หน่วยที่ 1
 
เรื่องระบบปฏิบัติการ
เรื่องระบบปฏิบัติการเรื่องระบบปฏิบัติการ
เรื่องระบบปฏิบัติการ
 
4 ca-process structure
4 ca-process structure4 ca-process structure
4 ca-process structure
 

More from krissapat

5 ca-memory structuret
5 ca-memory structuret5 ca-memory structuret
5 ca-memory structuretkrissapat
 
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)krissapat
 
9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)
9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)
9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)krissapat
 
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)krissapat
 
5 ca-memory structuret
5 ca-memory structuret5 ca-memory structuret
5 ca-memory structuretkrissapat
 
3 ca-computer system structure
3 ca-computer system structure3 ca-computer system structure
3 ca-computer system structurekrissapat
 
2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)
2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)
2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)krissapat
 
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)krissapat
 

More from krissapat (8)

5 ca-memory structuret
5 ca-memory structuret5 ca-memory structuret
5 ca-memory structuret
 
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
 
9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)
9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)
9 ca-io systems structure (wichet p.'s conflicted copy 2012-12-17)
 
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
6 ca-virtual memory structure (wichet p.'s conflicted copy 2012-12-17)
 
5 ca-memory structuret
5 ca-memory structuret5 ca-memory structuret
5 ca-memory structuret
 
3 ca-computer system structure
3 ca-computer system structure3 ca-computer system structure
3 ca-computer system structure
 
2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)
2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)
2 ca-computer systems (wichet p.'s conflicted copy 2012-12-18)
 
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
1 ca-cpu structure (wichet p.'s conflicted copy 2012-12-17)
 

8 ca-file system implementation (wichet p.'s conflicted copy 2012-12-17)

  • 2. Chapter 12: File System Implementation File System Structure File System Implementation Directory Implementation Allocation Methods Free-Space Management Efficiency and Performance Recovery Log-Structured File Systems NFS วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 2 ั
  • 3. โครงสร้า งระบบแฟ้ม File-System Structure File structure  หน่วยของหน่วยเก็บเชิงตรรกะ (Logical storage unit)  หน่วยรวมของข้อมูลที่เกี่ยวข้องกัน ระบบแฟ้มเก็บอยูบนหน่วยเก็บรอง-ดิสก์ (secondary storage- ่ disks) ระบบแฟ้มถูกจัดเก็บเป็นเลเยอร์ File control block – โครงสร้างของหน่วยเก็บประกอบด้วย ข้อมูลเกี่ยวกับแฟ้ม วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 3 ั
  • 4. Layered File System วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 4 ั
  • 5. A Typical File Control Block วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 5 ั
  • 6. โครงสร้า งระบบแฟ้ม ในหน่ว ยความจำา In-Memory File System Structures ภาพต่อไปนี้ใช้แสดงถึงโครงสร้างที่จำาเป็นของระบบแฟ้มที่จัด เตรียมไว้โดย OS Figure 12-3(a) อ้างถึงการเปิดแฟ้ม Figure 12-3(b) อ้างถึงการอ่านแฟ้ม วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 6 ั
  • 7. In-Memory File System Structures วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 7 ั
  • 8. ระบบแฟ้ม เสมือ น Virtual File Systems Virtual File Systems (VFS) เป็นวิธีการใช้งานระบบแฟ้มเชิง วัตถุ VFS อนุญาตให้ระบบที่เหมือนกันสามารถเรียกส่วนต่อประสาน (Application Program Interface-API) ที่ใช้สำาหรับระบบแฟ้ม ประเภทที่แตกต่างกันได้ API ถือเป็นส่วนต่อประสานแบบระบบแฟ้มเสมือน (VFS interface), มากกว่าจะระบุให้เป็นระบบแฟ้มชนิดใดๆ วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 8 ั
  • 9. Schematic View of Virtual File System วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 9 ั
  • 10. Directory Implementation รายการแบบเส้นตรง (Linear list) ของชื่อแฟ้มพร้อมพอยน์เตอร์ ที่ชี้ไปยังบล็อกข้อมูล (data blocks)  โปรแกรมอย่างง่าย  ใช้เวลาในการ execute ตารางแฮช (Hash Table) – รยการแบบเส้นตรงพร้อมโครงสร้าง ข้อมูลแบบแฮช (hash data structure)  ลดเวลาค้นหา directory  การชนกัน (collisions) – สถานการณ์ที่ 2 แฟ้ม มีชื่อแฮชอยู่ ตำาแหน่งเดียวกัน  ขนาดคงที่ (fixed size) วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 10 ั
  • 11. วิธ ก ารจัด สรร ี Allocation Methods วิธีการจัดสรร หมายถึง บล็อกของดิสก์จะถูกจัดสรรสำาหรับแฟ้ม ต่างๆ ได้อย่างไร การจัดสรรแบบต่อเนื่อง (Contiguous allocation) การจัดสรรแบบเชื่อมโยง (Linked allocation) การจัดสรรแบบดัชนี (Indexed allocation) วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 11 ั
  • 12. การจัด สรรแบบต่อ เนือ ง ่ Contiguous Allocation แต่ละแฟ้มจะอยูกันเป็นชุดของบล็อกที่เรียงต่อเนื่องกันบนดิสก์ ่ ง่าย – ต้องการเพียงบล็อกตำาแหน่งเริ่มต้น (block #) และความ ยาวของบล็อก (number of blocks) เท่านั้น การเข้าถึงแบบสุ่ม (Random access) จะมีพื้นที่ใช้การไม่ได้มาก เกิดปัญหาการจัดสรรหน่วยเก็บแบบ พลวัต (dynamic storage-allocation problem) แฟ้มไม่สามารถขยายได้ (Files cannot grow) วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 12 ั
  • 13. Contiguous Allocation of Disk Space วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 13 ั
  • 14. ระบบขยาย Extent-Based Systems มีระบบแฟ้มใหม่ๆ จำานวนมาก (I.e. Veritas File System) ใช้ โครงสร้างการจัดสรรแบบต่อเนื่อง Extent-based file systems จัดสรรบล็อกของดิสก์แบบขยาย (extents) ส่วนขยาย (extent) คือขยายบล็อกของดิสก์แบบต่อเนื่อง โดย ส่วนที่ถกขยายคือการจัดสรรแฟ้ม แฟ้มจะประกอบด้วยส่วนขยาย ู (extents) จำานวนหนึ่งหรือมากกว่าหนึ่ง วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 14 ั
  • 15. การจัด สรรแบบเชือ มโยง ่ Linked Allocation แต่ละแฟ้มจะมีรายการเชื่อมโยง (linked list) ของบล็อกดิสก์ โดยที่บล็อกอาจเป็นการแบ่งส่วนใดๆก็ได้บนดิสก์ block = pointer วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 15 ั
  • 16. Linked Allocation (Cont.) ง่าย– ต้องการเพียงที่อยูเริ่มต้น (starting address) ่ ระบบการจัดการพื้นที่ว่าง (Free-space management system) – ไม่มีพื้นที่ว่างโดยเปล่าประโยชน์ ไม่รองรับการเข้าแบบสุ่ม (random access) ต้องแปลงส่ง (Mapping) Q LA/511 R บล็อกที่เข้าถึงคือ Qth block ในสายโยงใยของบล็อกที่แทนแฟ้ม Displacement into block = R + 1 File-allocation table (FAT) – การจัดสรรพื้นที่ว่างดิสก์ (disk-space allocation) ดังกล่าวนี้มีใช้โดย MS-DOS และ OS/2. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 16 ั
  • 17. Linked Allocation วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 17 ั
  • 18. File-Allocation Table วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 18 ั
  • 19. การจัด สรรแบบดัช นี Indexed Allocation นำา pointers ทั้งหมดเข้าไปเก็บไว้ด้วยกันใน index block. มุมมองเชิงตรรกะ (Logical view) index table วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 19 ั
  • 20. Example of Indexed Allocation วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 20 ั
  • 21. Indexed Allocation (Cont.) ต้องมีตารางดัชนี (index table) เข้าถึงแบบสุ่ม (Random access) การเข้าถึงแบบพลวัต (Dynamic access) โดยไม่มีการแตก กระจายแบบภายนอก (external fragmentation), แต่จะ มีoverhead ของ index block การ Mapping จากเชิงตรรกะเป็นเชิงกายภาพในแฟ้มหนึ่งๆ สูงสุดขนาดไม่เกิน 256K words และ block size of 512 words ต้องใช้เพียง 1 block สำาหรับ index table Q LA/512 R Q = displacement into index table R = displacement into block วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 21 ั
  • 22. Indexed Allocation – Mapping (Cont.) Mapping จากเชิงตรรกะเป็นเชิงกายภาพในแฟ้มหนึ่งๆ นั้นไม่ผูก ติดกับความยาว (block size of 512 words) โครงสร้างแบบโยง (Linked scheme) – Link blocks ของ index table (ไม่จำากัดขนาด) Q1 LA / (512 x 511) R1 Q1 = block of index table R1 is used as follows: Q2 R1 / 512 R2 Q2 = displacement into block of index table R2 displacement into block of file: วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 22 ั
  • 23. Indexed Allocation – Mapping (Cont.) ดัชนีแบบ 2 ระดับ (Two-level index) ขนาดไฟล์สูงสุดคือ 5123 Q1 LA / (512 x 512) R1 Q1 = displacement into outer-index R1 is used as follows: Q2 R1 / 512 R2 Q2 = displacement into block of index table R2 displacement into block of file: วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 23 ั
  • 24. Indexed Allocation – Mapping (Cont.)  outer-index index table file วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 24 ั
  • 25. Combined Scheme: UNIX (4K bytes per block) วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 25 ั
  • 26. การจัด การพื้น ที่ว ่า ง Free-Space Management Bit vector (n blocks) 0 1 2 n-1 …  0 ⇒ block[i] free bit[i] = 1 ⇒ block[i] occupied Block number calculation (number of bits per word) * (number of 0-value words) + offset of first 1 bit วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 26 ั
  • 27. Free-Space Management (Cont.) Bit map ต้องการพื้นที่เพิ่มเติม Example: block size = 212 bytes disk size = 230 bytes (1 gigabyte) n = 230/212 = 218 bits (or 32K bytes) ง่ายต่อแฟ้มแบบต่อเนื่อง Linked list (free list)  หาพืนที่ต่อเนื่องได้ยาก ้  ไม่มีพนทีไร้ประโยชน์ ื้ ่ Grouping Counting วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 27 ั
  • 28. Free-Space Management (Cont.) ต้องมีการป้องกัน (protect)  Pointer ไปยังรายการที่ว่าง (free list)  Bit map  ต้องเก็บบนดิสก์  สำาเนาบนหน่วยความจำาและบนดิสก์อาจคนละชุด  ไม่ยนยอมให้เกิดสถานการณ์สำาหรับ block[i] โดยที่ bit[i] = 1 ิ ในหน่วยความจำา และ bit[i] = 0 บนดิสก์  Solution:  Set bit[i] = 1 in disk.  Allocate block[i]  Set bit[i] = 1 in memory วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 28 ั
  • 29. Linked Free Space List on Disk วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 29 ั
  • 30. ความสะดวกและประสิท ธิภ าพ Efficiency and Performance ความสะดวก (Efficiency) ขึนอยู่กับ: ้  อัลกอริธึมในการจัดสรรดิสก์และไดเรกทอรี  ชนิดของข้อมูลที่เก็บในรายการไดเรกทอรของแฟ้ม (file’s directory entry) ประสิทธิภาพ (Performance)  ดิสก์แคช (disk cache) – แยกส่วนของหน่วยความจำาสำาหรับบล็อก ที่ถกใช้งานบ่อย ู  free-behind and read-ahead – เป็นเทคนิคในการเข้าแบบลำาดับ ได้เหมาะทีสุด (optimize sequential access) ่  การปรับปรุงประสิทธิภาพของพีซโดยสร้าง dedicating section ี ของหน่วยความจำาเหมือนกับดิสก์เสมือน หรือแรมดิสก์ (virtual disk, or RAM disk) วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 30 ั
  • 31. Various Disk-Caching Locations วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 31 ั
  • 32. Page Cache เพจแคช (page cache) ใช้มากกว่าบล็อกดิสก์โดยใช้ เทคนิคvirtual memory Memory-mapped I/O ใช้ page cache Routine I/O ผ่าน file system ใช้ buffer (disk) cache จะนำาไปสู่ภาพในหน้าถัดไป วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 32 ั
  • 33. I/O Without a Unified Buffer Cache วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 33 ั
  • 34. Unified Buffer Cache A unified buffer cache ใช้เพจแคชเดียวกันสำาหรับเป็นแคชทั้ง หน่วยความจำา memory-mapped pages และ ordinary file system I/O วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 34 ั
  • 35. I/O Using a Unified Buffer Cache วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 35 ั
  • 36. การกู้ค น ื Recovery การตรวจสอบความสอดคล้องกัน (Consistency checking) – เปรียบเทียบข้อมูลในโครงสร้างไดเรกทอรีด้วยบล็อกข้อมูลบน ดิสก์ และพยายามแก้ไขความไม่สอดคล้องกัน ใช้ system programs ในการ back up สำารองข้อมูลจากดิสก์ ไปยังอุปกรณ์หน่วยเก็บอื่นๆ (floppy disk, magnetic tape). กู้แฟ้มหรือดิสก์ที่เสียหาย โดยเรียกคืน restoring ข้อมูลจาก ระบบสำารอง วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 36 ั
  • 37. Log Structured File Systems Log structured (หรือ journaling) ทำาการบันทึกระบบแฟ้มที่ ถูกปรับปรุงแต่ละครั้งไปยังระบบแฟ้มในลักษณะของธุร กรรม (transaction) ทุกธุรกรรมจะถูกเขียนลงบน log ธุรกรรมหนึ่งๆ จะบันทึกว่า สำา เร็จ (committed) หลังจากที่ถูกเขียนบน log เสร็จแล้ว อย่างไรก็ตาม file system อาจปรับปรุงยังไม่แล้วเสร็จก็ได้ ธุรกรรมใน log เป็นถูกเขียนแบบไม่พร้อมกัน (asynchronously written) บน file system เมื่อ file system ถูกแก้ไข ธุรกรรมก็จะ ถูกลบออกจาก log ถ้าระบบแฟ้มล่ม (crashes) ธุรกรรมที่ยังเหลืออยูใน log จต้องยัง ่ คงใช้การต่อได้ วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 37 ั
  • 38. The Sun Network File System (NFS) An implementation and a specification of a software system for accessing remote files across LANs (or WANs). The implementation is part of the Solaris and SunOS operating systems running on Sun workstations using an unreliable datagram protocol (UDP/IP protocol and Ethernet. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 38 ั
  • 39. NFS (Cont.) Interconnected workstations viewed as a set of independent machines with independent file systems, which allows sharing among these file systems in a transparent manner.  A remote directory is mounted over a local file system directory. The mounted directory looks like an integral subtree of the local file system, replacing the subtree descending from the local directory.  Specification of the remote directory for the mount operation is nontransparent; the host name of the remote directory has to be provided. Files in the remote directory can then be accessed in a transparent manner.  Subject to access-rights accreditation, potentially any file system (or directory within a file system), can be mounted remotely on top of any local directory. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 39 ั
  • 40. NFS (Cont.) NFS is designed to operate in a heterogeneous environment of different machines, operating systems, and network architectures; the NFS specifications independent of these media. This independence is achieved through the use of RPC primitives built on top of an External Data Representation (XDR) protocol used between two implementation- independent interfaces. The NFS specification distinguishes between the services provided by a mount mechanism and the actual remote- file-access services. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 40 ั
  • 41. Three Independent File Systems วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 41 ั
  • 42. Mounting in NFS Mounts Cascading mounts วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 42 ั
  • 43. NFS Mount Protocol Establishes initial logical connection between server and client. Mount operation includes name of remote directory to be mounted and name of server machine storing it.  Mount request is mapped to corresponding RPC and forwarded to mount server running on server machine.  Export list – specifies local file systems that server exports for mounting, along with names of machines that are permitted to mount them. Following a mount request that conforms to its export list, the server returns a file handle—a key for further accesses. File handle – a file-system identifier, and an inode number to identify the mounted directory within the exported file system. The mount operation changes only the user’s view and does not affect the server side. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 43 ั
  • 44. NFS Protocol Provides a set of remote procedure calls for remote file operations. The procedures support the following operations:  searching for a file within a directory  reading a set of directory entries  manipulating links and directories  accessing file attributes  reading and writing files NFS servers are stateless; each request has to provide a full set of arguments. Modified data must be committed to the server’s disk before results are returned to the client (lose advantages of caching). The NFS protocol does not provide concurrency-control mechanisms. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 44 ั
  • 45. Three Major Layers of NFS Architecture UNIX file-system interface (based on the open, read, write, and close calls, and file descriptors). Virtual File System (VFS) layer – distinguishes local files from remote ones, and local files are further distinguished according to their file-system types.  The VFS activates file-system-specific operations to handle local requests according to their file-system types.  Calls the NFS protocol procedures for remote requests. NFS service layer – bottom layer of the architecture; implements the NFS protocol. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 45 ั
  • 46. Schematic View of NFS Architecture วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 46 ั
  • 47. NFS Path-Name Translation Performed by breaking the path into component names and performing a separate NFS lookup call for every pair of component name and directory vnode. To make lookup faster, a directory name lookup cache on the client’s side holds the vnodes for remote directory names. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 47 ั
  • 48. NFS Remote Operations Nearly one-to-one correspondence between regular UNIX system calls and the NFS protocol RPCs (except opening and closing files). NFS adheres to the remote-service paradigm, but employs buffering and caching techniques for the sake of performance. File-blocks cache – when a file is opened, the kernel checks with the remote server whether to fetch or revalidate the cached attributes. Cached file blocks are used only if the corresponding cached attributes are up to date. File-attribute cache – the attribute cache is updated whenever new attributes arrive from the server. Clients do not free delayed-write blocks until the server confirms that the data have been written to disk. วิเ ชษฐ์ พลายมาศ | ระบบปฏิบ ต ิก าร (OS: Operating Systems) | การใช้งานระบบแฟ้ม (File-System Implementation) | 48 ั