File Systems Lab

  • Upload
    dv

  • View
    225

  • Download
    0

Embed Size (px)

Citation preview

  • 8/13/2019 File Systems Lab

    1/19

    Operating Systems

    6 File SystemsLab notes

    Course lectured by Prof. Gabriel Kuper

    Lab assist. Ilya Zaihrayeu

    http://www.dit.unitn.it/~ilya/os.htm

  • 8/13/2019 File Systems Lab

    2/19

  • 8/13/2019 File Systems Lab

    3/19

    Ilya Zaihrayeu Operating Systems Course 3

    Recall: file allocation strategies

    contiguous

    linked

    indexed

  • 8/13/2019 File Systems Lab

    4/19

    Ilya Zaihrayeu Operating Systems Course 4

    File allocation strategies, contd

    A:Operations: read blocks + write blocks + write the file control

    block

    0r + 1w = 199r + 2w = 1010r + 1w = 1f)

    0r + 1w = 150r + 1w = 51

    51r + 1w = 52

    49r + 50w = 99

    50r + 51w = 101

    e)

    0r + 1w = 11r + 1w = 299r + 100w =199d)

    0r + 2w = 21r + 3w = 40r + 2w = 2c)0r + 2w = 250r + 2w = 5250r + 52w = 102b)

    0r + 2w = 20r + 2w = 2100r + 102w=202a)

    IndexedLinkedContiguous

  • 8/13/2019 File Systems Lab

    5/19

    Ilya Zaihrayeu Operating Systems Course 5

    File allocation strategies-2

    Q: One way to use contiguous allocation of the diskand not suffer from holes is to compact the diskevery time a file is removed.

    Since all files are contiguous, copying a file requires aseek and rotational delay to read the file, followedby the transfer at full speed. Writing the file backrequires the same work.

    a) Assuming a seek time of 5 msec, a rotational delayof 4 msec, a transfer rate of 8 MB/sec, and anaverage file size of 8 KB, how long does it take toread a file into main memory then write it back to the

    disk at a new location?b) Using these numbers, how long would it take to

    compact half of a 16-GB disk?

  • 8/13/2019 File Systems Lab

    6/19

    Ilya Zaihrayeu Operating Systems Course 6

    File allocation strategies-2, contd

    A:

    a) Time to read a file = seek time + latency time

    + read time = 5 msec + 4 msec + 8 KB / (8 *1024 KB / 1 * 1000 msec) 0.98 msec

    Therefore read + write = 2 * 0.98 msec = 1.96

    msecb) Half of a 16-GB disk is 8 GB = 8 388 608 KB

    That is approximately 1 048 576 files. Each file

    takes 1.96 msec, thus the whole processwill take about 2055 sec, i.e. about 34 min

  • 8/13/2019 File Systems Lab

    7/19

    Ilya Zaihrayeu Operating Systems Course 7

    Free disk space management

    Q: Free disk space can be kept track of using a

    free list or a bit map. Disk addresses require

    D bits. For a disk with B blocks, F of whichare free, state the condition under which the

    free list uses less space than the bit map.

    For D having the value 16 bits, express your

    answer as a percentage of the disk spacethat must be free.

  • 8/13/2019 File Systems Lab

    8/19

    Ilya Zaihrayeu Operating Systems Course 8

    Free disk space management, contd

    A:

    The bit map requires B blocks, whereas the

    free list requires F*D bits. Thus the statewhen the free list uses less space than the bitmap is F*D < B.

    The percentage of disk space free is given bythe fraction F/B. F*D less than B becomes

    F/B less than 1/D. If D is 16, then this fractionis 1/16 or 6.25 percent

  • 8/13/2019 File Systems Lab

    9/19

    Ilya Zaihrayeu Operating Systems Course 9

    File system consistency

    Q: A file system checker has built up its counters as

    shown bellow

    Are there any errors? If so, are they serious? Why?

    How to fix them?

    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

    In use 1 1 0 1 0 1 2 1 1 0 0 1 1 1 0 0

    free 0 0 0 0 2 0 0 0 0 1 1 0 1 0 1 1

  • 8/13/2019 File Systems Lab

    10/19

    Ilya Zaihrayeu Operating Systems Course 10

    Recall: file system consistency

    Initially:

    Checking i-nodes: if a blockis referenced, its number Inuse is incremented

    Checking free lists or bitmaps: if a block is

    referenced, its number freeis incremented

    If the system is consistent,each block will have 1 either

    in In use or in free (in thisexample the system isinconsistent)

    0 1 2 3 4 5 6

    In use 0 0 0 0 0 0 0

    free 0 0 0 0 0 0 0

    0 1 2 3 4 5 6

    In use 0 2 0 1 0 0 0

    free 0 0 0 0 0 0 0

    0 1 2 3 4 5 6

    In use 0 2 0 1 0 0 0

    free 1 0 1 0 1 1 1

    0 1 2 3 4 5 6

    In use 0 2 0 1 0 0 0

    free 1 0 1 0 1 1 1

  • 8/13/2019 File Systems Lab

    11/19

    Ilya Zaihrayeu Operating Systems Course 11

    File system consistency, contd

    A:

    Block 2 is not reported in either table (missing block). Not

    serious, but wastes space. Add it to the free list Block 4 is twice in a free list. Not serious at the moment. Just

    fix the free list

    Block 6 is present in 2 files at the same time. If a file is

    removed then the block will appear in the both lists. Thesolution is to allocate a free block, copy the contents of 6

    there, and insert the copy onto one of the files

    Block 12 is present in the both lists. Remove it from the free

    list

    0 1 2 3 4 5 6 7 8 9 10 111213 14 15

    In use 1 1 0 1 0 1 2 1 1 0 0 1 1 1 0 0

    free 0 0 0 0 2 0 0 0 0 1 1 0 1 0 1 1

  • 8/13/2019 File Systems Lab

    12/19

    Ilya Zaihrayeu Operating Systems Course 12

    Free memory space management

    Q: The beginning of a free space bitmap looks like thisafter the disk partition is first formatted:1000 0000 0000 0000 (the first block is used by the

    root directory).The system always searches for free blocks startingat the lowest numbered block, so after writing file A,which uses 6 blocks, the bitmap looks like this: 1111

    1110 0000 0000. Show the bitmap after each of thefollowing additional actions:

    a) File B us written, using 5 blocks.

    b) File A is deleted.

    c) File C is written, using 8 blocks.d) File B is deleted

  • 8/13/2019 File Systems Lab

    13/19

    Ilya Zaihrayeu Operating Systems Course 13

    Free memory space management, contd

    A:

    a) 1111 1111 1111 0000

    b) 1000 0001 1111 0000

    c) 1111 1111 1111 1100

    d) 1111 1110 0000 1100

    A B

    B

    BC C

    C C

  • 8/13/2019 File Systems Lab

    14/19

    Ilya Zaihrayeu Operating Systems Course 14

    Free memory space management-2

    Q: A certain file system uses 2 KB disk blocks.

    The median file size is 1 KB. What fraction of

    the disk space is wasted for 1 KB files? Howmight you justify wasting the disk space?

  • 8/13/2019 File Systems Lab

    15/19

    Ilya Zaihrayeu Operating Systems Course 15

    Free memory space management-2, contd

    A: The 1 KB median file size consumes only half of the 2 KB

    disk block, and thus leads to 50% wasted disk space

    Because disks generally read large disk blocks more efficiently,

    and realistic file systems include large files, disk performance

    can justify the wasted disk space

    2K

  • 8/13/2019 File Systems Lab

    16/19

    Ilya Zaihrayeu Operating Systems Course 16

    Directories and files

    Q: How many disk operations are needed to

    fetch the i-node for the file

    /usr/ast/courses/os/handout.t?

    Assume that the i-node for the root directory is

    in memory, but nothing else along the path is

    in memory. Also assume that all directories fit

    in one disk block.

  • 8/13/2019 File Systems Lab

    17/19

    Ilya Zaihrayeu Operating Systems Course 17

    Recall: i-nodes

    I-node stores the attributes

    and disk addresses of a

    files blocks

    The first few addresses are

    stored in the i-node itself

    Additional addresses are

    available via single, doubleand triple indirect blocks

    reference

    In UNIX directories are

    implemented as i-nodes

  • 8/13/2019 File Systems Lab

    18/19

    Ilya Zaihrayeu Operating Systems Course 18

    Directories and files, contd

    A: Since all directories fit in one disk block then all required data ona directory is stored in the i-node itself

    To open /usr/ast/courses/os/handout.t, assuming the root i-node is

    already in memory, we do the following reads:

    1: directory /2: i-node for /usr3: directory /usr4: i-node for /usr/ast5: directory /usr/ast6: i-node for /usr/ast/courses7: directory /usr/ast/courses

    8: i-node for /usr/ast/courses/os/9: directory /usr/ast/courses/os/10: i-node for /usr/ast/courses/os/handout.t

  • 8/13/2019 File Systems Lab

    19/19

    Ilya Zaihrayeu Operating Systems Course 19

    References

    Andrew S. Tanenbaum, Modern Operating

    Systems

    Silberschatz Galvin, Operating System

    Concepts