2019329621196麻宣政homework13 Version 0 |
|
👤 Author: by 1436830195qqcom 2021-12-29 11:06:08 |
1. Continuous distribution:
Continuous allocation is to allocate a set of continuous blocks on the disk to store a file. Each block on the disk has an address and is arranged linearly. Then the computer only needs to store the file name, the first address of the file, and the length of the file.
The advantages of this allocation method are: 1. Easy to access; 2. Since the file system remembers the address of the last visit, this method supports direct access and sequential access.
The disadvantages are:
1) New file allocation and expansion issues: When a file is created, we need to allocate space according to the size of the file, but during the use of the file, the file may become larger or may be deleted.
If the files are close to each other, it is difficult to expand; one solution is: when the space is not enough, add an expansion pointer to the last block to point to another empty block for expansion, and so on.
If we allocate a certain amount of expandable space to each file, but when the user no longer expands some files, it will cause a waste of space.
2). External fragmentation (the entire block cannot be used): In the process of continuously adding and deleting files, some concentrated small blocks (such as blocks 18 and 19 in the figure) will be unusable, and the files around them will not be used. Expansion, there is no such small file can be stored in it, it will cause waste. One solution is to periodically merge these small fragments and move the positions of other file blocks to make these small fragments aggregate into one large block for later use. However, this method has a serious time cost and will make the computer unable to work during this period.
2. Link distribution:
The idea of this allocation method is similar to a linked list, each block is a node, and the end of each block stores the address of the next block. When accessing a file, when the end of a block is accessed, the address of the next block is obtained to access the next block. When the access to the file ends, the address of that block is a specific terminator (the terminator in the legend is -1). Then the file directory structure only needs the file name, start address, and end address.
The advantages of link assignment are:
1). There will be no external fragmentation problem, because this allocation method has no position restriction, any block can point to any block, and it can also be pointed to by any block.
2) Easy to expand: If the file needs to be expanded, you only need to add a node at the end of the file chain, and modify the original end node and the end address of the file directory.
But link allocation also has its own shortcomings:
1). Only sequential access: Due to the linked list used by this disk allocation method, it can only be accessed sequentially. To access the i-th block of the file, you must start from the beginning and follow the pointer to find the i-th block.
2) Pointer waste of memory: Because each block needs to store additional pointers, this causes a waste of space. An optimization method is: multiple blocks share the same address, which is regarded as one block, which is called a cluster. This can effectively reduce the number of pointers, but if the last cluster cannot be used up, for example, a cluster contains 4 blocks, but the file + pointer requires a total of 13 blocks, then 4 clusters are needed, but the last cluster is only One block is used, and one cluster shares one address, so the other three blocks cannot be allocated and can only be wasted.
3. Index allocation:
In order to solve the problems of the above two methods, index allocation can be used. Index allocation simply means that the pointers allocated by the link are stored in a block in a concentrated order, then the file directory only needs to store the file name and the address of the index block, and then access in this block according to the address, of course, you can also pass the offset Visit directly after you find the address you want to visit.
There is a problem with this access method: the number of index addresses stored in a block is limited, so how to control the allocation? The mechanisms for this purpose include the following:
1) Link scheme: Simply put, it is to use link allocation to expand the index block. When one index block is used up, it is linked to the next block through the pointer.
2) Multi-level index: Just like a tree, the index block of the directory points to the root node, and then the address in the block points to another block, which is the second-level index, and so on.
3) Combination scheme: For example, in the following figure, an index block contains 15 pointers (direct block + indirect block), and the first 12 pointers are direct blocks; that is, they include the address of the block that can store file data . Therefore, small files do not need to be index blocks. The first-level indirect block is the second-level index structure, the second-level indirect block is the three-level index structure, and the third-level indirect block is the four-level index structure. Through this layered method, files of different sizes can be allocated to the appropriate index structure.