File. File System Implementation. File Metadata. File System Implementation. Direct Memory Access Cont. Hardware background: Direct Memory Access

Similar documents
File. File System Implementation. Operations. Permissions and Data Layout. Storing and Accessing File Data. Opening a File

Disk Scheduling. Based on the slides supporting the text

Chapter 14: Mass-Storage Systems. Disk Structure

Module 13: Secondary-Storage Structure

Disk Scheduling. Chapter 14 Based on the slides supporting the text and B.Ramamurthy s slides from Spring 2001

Chapter 13: Mass-Storage Systems. Disk Scheduling. Disk Scheduling (Cont.) Disk Structure FCFS. Moving-Head Disk Mechanism

Chapter 13: Mass-Storage Systems. Disk Structure

CSE325 Principles of Operating Systems. Mass-Storage Systems. David P. Duggan. April 19, 2011

Mass-Storage Structure

Chapter 12: Mass-Storage Systems. Operating System Concepts 8 th Edition,

Mass-Storage Structure

V. Mass Storage Systems

CS420: Operating Systems. Mass Storage Structure

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Chapter 14: Mass-Storage Systems

Chapter 10: Mass-Storage Systems

I/O, Disks, and RAID Yi Shi Fall Xi an Jiaotong University

CS3600 SYSTEMS AND NETWORKS

CSE 4/521 Introduction to Operating Systems. Lecture 27 (Final Exam Review) Summer 2018

Chapter 10: Mass-Storage Systems

Chapter 10: Mass-Storage Systems. Operating System Concepts 9 th Edition

Disk Scheduling COMPSCI 386

Module 13: Secondary-Storage

Chapter 12: Secondary-Storage Structure. Operating System Concepts 8 th Edition,

Operating Systems. Operating Systems Professor Sina Meraji U of T

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Chapter 10: Mass-Storage Systems

Free Space Management

Disc Allocation and Disc Arm Scheduling?

CHAPTER 12: MASS-STORAGE SYSTEMS (A) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Introduction. Secondary Storage. File concept. File attributes

Chapter-6. SUBJECT:- Operating System TOPICS:- I/O Management. Created by : - Sanjay Patel

Overview of Mass Storage Structure

Chapter 12: Mass-Storage Systems. Operating System Concepts 8 th Edition,

I/O Device Controllers. I/O Systems. I/O Ports & Memory-Mapped I/O. Direct Memory Access (DMA) Operating Systems 10/20/2010. CSC 256/456 Fall

Disk scheduling Disk reliability Tertiary storage Swap space management Linux swap space management

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 420, York College. November 21, 2006

I/O Management and Disk Scheduling. Chapter 11

CS 550 Operating Systems Spring File System

Chapter 11: File System Implementation. Objectives

File Systems: Fundamentals

CS370 Operating Systems

Operating Systems 2010/2011

Chapter 12: Mass-Storage

Chapter 12: Mass-Storage

File Systems: Fundamentals

Part IV I/O System. Chapter 12: Mass Storage Structure

CS370 Operating Systems

Tape pictures. CSE 30341: Operating Systems Principles

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

CS 537 Fall 2017 Review Session

Secondary Storage (Chp. 5.4 disk hardware, Chp. 6 File Systems, Tanenbaum)

File Systems. Kartik Gopalan. Chapter 4 From Tanenbaum s Modern Operating System

EIDE, ATA, SATA, USB,

Chapter 12: Mass-Storage

File Layout and Directories

CSE380 - Operating Systems

Final Exam Preparation Questions

Chapter 11. I/O Management and Disk Scheduling

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

I/O Systems and Storage Devices

Silberschatz, et al. Topics based on Chapter 13

Chapter 14 Mass-Storage Structure

File Systems. Before We Begin. So Far, We Have Considered. Motivation for File Systems. CSE 120: Principles of Operating Systems.

CS370 Operating Systems

Operating Systems. Lecture File system implementation. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

File System Internals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

File System Internals. Jo, Heeseung

MASS-STORAGE STRUCTURE

Introduction to OS. File Management. MOS Ch. 4. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Chapter 11 I/O Management and Disk Scheduling

CSE 120: Principles of Operating Systems. Lecture 10. File Systems. February 22, Prof. Joe Pasquale

Department of Computer Engineering University of California at Santa Cruz. File Systems. Hai Tao

Today: Secondary Storage! Typical Disk Parameters!

Da-Wei Chang CSIE.NCKU. Professor Hao-Ren Ke, National Chiao Tung University Professor Hsung-Pin Chang, National Chung Hsing University

MODULE 4. FILE SYSTEM AND SECONDARY STORAGE

EECS 482 Introduction to Operating Systems

Segmentation with Paging. Review. Segmentation with Page (MULTICS) Segmentation with Page (MULTICS) Segmentation with Page (MULTICS)

[537] Fast File System. Tyler Harter

Computer Systems Laboratory Sungkyunkwan University

UNIT 4 Device Management

Lecture 9. I/O Management and Disk Scheduling Algorithms

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems

b. How many bits are there in the physical address?

CS370 Operating Systems

Storing Data: Disks and Files. Storing and Retrieving Data. Why Not Store Everything in Main Memory? Database Management Systems need to:

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Part IV I/O System Chapter 1 2: 12: Mass S torage Storage Structur Structur Fall 2010

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CISC 7310X. C11: Mass Storage. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/19/2018 CUNY Brooklyn College

Storing and Retrieving Data. Storing Data: Disks and Files. Solution 1: Techniques for making disks faster. Disks. Why Not Store Everything in Tapes?

Review question: Protection and Security *

Storing and Retrieving Data. Storing Data: Disks and Files. Solution 1: Techniques for making disks faster. Disks. Why Not Store Everything in Tapes?

CSCI-GA Operating Systems. I/O : Disk Scheduling and RAID. Hubertus Franke

Chapter 4 File Systems. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved

Disks and RAID. CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, E. Sirer, R. Van Renesse]

File Systems. File system interface (logical view) File system implementation (physical view)

Transcription:

File File System Implementation Operating Systems Hebrew University Spring 2009 Sequence of bytes, with no structure as far as the operating system is concerned. The only operations are to read and write bytes. Interpretation of the data is left to the application using it. File descriptor a handle to a file that the OS provides the user so that it can use the file 1 2 File Metadata Owner: the user who owns this file. Permissions: who is allowed to access this file. Modification time: when this file was last modified. Size: how many bytes of data are there. Data location: where on the disk the file s data is stored. File System Implementation We discuss the classical Unix File system All file systems need to solve similar issues. 3 4 Hardware background: Direct Memory Access When a process needs a block from the disk, the cpu needs to copy the requested block from the disk to the main memory. This is a waste of cpu time. If we could exempt the cpu from this job, it will be available to run other ready processes. This is the reason that the operating system uses the DMA feature of the disk controller. Disk access is always in full blocks. 5 Direct Memory Access Cont. Sequence of actions: 1. OS passes the needed parameters to the disk controller (address on disk, address on main memory, amount of data to copy) 2. The running process is transferred to the blocked queue and a new process from the ready queue is selected to run. 3. The controller transfers the requested data from the disk to the main memory using DMA. 6 4. The controller sends an interrupt to the cpu, 1

Disk Layout Boot Block for loading the OS (optional) Swap area (optional) Super Block File system management i-nodes File metadata Data blocks Actual file data Super Block Manages the allocation of blocks on the file system area This block contains: The size of the file system A list of free blocks available on the fs A list of free i-nodes in the fs And more... Using this information it is possible to allocate disk block for saving file data or file metadata 7 8 Mapping File Blocks It is inefficient to save each file as a consecutive data block. Why? How do we find the blocks that together constitute the file? How do we find the right one if we want to access the file at a particular offset? How do we make sure not to spend too much space on management data? We need an efficient way to save files of varying sizes. Distribution of File sizes Many very small files that use little disk space Some intermediate files Very few large files that use a large part of the disk space 9 10 The Unix i-node In Unix, files are represented internally by a structure known as an inode, it includes an index of disk blocks. The index is arranged in a hierarchical manner: Few direct pointers, which list the first blocks of the file (Good for small files) One single indirect pointer - points to a whole block of additional direct pointers (Good for intermediate files) One double indirect pointer - points to a block of indirect pointers. (Good for large files) One triple indirect pointer - points to a block of double indirect pointers. (Good for very large files) 11 i-node - Example Blocks are 1024 bytes. Each pointer is 4 bytes. The 10 direct pointers then provide access to a maximum of 10 KB. The indirect block contains 256 additional pointers, for a total of 266 blocks (266 KB). The double indirect block has 256 pointers to indirect blocks, so it represents a total of 65536 blocks. File sizes can grow to a bit over 64 MB. 12 2

i-node Structure i-node a more up-to-date example Blocks are 4096 bytes. Each pointer is 4 bytes. The 12 direct pointers then provide access to a maximum of 48 KB. The indirect block contains 1024 additional pointers, for a data of size (4 MB). The double indirect block has 1024 pointers to indirect blocks, so it points to 4GB of data The triple indirect block allow files of 4TB This is a 64bit implementation 13 14 i-node Allocation The super blocks caches a short list of free inodes. When a process needs a new inode, the kernel can use this list to allocate one. When an inode is freed, its location is written in the super block, but only if there is room in the list If the super block list of free inodes is empty, the kernel searches the disk and adds other free inodes to its list. To improve performance, the super block contains the number of free inodes in the file system. 15 Allocation of Disk Blocks When a process writes data to a file, the kernel must allocate disk blocks from the file system for direct or indirect block. Super block contains the number of free disk blocks in the file system. When the kernel wants to allocate a block from the file system, it allocates the next available block in the super block list. 16 Storing and Accessing File Data Storing data in a file involves: Allocation of disk blocks to the file. Read and write operations Optimization - avoid disk access by caching data in memory. Operations Open: gain access to a file. Close: relinquish access to a file. Read: read data from a file, usually from the current position. Write: write data to a file, usually at the current position. Append: add data at the end of a file. Seek: move to a specific position in a file. Rewind: return to the beginning of the file. Set attributes: e.g. to change the access permissions. 17 18 3

fd=open( myfile",r) fd=open( myfile",r) 19 1. The file system reads the current directory, and finds that myfile is represented internally by entry 13 in the list of files maintained on the disk. 20 fd=open( myfile",r) 2. Entry 13 from that data structure is read from the disk and copied into the kernel s open files table. fd=open( myfile",r) 21 3. User s access rights are checked and the user s variable fd is made to point to the allocated entry in the open files table 22 Why do we need the open file table? Temporal Locality principle. Saving disk calls. All the operations on the file are performed through the file descriptor. read(fd,buf,100) 23 24 4

read(fd,buf,100) 1. The argument fd identifies the open file by pointing into the kernel s open files table. read(fd,buf,100) 2. The system gains access to the list of blocks that contain the file s data. 25 26 read(fd,buf,100) read(fd,buf,100) 3. The file system reads disk block number 5 into its buffer cache. (full block = Spatial Locality) 27 4. 100 bytes are copied into the user s memory at the address indicated by 28 buf. Writing to a File Writing to a File Cont. Suppose the following scenario: 1. We want to write 100 bytes, starting with byte 2000 in the file. 2. Each disk block is 1024 bytes. Therefore, the data we want to write spans the end of the second block to the beginning of the third block. The full block must first be read into the buffer cache. Then the part being written is modified by overwriting it with the new data. 29 We will write 48 bytes at the end of block number 8 and the rest of the data should go into the third block. The third block must be allocated from the pool of free blocks. Let s assume that block number 2 on the disk was free, and that this block was 30 allocated. 5

