Why Is the Space Not Released After I Delete a Large File on a Linux ECS?
Symptom
The space usage of the root directory on a Linux ECS is too high, for example, 96%, as shown in Figure 1.
You find that the access_log file generated by Apache occupies about 42 GB in the root directory. Then you perform the following operations attempting to release space:
However, the output tells you that the usage is still 96%.
Possible Cause
The file you deleted is locked by another running process that keeps writing data to the file.
The following are basics about file storage in Linux, which can help you better understand the possible cause.
In Linux file systems, a file is organized into two parts:
- File pointer: The pointer is stored in the file system metadata. When the file is deleted, the file pointer will be deleted from the metadata.
- File data: The file data is stored on the disk.
Generally, after the file pointer is deleted from the metadata, the disk space occupied by the file data will be marked as available. However, if the file is still being used by another running process when it is deleted, the file pointer will fail to be deleted from the metadata, and the system will determine that the file has not been deleted and does not reclaim the space occupied by the file data.
Solution
- Run the lsof command to check whether any process keeps writing data to the access_log file.
lsof -n |grep delete
Figure 2 Checking the process that locks the file
As shown in the command output, the access_log file is still being used by the httpd process which keeps writing log data into the file. Value deleted in the brackets indicates that the log file has been deleted. But the space is not released because httpd keeps writing data to the file.
- Stop or restart the httpd process, or restart the system. You are advised to clear the content of access_log, rather than deleting it.
Run the following command to clear access_log:
echo "">/access_log
In this way, the disk space will be released immediately and the process can continue writing logs to the file. Then, run the df -h command to check the space usage again.
Figure 3 Checking the space usage of the root directory
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot