Work Sheet 11 1.What is a contiguous allocation and what are the main difficulties associated with it. ### The contiguous allocation method requires each file to occupy a set of contiguous blocks on the disk. Contiguous allocation of a file is defined by the disk address and length of the first block. The main difficulties associated with it includes: finding space for a new file; external fragmentation; determining how much space is needed for a file. 2.Rank the allocation methods on speed. ### For sequential acess: contiguous allocation and linked allocation requires only one access to get a disk block;indexed allocation depends on the index structure, on the size of the file, and on the position of the block desired, may required one, two or more access to get a disk block. For direct acess: contiguous allocation requires only one access; indexed allocation depends on the index structure, on the size of the file, and on the position of the block desired, may required one, two or more access to get a disk block; for linked allocation, an access to the ith block might require i disk reads. 3.Explain different methods for allocating space for contiguous files. ### First-fit: allocate the first space that is big enough; Best-fit: allocate the smallest space that is big enough; Worst-fit: allocate the largest space. 4.List four ways a system could use to determine which sectors are free. Give advantage of each. ### Bit vector: the main advantage of this approach is that its is relatively simple and efficient to find the first free block, or n consecutive free blocks on the disk; Linked list: It only keeps a pointer to the first free block in a special location on the disk and acching it in memory, and can save the space; Grouping: the importance of this implementation is that the addresses of a large number of free blocks can be found quickly; Counting: Only keep the free-sapce list that consists of a disk address and a count, and can save the space. 5.What data-structures can be used for directory information? What are its advantages and disadvantages? ### Linear list: this method is simple to program but time-consuming to execute, and its real disadvatage is the linear search to find a file; Hash table: fast and efficient; unfortunately, damage to the table or a systme creash conld result in the direcotry information not corresponding to the disks' contents. 6.Do problems 11.1, 11.4, 11.6 and 11.8 ### 11.1,11.4, 11.6 ### Please see worksheet 10. 11.8 ### In the typical disk devices, we locate a file with its directory and file name rather than registers. Thus, when we relocate files, we only change the file physical address, but keep its directory and filename. The reasons why recompacting and relocation of files often are avoided: time cost is too high; system operation generally cannot be permitted; for sequential files, general used to backup, exist less fragmentation, and for direct acess files, new free space can merge with fragmentation. Work Sheet 12 1.Explain the meanings of port, bus, controller, device driver. ### Port is the connection point that the device communicates with the machine; Bus is a set of wires and a rigidly defined protocol that specifies a set of messages that can be sent on the wires; Controller is a collection of electronics that can operate a port, a bus, or a device; Device driver present a uniform device-access interface to the I/O subsystem, much as system calls provide a standard interface between the application and the operating system. 2.What is meant by polling? ### In fact, polling is in a loop, reading the status register over and over until the busy bit becomes clear. 3.Explain different types of I/O devices. ### According to their characteristics, I/O devices divide into different types: Character-stream or block device; sequential or random-access device; synchronous or asynchronous device; sharable or dedicated device; read-write, read only, or write only device etc. 4.Explain what is meant by DMA and what are some of DMA devices? ### DMA means Direct Memory Access. After setting up buffers, pointers, and counters for the I/O device, the device controller transfers an entire block of data directly to or from its own buffer storage to memory, with no intervention by the CPU. Only one interrupt is generated per block, rathter than the one interrupt per byte(or word) generated for low-speed devices. Such as tape, disk, or communications network are DMA devices. 5.Do problems 12.2, 12.4, 12.8 and 12.10 ### 12.2 ### a. Buffering; polling I/O. To b. Spooling; Interrupt-driven I/O. c. Caching and buffering; Interrupt-driven I/O. d. Buffering; Interrup-driven I/O. Choosing buffering mainly because of coping with a speed mismatch. Choosing caching because it can improve the accessible speed. Choosing spooling because it is a buffer that holds output for a device. Modern operating system always prefer to interrupt-driven I/O instead of polling I/O. As for mouse, we can use polling I/O because no much data need transfer and it is interactive. 12.4 ### Blocking I/O: text interface for only keyboard input; command line interface; select system call for network sockets (set it > 0); Nonblocking I/O: A user interface that receives keyboard and mouse input while processing and displaying data on the screen; a video application that reads frames from a file on disk while simultaneously decompressing and displaying the output on the display; the select system call for network sockets (set it to 0). Just implementing nonblicking I/O and having processes busy-wait's cost is high. 12.8 ### To initiate a DMA transfer, the host writes a DMA command block into memory. This block contains a pointer to the source of a transfer, a pointer to the destination of the tranfer, and a count of the numberof bytes to be transferred. The CPU writes the address of this command block to the DMA controller, then goes on with other work. The DMA controller then proceeds to operate the memory bus directly, placing addresses on the bus to perform transfers without the help of the main CPU. To implement DMA, handshaking between the DMA controller and the device controller, tranfering data, seizing the memory bus and interrupting the CPU all are needed. Thus, its hardware is complicated. 12.10 ### Because I/O is a major factor in system performance. If the CPU speed increase but system bus and device speeds can't scale up, the CPU can't spped up for waiting the I/O service. Then, the system bus and device speeds become bottle neck. So, it is important to scale up system bus and device speeds while the CPU speed increases. Work Sheet 13 1.Explain the meanings of sector, track and cylinder. ### Sector is the smallest addressable portion of a disk; Track is a circular set of sectors in a platter; Cylinder is a set of tracks that are at one arm position. 2.How is the information on the track referenced? ### The one-dimensional array of logical blocks is mapped onto the sectors of the disk sequentially. Sector 0 is the first sector of the first track on the outermost cylinder. The mapping then proceeds in order through that track, then through the rest of the tracks in that cyclinder, and then through the rest of the cylinders from outermost to innermost. 3.What characteristics determine the disk access speed? ### Seek time and Rotational latency determine the disk access speed. Seek time is the time for the disk arm to move the heads to the cylinder containing the desired secotr; The rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head. 4.What information is needed for disk I/O? ### Whether this 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 transfered is. 5.Do problems 13.1, 13.2, 13.6 and 13.13 ### 13.1 ### a. FCFS apparently is truly fair since it services accoring to time order. Suppose we have this case: the prevouse is 50, cuurntly at request at 100, and in FIFO order is 51, 100, 70, 100, 90, 100, 10, 100, ..., 100, ..., 100, We must have a starvation since it stays in cyclinder 100 all the time either SSTF, SCAN , LOOK etc. b. If SCAN can ensure to advance one cyclinder every time, it can ensure fairness. c. In time-sharing system, many users share the computers simultaneously. We must ensure every user gets a limit response time. That means starvation can't occur and should be fairness. d. Batdh jobs; heavy load on the disk; efficiecy is very importang. 13.2 ### a. FCFS: 143 -> 86 -> 1470 -> 913 -> 1774 -> 948 -> 1509 -> 1022 -> 1750 -> 130 total= 7081 b. SSTF 143 -> 130 -> 86 -> 913 -> 948 -> 1022 -> 1470 -> 1509 -> 1750 -> 1774 total= 1745 c. SCAN 143 -> 913 -> 948 -> 1022 -> 1470 -> 1509 -> 1750 -> 1774 -> 4999 -> 130 -> 86 total= 9769 d. LOOK 143 -> 913 -> 948 -> 1022 -> 1470 -> 1509 -> 1750 -> 1774 -> 130 -> 86 total = 3319 e. C-SCAN 143 -> 913 -> 948 -> 1022 -> 1470 -> 1509 -> 1750 -> 1774 -> 4999 ->0 -> 86 -> 130 total = 9985 13.6 ### For SCAN: type SCAN=monitor; var cyl: array [1..cylinderMAX] of condition; var cur,step=1; procedure entry request(i:0..cylinderMAX) begin cyl[i].wait; ... service ... cyl[i].signal; end procedure service(i:0..cylinderMAX) begin cyl[i].signal; cyl[i].wait; end begin while(true) cur=cur+step; if(cur==cylinderMAX) step=1; if(cur==cylinderMAX) step=-1; service(cur); endwhile end For C-SCAN: type SCAN=monitor; var cyl: array [1..cylinderMAX] of condition; var cur; procedure entry request(i:0..cylinderMAX) begin cyl[i].wait; ... service ... cyl[i].signal; end procedure service(i:0..cylinderMAX) begin cyl[i].signal; cyl[i].wait; end begin while(true) cur=(cur+1)%cylinderMAX; service(cur); endwhile end 13.13 ### Because an overload in either the disks or controllers can cause idleness in others, and make the response time longer in the multitasking enviroment. 6.(GRE Sample Question?) In the NoNicks OS, the time required by a single file-read operation has 4 nonverlapping components. Disk Seek time: 25 ms Disk Latency Time: 8 ms Disk Transfer Time: 1 ms per 1000 bytes OS overhead: 1 ms per 1000 bytes + 10 ms (fixed time) In a version 1 of the system, the file read retrieved blocks of 1000 bytes. In version 2, the file read(along with the underlying layout on the disk) was modified to retrieve blocks of 4000 bytes. The ratio of the time required to read a large file under version2 to the time required to read the same large file under version 1 is about: a) 3.5 b) 1.2 c) 3.1 d) 0.35 e) None of the above ### The time under version2= 25+8+4000/1000 + 4000/1000 +10 =51ms The time under version1= 4*(25+8+1000/1000+1000/1000+10)=180ms Thus, the answer is 51/180 = 0.28. The choice is e.