Analysis of real questions for system architects (1)-physical structure of file system

1 Real question analysis

Suppose the file system adopts index node management, and the index node has 8 address items iaddr[0] ~ iaddr[7], and the size of each address item is 4B. iaddr[0] ~ iaddr[4] use direct address indexing, iaddr[5] and iaddr[6] use first-level indirect address indexing, and iaddr[7] use second-level indirect address indexing. Assuming that the size of the disk index block and the disk data block are both 1KB, the index node of file File1 is shown in the figure below. If the user accesses the information with the logical block numbers of 5 and 261 in the file File1, the corresponding physical block numbers are respectively (3), and the physical block number 101 stores (4).

(3) A. 89 and 90 B. 89 and 136 C. 58 and 187 D. 90 and 136

(4) A. File1 information B. Direct address index table C. Primary address index table D. Secondary address index table

The key to solving problems is to look at pictures. The address in the cell in the figure is the physical block address, while the logical block is a blank cell, and the logical block number is not marked.

First, according to the content of the subject, the following logical block numbers can be derived. Note: The logic block number starts from 0. There are 5 logical block numbers from 0 to 4, and the direct address index is used.

Because the size of each address item of the physical block is 4B, the size of the disk index block is 1KB, which is 1024B. 1024/4 = 256, so a disk index block can store 256 physical block addresses. Therefore, the logical block number range corresponding to the first-level indirect address index can be inferred.
Because each index block can store 256 physical block addresses, the logical block number range corresponding to the first level 1 indirect address index is 5 ~ 260; the logical block number range corresponding to the second level 1 indirect address index is 261 ~ 516. The specific calculation steps are:
[1] 260 = 5 + 256 -1.
[2] 516 = 261 + 256 -1.

Therefore, the first empty choice C.

The block number is 101. The physical address adopts the secondary index method, and its line is connected to the primary address index table, which itself stores the secondary address index. So the second empty pick D.


This question involves the following knowledge points.

2 The physical structure of the file system

The physical structure of a file refers to how the file is stored on the storage device. The physical structure of the file focuses on improving memory utilization efficiency and reducing access time. File storage devices are usually divided into physical blocks of the same size, and physical blocks are the basic unit for allocating and transmitting information. The physical structure of the file involves the block strategy and file allocation strategy of the file storage device, and determines the storage location of the file information on the storage device. Commonly used file allocation strategies are:

(1) Sequential distribution (continuous distribution)

This is the simplest distribution method. A group of consecutive physical blocks are allocated in advance when the file is created, and then the information (or records) is sequentially stored in the physical blocks according to the order of the information (or records) in the logical file. In this way, only need to know the starting position of the file on the file storage device and the length of the file can be accessed. This distribution method is suitable for sequential access. When accessing adjacent information continuously, the access speed is fast. The disadvantage is that the information length of the file must be specified when the file is created, and it cannot be dynamically increased in the future, and it is generally not suitable for files that need to be modified frequently.

(2) Link distribution (series distribution)

This is done one by one in a single physical block. Each physical block (usually the last unit) has a pointer that points to the address of the next physical block that is subsequently connected. In this way, all physical blocks are linked to form a link queue. When establishing a link file, there is no need to specify the length of the file. In the description information of the file, only the first physical block number of the file needs to be pointed out, and the file length of the link file can be dynamically increased. Only by adjusting the pointers between physical blocks, an information block can be inserted or deleted. The advantage of link allocation is that it can solve the problem of memory fragmentation and improve storage space utilization. Because the linked files can only be searched in the order of the link pointers in the queue, the search efficiency is low, and generally only suitable for sequential access, not for random access.

(3) Index allocation

This is another method of discontinuous allocation of file storage. The system using the index allocation method creates an index table for each file, and each entry in the index table indicates the logical block number where the file information is located and the corresponding physical block number. Index allocation can not only meet the requirements of file dynamic growth, but also realize random access conveniently and quickly. For some large files, when the size of the index table exceeds one physical block, the allocation problem of the index table will occur. Generally, multi-level (indirect index) technology is used. At this time, the physical block indicated by the index table is not the file but the physical block address of the file information. If a physical block can store n addresses, in the first-level indirect index mode, the addressable file length will be [n's quadratic] block. For larger files, secondary or even tertiary indirect indexing can be used (for example, the UNIX operating system uses a tertiary index structure).

The advantage of the index file is that it is suitable for both sequential access and random access. The disadvantage is that the index table increases the overhead of storage space.

In addition, the disk needs to be accessed twice when accessing the file, one is to access the index table, and the other is to access the file information according to the physical block number provided by the index table. In order to improve efficiency, an improved method is to load the index table into memory in advance before operating on a file. In this way, file access can directly determine the corresponding physical block number from the memory index table, so that only one access to the disk is required.

Guess you like

Origin blog.csdn.net/deniro_li/article/details/108892955