Writing to a file Cont. The buffer cache The buffer cache is important to improve performance But it can cause reliability issues: It delays the writeback to disk Therefore if we are unlucky the data may be lost. Q. Is there a need to read it from the disk before modifying it? Since this is a new block, we can just allocate a block in the buffer cache, prescribe that it now represents block number 2, and copy the requested data to it (52 bytes). 31 Finally, the modified blocks are written back to the disk. 32 The Location in the File The read system call provides a buffer address for placing the data in the user s memory, but does not indicate the offset in the file from which the data should be taken. The operating system maintains the current offset into the file, and updates it at the end of each operation. If random access is required, the process can set the file pointer to any desired value by using the seek system call. 33 The main OS file tables The i-node table - each file may appear at most once in this table. The open files table an entry in this table is allocated every time a file is opened. Each entry contains a pointer to the inode table and a position within the file. There can be multiple open file entries pointing to the same i-node. The file descriptor table separate for each process. Each entry points to an entry in the open files table. The index of this slot is the fd that was returned by open. 34 Sharing a File Sharing a File - Cont. Assume there is a log file that needs to be written by more than one process. If each process has its own file pointer, there is a danger that one process will overwrite log entries of another process. If the file pointer is shared, each new log entry will indeed be added to the end of the file. The three OS file tables allow us to control sharing and permissions The file descriptor table adds a level of indirection, so the user cannot guess open files to bypass access permissions. 35 36 6

RAID Structure Problems with disks Data transfer rate is limited by serial access. Reliability Solution to both problems: Redundant arrays of inexpensive disks (RAID) In the past, RAID (combination of cheap disks) was an alternative for large and expensive disks. Today: RAID is used for higher reliability and higher datatransfer rate. So the I in RAID stands for independent instead of inexpensive. So RAID now stands for Redundant Arrays of Independent Disks. 37 RAID Approaches RAID 1: mirroring there are two copies of each block on distinct disks. This allows fast reading (you can access the less loaded copy), but wastes disk space and delays writing. 38 RAID Approaches - Cont RAID Approaches - Cont RAID 3: parity disk data blocks are distributed among the disks in roundrobin manner. For each set of blocks, a parity block is computed and stored on a separate disk. If one of the original data blocks is lost due to a disk failure, its data can be reconstructed from the other blocks and the parity. Example: disk 1 disk 2 0110 1000 disk 3 0010 parity 1100 RAID 5: distributed parity in RAID 3, the parity disk participates in every write operation (because this involves updating some block and the parity), and becomes a bottleneck. The solution is to store the parity blocks on different disks. 39 40 Disk Structure I/O Management and Disk Scheduling Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer. The 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially. Sector 0 is the first sector of the first track on the outermost cylinder. Mapping proceeds in order through that track, then the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost. 41 42 7

Moving-Head Disk Mechanism Disk Scheduling The operating system is responsible for using hardware efficiently - having a fast access time and disk bandwidth. Access time has two major components Seek time is the time for the disk to move the heads to the cylinder containing the desired sector. Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head. Minimize seek time Seek time seek distance Disk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer. 43 44 Disk Scheduling - Cont. Whenever a process needs I/O from the disk, it issues a system call to the OS with the following information. Whether the operation is input or output What the disk address for the transfer is What the memory address for the transfer is What the number of bytes to be transferred is. Several algorithms exist to schedule the servicing of disk I/O requests. We illustrate them with a request queue (0-199). 98, 183, 37, 122, 14, 124, 65, 67 45 46 Head pointer 53 FCFS Advantage: fair Disadvantage: slow FCFS Illustration shows total head movement of 640 cylinders. Shortest-Seek-Time-First (SSTF) Selects the request with the minimum seek time from the current head position. SSTF scheduling is a form of SJF scheduling May cause starvation of some requests. Illustration shows total head movement of 236 cylinders. SSTF - Cont. Total head movement=236 cylinders 47 48 8

Selecting a Disk-Scheduling Algorithm SSTF is common and has a natural advantage over FCFS There are other algorithms that perform better for systems that place a heavy load on the disk (little chance to starvation). Performance depends on the number and types of requests. Requests for disk service can be influenced by the file-allocation method. 49 9