Why does the space occupied by a file exceed the actual file size?
Published: 2024-06-04
Take the Windows system as an example, first look at a few images:
Figure 1: The file size is smaller than the size on disk.

Figure 2: The file size is the same as the size on disk.

Figure 3: The file size is larger than the size on disk.

The above 3 figures show several cases of file size and size on disk. The first two scenarios are relatively common. The reason why the file size is sometimes smaller than the size on disk is the cluster size limit. A cluster represents the minimum amount of disk space that can be allocated to save a file. The cluster size of the area where the sparse.txt file is stored is 4096 bytes. In Figure 1, the file size is 4096 bytes (you can use the chkdsk command to check), so a 5K file needs 2 clusters to store, as shown in the following figure:

Figure 2 shows that the file size is 5M. 5M is exactly an integer multiple of 4096, so the file size is the same as the size on disk.
Next, focus on the third case. This involves the sparse file issue. For systems that do not support sparse files, this situation will not occur. See an example:
/**
* Regular files may have a lot of unnecessary space waste
* @throws IOException
*/
@Test
public void normalFile() throws IOException {
File file = new File("d:/tmp/sparse.txt");
Path path = file.toPath();
FileChannel ch = FileChannel.open(path, StandardOpenOption.CREATE,StandardOpenOption.WRITE);
ch.position(5*1024*1024L);
ch.write(ByteBuffer.wrap("hello world".getBytes("utf-8")));
ch.close();
}
/**
* Sparse file mode
* @throws IOException
*/
@Test
public void sparseFile() throws IOException {
File file = new File("d:/tmp/sparse.txt");
Path path = file.toPath();
FileChannel ch = FileChannel.open(path, StandardOpenOption.SPARSE,StandardOpenOption.CREATE_NEW,StandardOpenOption.WRITE);
ch.position(5*1024*1024L);
ch.write(ByteBuffer.wrap("hello world".getBytes("utf-8")));
ch.close();
}Some users will find that the file size counted in File Manager is inconsistent with the actual space occupied.For example, the space size prompt indicates that it exceeds the limit while the file size does not exceed the limit.This is also caused by these reasons. In summary, the space occupation detected by our system is the actual space occupied by the files, not the size of the files themselves. If the space limit is prompted to be exceeded, please upgrade the space capacity to avoid affecting your normal use.
If your host quota exceeds the limit by a lot, but the actual occupied space is not large, it is because there are many small cache files, such as files under the \runtime\session path, as shown in the following figure:

If deleting such files through FTP or File Manager is too slow, please[Submit a Ticket], you can authorize a technical engineer to handle batch deletion for you.
