File System Optimization: Parsing Issues Related To Disk Blocks, Index Tables, And File Lengths
“Slimming down” and speeding up mobile phones: Storage and file system logic you must master
When using your mobile phone or computer every day, have you ever been confused about why you have deleted files but there is still not enough space? Or why is there a limit to the size of a single file? Behind this actually lies the core logic of the operating system regarding file management and storage optimization. Today, we are not going to talk about those boring theories. Instead, based on these principles, we will open the hidden functions that can keep your equipment looking like new for a long time, as well as the techniques to improve efficiency.
Get to know your “digital warehouse”: storage blocks and index tables
128
Try to boldly imagine that the storage space of your mobile phone is equivalent to a very huge warehouse. This warehouse has a maximum capacity of 16TB or more. Within this warehouse, there are countless shelves of the same size neatly arranged. These shelves are also called disk blocks, or they can also be called storage blocks. The common size is 4KB. When you save a file (such as a photo or a movie), instead of placing it completely in a single location, the system breaks it into a large number of small pieces and then stores these small pieces on empty shelves.
So, how does the system quickly find these scattered small pieces and then reassemble them into your file? This requires a "treasure map" – that is, the index table that exists in the file control block (FCB) . This table records which shelves (block numbers) your file data are placed on.
<strong>Direct indexing强> : It's like you have a small book with the numbers of all the shelves directly recorded on it. If the notebook is large enough (such as<strong>1024B强> The index table area) can record enough block numbers, then the maximum length of a file is directly determined by the recording capacity of this notebook. If the space occupied by each block number is set to 8B , 128 block numbers can be recorded, and the maximum capacity of a single file is 128 * 4KB = 512KB . This is the reason why the old-fashioned system that simply uses a direct index structure cannot support very large video files.
Systems that support larger files (like Blu-ray original movies) introduce more advanced "treasure map" strategies (such as four-level index structures), which are multi-level indexes. This is like recording the shelf number directly in your notebook, as well as recording clues to another notebook. The primary index points to the block that specifically stores the block number, the secondary index points to the block that stores the block pointing to the block number, and so on. In the case of a four-level index, even if the physical block size is only 1KB and the space occupied by the index item is only 4B, it is possible to manage an astronomical number of file blocks through this layer-by-layer and step-by-step approach, thereby supporting extremely large-scale single files.
Powerful efficiency improvement techniques are presented. After knowing this principle, if you are transferring a large number of small files (such as many photos, etc.), the speed is likely to slow down. This is because the system needs to create and manage a large number of indexes. At this time, you can first package them into a large file (such as a ZIP compressed package), and then continue to use it for transmission or backup, which can significantly improve efficiency.
A revolution in file management: directory entry decomposition
In the "File Manager" on our mobile phones, when opening a folder, why is it sometimes very fast and sometimes taking some time to load? What is related to this is the way the system searches the directory.
4B 256*4*1024B
2的64次方×2的12次方+(1008/8)×2的12次方≈2的76次方
合理的起始块号和块数所占字节数分别为<12,4>(或<0,16>或<9,7>或<10,6>或<11,5>等)。理由:块数占4B或以上,就可表示16TB大小的文件长度,达到文件系统的空间上限
In the traditional method, what is called the "ID card" of each file is the file control block, or FCB for short. It covers all information such as file name, size and location, and these contents are all stored in the directory file. Assume that the size of a disk block is 512 bytes and the size of an FCB is 64 bytes. In this case, a disk block can only store 8 FCBs. In a directory, if there are 254 files, then the directory files will occupy 32 disk blocks. When you search for one of these files, it requires, on average, sixteen accesses to the disk or flash memory, because having to traverse half of the disk blocks is definitely going to slow things down, that's for sure.
This is where the "catalog item decomposition method" comes into play, also known as the "FCB decomposition method", which splits the FCB into two parts.
1. Symbol part : It only covers the file name and a "pointer" pointing to the main part ( the internal number of the file ). This part occupies 10 bytes .
16.5

2. This part of the basic information: covers the file internal number and all other detailed information, such as size, permissions, modification date, etc. It occupies the remaining 54 bytes.
In this way, a disk block with a size of 512 bytes can store approximately 51 "symbol parts" that only contain file names. Similarly, when searching for 254 files, you now only need to access about 5 disk blocks (254 divided by 51) to find the "pointer" of the target file, and then use the pointer to read the disk block storing the detailed information. The average number of market visits has dropped sharply from the original 16 times to about 3 times!
System setup tips are as follows, which is why modern operating systems recommend periodically doing a "rebuild Spotlight index" or something similar. When your file search becomes extremely slow, it is very likely that the index structure of the file system is disordered. Rebuilding the index is equivalent to organizing the "directory book" again, so that the system can quickly locate files.
Battery Care and Storage Optimization: The Hidden Connection
6+256+256的2次方+256的3次方+256的4次方
You may not think that the degree of file system fragmentation is also related to battery life .
When files are frequently created and deleted, the storage space becomes fragmented, which means that the data blocks of a file may be scattered in different corners of the memory chip. When you read this file, the head (for mechanical hard disks) or the controller (for flash memory) need to constantly perform jump addressing, which will generate additional read and write operations and power consumption.
In terms of computers, regular "disk defragmentation" (this operation is effective for mechanical hard drives) and executing the "TRIM" command on mobile phones and solid-state drives (generally maintained by the operating system itself) can promote file data to be stored as continuously as possible. This not only reduces the time required for addressing, improves file reading and writing speeds, but also avoids unnecessary power consumption, thereby indirectly optimizing battery life. On your phone, find the "Storage" option in "Settings" and occasionally perform a "Cleaning Acceleration" or "Deep Cleaning", which can often trigger the system's background optimization mechanism.
Troubleshooting: When a file system gets angry
8.5
Sometimes, your USB flash drive or mobile phone memory card suddenly cannot be read, or it prompts you to format it. This is most likely because the metadata of the file system, that is, the "treasure map" is broken.
Troubleshooting tips : On Windows systems, you can use the chkdsk command to enter chkdsk X: /f , where These tools will attempt to scan and fix inconsistencies in the index table, and they will also fix inconsistencies in the directory entries. This is like repairing a torn treasure map to make it usable again. Never format as soon as you encounter a problem. You should first try the repair tools that come with the system. It is very possible to recover important data.
When we understand the underlying file system logic, we first start with direct indexing, then evolve to four-level indexing, and then the retrieval optimization of directory item decomposition. Through this understanding, we can not only better understand the limits of device capacity, but also master a series of practical efficiency improvement methods and troubleshooting methods, so that the digital devices in our hands can always be maintained in the best condition.