Files and Disks

  • View
    2

  • Download
    0

Embed Size (px)

DESCRIPTION

This presentation brings information about the storage and retrieval of file on disks

Text of Files and Disks

  • Chap 0 Input and Output (IO)In addition to processing the job (using CPU and memory), IO is the main job of a computer systemInput and output are typically carried out by peripheral devices, managed by the IO subsystem of the kernelEvery device has a corresponding device driver that manages the interface (IF) between device and kernelAll device drivers are typically implemented with a single interface that the kernel understands (syscalls?)Operations: open, close, initialize, read, writeTypically the device manufacturer provides the IF

    Chap 0

  • Chap 0HardwareCPUcachecachesystem busmonitorgraphicscontrollerIDE DiskControllerdisk 1disk n...

    Chap 0

  • Chap 0Communicating with a DeviceThe device driver (DD) has to communicate with the device to give it commands and receive feedbackSo-called IO-instructions read/write data to an IO-portusually a register communicates directly with the device (i.e., whenever a write is done on an IO port, the device subsequently receives the data)Another way of doing it is using memory-mapped IOsame idea, but the communication is done through specific (predefined) memory locationsSome systems use both (for example, a monitor has IO-ports for control and memory-mapped IO for large data transfers)

    Chap 0

  • Chap 0Communication (cont)Two ways of CPU-device communication:Polling: the device is asked (polled) whether it has data 1- host checks the status register for that device 2- host tells the device to go ahead 3- device writes data/command to the IO-portallows CPU to control how/when it interacts with device, but large overhead if it has to poll repeatedlyInterrupts: the device takes the initiative 1- the device interrupts CPU to pass on data/commands 2- CPU does a context switch to process the interrupt 3- CPU returns from interrupt and resumes processCPU doesnt waste time polling, but has no control of when device will interrupt

    Chap 0

  • Chap 0Real-Time Systems Device CommunicationIn real-time systems (RTSs), due to deadlines, devices are usually not allowed to interrupt when they want a mal-functioning device could bring down the systemIn RTSs, many tasks are periodic (reading sensors, sending commands to actuators)If polling is used, need to guarantee that IO will be done in a timely fashionIf interrupts are used, need to guarantee that they will not violate the deadline guarantees given to processes

    Chap 0

  • Chap 0Handling InterruptsInterrupt controller hardware provides ability to :defer interruptscall the proper interrupt service routine (ISR)distinguish and prioritize between high- and low-priority interruptsIn addition, processors can (and do!) mask interruptsdisallow some interrupts to occur to process other stuffhowever, there is the non-maskable interrupt (emergency)

    Chap 0

  • *More on InterruptsInterrupt vectors are very common: keep the address of the ISR in a fixed location, the hardware will read the number of the interrupt and jump to the appropriate location The interrupt handler will not have its own stack. However, it will execute on top of the kernel stack, not in the user stackThis is because there is little control over the size of the user stack and the ISR may run out of memory

  • Chap 0Interacting with DevicesSometimes a mixture of interrupts and IO using direct memory access (DMA) is beneficial.A disk that has to read large data block to position X:receives the request, reads the dataasks the DMA controller to put it in the memory location Xand then, finally, interrupts the CPUThe DMA controller and the disk exchange information (a protocol) to be able to do this transferIn some architectures this is called cycle stealing, since the bus is used to transfer data into the memory and thus the CPU cannot use the memory in those cycles

    Chap 0

  • Chap 0Kernel IO SubsystemThe users want to use the devices. How to achieve it?The user uses a library that invokes system calls in the OS.The system calls get translated into device driver requestsThe DDs request service from the IO controllers, who talk to the deviceWhen the service is done, the controller sends an interrupt, to signal CPU

    Chap 0

  • Chap 0Disk as a case studyA disk drive has several physical componentsspindlesurface (one side in the pack) read/write arm and head cylinder (or track) sector

    Chap 0

  • Chap 0Accessing the DiskA disk is accessed through the library, file system, DevDriver and disk controllerThe calls to the controller are called disk drive commands, such as drive select, head select, direction, read/write, data out, etcThe disk controller does the synchronization between disk and OS, signaling/timing, some error controlSeveral users may request data to/from the disk at onceThe file system is the first entity to recognize it and synchronize access to the disk

    Chap 0

  • Chap 0Accessing the Disk (cont)The FS does the scheduling of the requests, that is, it determines the order in which the requests are servicedThe FS and DD also use buffering for synchronization (support speed/data size mismatch between OS-device)The user, FS, and DD have different ideas (abstraction) of how the file looks like.user: contiguous space, byte by bytefile system: blocks of data, with logical addressesDD: sectors in disk, in specific hardware addresses (typically consists of < cyl, track, sect >

    Chap 0

  • Chap 0Accessing the Disk (cont)The translations take place each time a new interface is crossedThe file-relative logical address The volume-relative logical address The drive-relative physical address Some disks have also a zone, and the physical address becomes < cyl, zone, track, sect >This is because the length of outer tracks /cylinders compared with inner tracks/cylinders (density)

    Chap 0

  • Chap 0Accessing the Disk (cont)When we need to access a sector, the disk head needs to be positioned over that sector (or more accurately, the disk must rotate until the sector is under the head)For that, several delays are involved in the disk operation, in decreasing timeseek delay: position HEAD on correct track/cylinderrotational delay: position correct SECTOR under headtransfer delay: transfer data to/from memoryTherefore, it is important to minimize the highest delay, namely, the seek delay

    Chap 0

  • Chap 0Improve Disk SpeedIncrease buffering in the device driver and/or disk controller (this is a type of cache)Reduce rotational delay:place blocks of the same file in the same cylinderread the blocks in the appropriate orderallow block interleaving (clearly, the number of sectors in the disk should be odd, unlike the drawing)1234

    Chap 0

  • Chap 0InterleavingInterleaving is done in the device driver, since it will have to tell the controller where to place sectors in the disk. Clearly, interleaving is tightly coupled with the device itselfThe device decides the interleaving degree (how many sectors to skip over), which is tightly coupled with the speeds of the diskRotationalSeek (or arm speed) Transfer

    Chap 0

  • Chap 0Improve Disk Speed (cont)To decrease seek delays one can:increase the number of headspark the head in the middle track of the disk to decrease the average seek delayplace the data in the appropriate locations (tracks)The organ pipe distribution does the last trickcreate a histogram of the disk block usage (count the number of times that disk blocks are used)place most used blocks in the middle trackspindle

    Chap 0

  • Chap 0Improve Disk Speed (cont)RAID: Redundant Array of Inexpensive DisksAllows for more parallelism when retrieving datastore each part of a block in a separate disk, and allow all sub-blocks to be retrieved in parallelIf disks are homogeneous and synchronized, even better performance can be achievedIf disks are heterogeneous or not synchronized, performance is worse since it depends on the slowest of the disks, or the one off phase.can use slower, cheaper disks

    Chap 0

  • *Possible File StructuresNone - sequence of words or bytesSimple record structureLines Fixed lengthVariable lengthComplex StructuresFormatted documentRelocatable load fileCan simulate last two with first method by inserting appropriate control characters.Who decides:Operating systemProgram

  • *File AttributesName only data kept in human-readable form.Type needed for supporting different file types.Location pointer to file location on device.Size current file size.Protection controls who can do reading, writing, executing, access, etc.Time, date, and user identification data for protection, security, and usage monitoring.Information about files are kept in the directory structure, which is maintained on the disk.

  • *File Operationscreatewritereadfile seek: reposition within filedeletetruncateopen(Fi) search the directory structure on disk for entry Fi, and move the content of entry to memory.close (Fi) move the content of entry Fi in memory to directory structure on disk.

  • *Directory StructureA collection of nodes containing information about all files.Both the directory structure and the files reside on disk.Backups of these two structures are kept on tapes.

  • *Information in a Device DirectoryName TypeAddress Current lengthMaximum lengthDate last accessed (for archival)Date last updatedOwner IDProtection information

  • *Operations Performed on a DirectorySearch for a fileCreate a fileDelete a fileList a directoryRename a fileTraverse the file system

  • *Logical Directory OrganizationGoals:Efficiency locating a file quickly.Naming convenient to users.Two users can have same name for different files.The same file can have several different names.Grouping logical grouping of files by propertie