






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Operating Systems is necessary course in Computer Science. Its about threading, process scheduling, deadlocks, memory management etc. This lecture includes: Space, Allocation, Free, Space, Structure, Scheduling, Index, Block, Header, Externel, Fragmentation
Typology: Study notes
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Operating Systems Lecture No. 45
Chapters 12 and 14 of the textbook Lecture 45 on Virtual TV
Space Allocation Techniques (continued) Free Space Management Disk Structure and Scheduling
Indexed allocation supports direct access without suffering from external fragmentation because any free block on the disk may satisfy a request for more space. Depending on the disk block size and file system size, a file may need more than one index block. In this case there are two ways of organizing index blocks:
LLiinnkkeedd sscchheemmee ((lliinnkkeedd lliisstt ooff iinnddeexx bblloocckkss)) An index block is normally one disk block. Thus, it can be read and written directly by itself. To allow for large files, we may link together several index blocks. For example, an index block might contain a small header giving the name of the file and a set of first 100 disk-blocks addresses. The next address (the last word in the index block) is nil (for a small file) or a pointer to another index block (for a large file), as shown below.
Linked scheme for interconnecting index blocks
Directory Entry
MMuullttii--lleevveell iinnddeexx sscchheemmee The second method of handling multiple index blocks is to maintain multi-level indexing. In the following diagram, we show two-level index table.
Two level Index Table
The UNIX file manager uses a combination of indexed allocation and linked lists for the index table. It maintains 10-15 direct pointers to file blocks, and three indirect pointers (one-level indirect, two-level indirect, and three-level indirect), all maintained in file’s inode, as shown below.
UNIX inode
Let’s consider a UNIX system with following attributes:
Directory Entry
File Data Block
First Level Index
SSiinnccee ddiisskk ssppaaccee iiss lliimmiitteedd,, wwee nneeeedd ttoo rreeuussee tthhee ssppaaccee ffrroomm ddeelleetteedd ffiilleess ffoorr nneeww ffiilleess iiff ppoossssiibbllee.. TToo kkeeeepp ttrraacckk ooff ffrreeee ddiisskk ssppaaccee,, tthhee ssyysstteemm mmaaiinnttaaiinnss aa ffrreeee--ssppaaccee lliisstt.. TThhee ffrreeee ssppaaccee lliisstt rreeccoorrddss aallll frfreeee ddiisskk bblloocckkss--tthhoossee nnoott aallllooccaatteedd ttoo ssoommee ffiillee oorr ddiirreeccttoorryy.. TToo ccrreeaattee aa ffiillee wwee sseeaarrcchh tthhee ffrreeee--ssppaaccee lliisstt ffoorr tthhee rreeqquuiirreedd aammoouunntt ooff ssppaaccee aanndd aallllooccaattee tthhee ssppaaccee ttoo tthhee nneeww ffiillee.. TThhiiss ssppaaccee iiss tthheenn rreemmoovveedd ffrroomm tthhee ffrreeee--ssppaaccee lliisstt.. WWhheenn aa ffiillee iiss ddeelleetteedd,, iittss ddiisskk ssppaaccee iiss aaddddeedd ttoo tthhee ffrreeee ssppaaccee lliisstt..
BBiitt vveeccttoorr FFrreeqquueennttllyy,, tthhee ffrreeee ssppaaccee lliisstt iiss iimmpplleemmeenntteedd aass aa bbiitt mmaapp oorr bbiitt vveeccttoorr.. EEaacchh bblloocckk iiss rreepprreesseenntteedd bbyy 11 bbiitt.. IIff tthhee bblloocckk iiss ffrreeee,, tthhee bbiitt iiss 11;;iiff iitt iiss aallllooccaatteedd,, tthhee bbiitt iiss 00.. TThhiiss aapppprrooaacchh iiss rreellaattiivveellyy ssiimmppllee aanndd eeffffiicciieenntt iinn ffiinnddiinngg tthhee ffiirrsstt ffrreeee bblloocckk oorr nn ccoonnsseeccuuttiivvee ffrreeee bblloocckkss oonn tthhee ddiisskk..
0 0 11 2 2 nn--1 1
TThhee ccaallccuullaattiioonn ooff bblloocckk nnuummbbeerr iiss:: ((number of bits per word) * (number of 0-value words) + offset of first 1 bit
Example for (^) oovveerrhheeaadd ooff bbiitt mmaapp
Block size = 4 KB = 2^12 bytes Disk size = 40 GB = 40 * 2^30 bytes Overhead = 40 * 2^30 /2^12 = 40 * 2^18 bits = 40 * 32 KB = 1280 KB
LLiinnkkeedd lliisstt ((ffrreeee lliisstt)) Another approach to free space management is to link together all the free disk blocks, keeping a pointer to the first free block in a special location on the disk and caching it in memory. The first block contains a pointer to the next free disk block and so on. However this scheme is not efficient. To traverse the list, we must read each block, which requires substantial I/O time. It cannot get contiguous space easily. The following diagram shows an example of free space management by using the linked list approach.
0 2
bit[i]{
0 block[i] is free 1 block[i] is occupied
Linked free space list on disk Similar to the example given for the bit map above, you can calculate the overhead for maintaining free space with linked list. We leave it as an exercise for you.
GGrroouuppiinngg A modification of free-list approach is to store the addresses of n free blocks in the first free block. The first n-1 blocks of these blocks are actually free. The last block contains addresses of the next n free blocks, and so on. The importance of this implementation is that the addresses of a large number of free blocks can be found quickly.
CCoouunnttiinngg We keep the address of the first free block and the number n of free contiguous blocks that follow the first block in each entry of a block. This scheme is good for contiguous allocation. Although each entry requires more space, the overall list will be shorter.
A number of I/O operations (inserting, deleting, and reading a file block) needed for the various allocation schemes indicate the goodness of these schemes. The following example illustrates this.
Assumptions Directory, Bit-map, and index blocks are in the main memory Worst-case and best-case scenarios File size of 100 blocks
Determine the number of I/O operations needed to
Disks provide the bulk of secondary storage for modern computer systems. Magnetic tape was used as an early secondary storage medium but the access is much slower than for disks. Thus tapes are currently used mainly for backup, for storage of infrequently used information etc. Modern disk drives are addressed as large one dimensional array of logical blocks, where the logical block is the smallest unit of transfer. The size of a logical block is usually 512 bytes, although some disks can be low-level formatted to choose a different logical block size, such as 1024 bytes. The one dimensional array of logical blocks is mapped onto the sectors of the disk sequentially. Block 0 is the first sector of the first track on the outermost sector. The mapping proceeds in order through that track, then through the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to the innermost. By using this mapping, we can – at least in theory – convert a logical block number into an old style disk address that consists of a cylinder number, a track number within the cylinder and a sector number within that rack. In practice it is difficult to perform this translation for two reasons. First, most disks have some defective sectors but the mapping hides this by substituting spare sectors from elsewhere on the disk. Second, the number of sectors per track is not a constant on some drives. On media that use a constant linear velocity (CLV) the density of bits per track is uniform. The farther a track is from the center of the disk, the greater its length so the more sectors it can hold. As we move from the outer zones to the inner zones, the number of sectors per track decreases. Tracks in the outermost tracks typically hold 40% more sectors than do tracks in the innermost zone. The drive increases its rotation speed as the head moves from the outer to the inner tracks to keep the same rate of data, moving under the head. Alternatively the disk rotation speed can stay constant and the density of bits decreases from inner tracks to outer tracks to keep the data rate constant. This method is used in hard disks and is known as constant angular velocity (CAV).
One of the responsibilities of the operating system is to use the computer system hardware efficiently. For the disk drives, meeting this responsibility entails having a fast access time and disk bandwidth. The access time has two major components. The seek time is the time for the disk arm to move the heads to the cylinder containing the desired sector. The rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head. The 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. We can improve both the access time and the bandwidth by scheduling the servicing of disk I/O requests in a good order. Some of the popular disk-scheduling algorithms are: First-come-first-serve (FCFS) Shortest seek time first (SSTF) Scan Look Circular scan (C-Scan) Circular look (C-Look)
We now discuss the first four of these algorithms with an example each. We assume a disk with 200 cylinders.
First Come First Served Scheduling The simplest form of disk scheduling is FCFS. This algorithm is intrinsically fair, but it generally does not provide the fastest service. Consider for example a disk queue with requests for I/O to blocks on cylinders
98,183,37,122,14,124,65,
in that order. If the disk head is initially at cylinder 53 and the direction of movement is from left to right (i.e., from cylinder 0 to cylinder 199), it will first move from 53 to 98, then to 183, 37, 122, 14, 124, 65 and finally to 67, for a total head movement to of 640 cylinders.
First-come-first-serve disk scheduling example
The wild swing from 122 to 14 and then back to 124 illustrates the problem with this schedule. If the requests for cylinders 37 and 14 could be serviced together before or after the requests at 122 and 124, the total head movement could be decreased substantially and performance could be thereby improved.
SSTF Scheduling It seems reasonable to service all the requests close to the current head position, before moving the head far away to service other requests. This assumption is the basis for the shortest seek time first (SSTF) algorithm. The SSTF algorithm selects the request with the minimum seek time from the current head position. Since seek time increases with the number of cylinders traversed by the head, SSTF chooses the pending request closest to the current head position.
Scan disk scheduling algorithm with disk head moving from right to left
Look algorithm This algorithm is a version of SCAN. In this algorithm the arm only goes as far as the last request in each direction, then reverses direction immediately, serving requests while going in the other direction. That is, it looks for a request before continuing to move in a given direction. For the given reques queue, the total head movement (seek distance) for the Look algorithm is 208.
Look disk scheduling algorithm with the disk head moving from righ to left
C-Scan and C-Look algorithms In the C-Scan and C-Look algorithms, when the disk head reverses its direction, it moves all the way to the other end, without serving any requests, and then reverses again and starts serving requests. In other words, these algorithms serve requests in only one direction.