OS file storage method

File storage method:

  • continuous space storage
  • Non-contiguous space storage method

Non-continuous space storage methods: linked list method, index method

Way disk access times advantage shortcoming
sequential allocation Access disk 1 time Sequential access speed is fast, when the file length is fixed, random access can be performed according to the file start address and record length Continuous storage space is required, which will generate external fragments, which is not conducive to the dynamic expansion of files
linked list allocation Access disk n times There is no external fragmentation, which improves the utilization rate of external storage space and facilitates dynamic growth It can only be accessed according to the order of the file pointer chain, the search efficiency is low, and the storage of pointer information consumes memory or disk space
index allocation Level m needs to access the disk m + 1 times Random access, easy file addition and deletion The index table increases the overhead of storage space, and the search strategy of the index table has a great impact on the efficiency of the file system

continuous space

Continuous space storage method: continuously placed on the disk, high read and write efficiency

image.png

shortcoming :

  • Disk space fragmentation: vacancy data does not match application data
  • The length of the file is not easy to expand: to expand the file, to move the data, the efficiency is low

image.png

discontinuous space

linked list

Linked list method: discrete, discontinuous

  • Benefits: Improve the utilization of disk space, and the file length can be dynamically expanded

Linked list implementation: implicit linked list, explicit link

The implementation of the implicit linked list: there is the first block in the file header, and the last block position

  • Each data block vacates a pointer space to store the location of the next data block

image.png

shortcoming :

  • Data blocks cannot be accessed directly, only files can be accessed sequentially through pointers
  • The data block pointer consumes a certain amount of storage space
  • Poor stability, when the pointer of the linked list is lost, it will lead to data loss

Explicit link: The pointer of each data block of the linked file is placed in the linked list of the memory (File Allocation Table (File Allocation Table, FAT))

image.png

Find records in memory:

  • Pros: Increased retrieval speed, reduced number of disk accesses
  • Cons: Not suitable for large disks

index

Index implementation: Create an index data block for each file and store a list of pointers to file data blocks

  • Find the location of the index data block through the index data block pointer of the file header, and then find the corresponding data block through the index information of the index data block

image.png

Index advantages:

  • Easy to create, enlarge, and shrink files
  • No Fragmentation Issues
  • Support sequential read and write, random read and write
  • Cons: storage index overhead

For large files, the index data block cannot fit, use combination processing

Chained index block: linked list + index

  • Implementation method: Reserve a pointer to store the next index data block in the index data block, use it up, find the next storage

image.png

Multi-level index block: index + index mode

  • Implementation method: index block puts multiple index data blocks

image.png

Guess you like

Origin blog.csdn.net/qq_44226094/article/details/131750248