Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Lsof handles the problem of inconsistent size of df and du

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The APP server root is full. Keep calling the police.

Df shows that the root partition has used 90% of the space, but the total amount of du root partition is only about 40G. The partition should not have a large number of small files, so it should not cause the block full problem caused by a large number of small files.

After searching the Internet, it is found that there may be a program operating large files so that the file handle is not released, and these file handles occupied by the program will be considered by df to be stored on the hard disk.

The online explanation goes like this:

Du is to count all the files in the directory separately, while df counts the space allocated from the file system, and includes the space applied for by the program.

If it seems, there should be a lot of space under the / directory occupied by a program.

Processing method lsof / | grep delete

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

Mongod 2842 root 15u REG 251J 0 536870912 6296116 / var/lib/mongodb/vida_log.3 (deleted)

Mongod 2842 root 16u REG 251J 0 536870912 6306826 / var/lib/mongodb/vida_log.4 (deleted)

Mongod 2842 root 10u REG 251 REG 0 536870912 6345649 / var/lib/mongodb/vida_log.0 (deleted)

Mongod 2842 root 11u REG 251 REG 0 536870912 6345658 / var/lib/mongodb/vida_log.1 (deleted)

Mongod 2842 root 12u REG 251 REG 0 536870912 6345659 / var/lib/mongodb/vida_log.2 (deleted)

Ruby 25149 vidafm 3w REG 251 REG 0 5594054 7351133 / var/www/vida_api_120614/log/development.log.4 (deleted)

Ruby 26599 vidafm 3w REG 251 REG 0 5594054 7351133 / var/www/vida_api_120614/log/development.log.4 (deleted)

Nginx 9388 nobody 82u REG 251 Magi 0 90112 6162236 / opt/nginx/client_body_temp/0004778814 (deleted)

You can see that the files on the SIZE line are very large and are already in delete status, indicating that the file has been deleted but the file handle has not been released by the program.

Kill can free up space by dropping these processes.

After re-df-h, I found that the available space has become 90G +, which is very comfortable.

Another interpretation of df and du on the Internet

The du-sh command accumulates the total number of blocks used by a specified file system by adding all directories, symbolic links, and the number of blocks used by files in that file system

The df command obtains the total number of blocks and the number of remaining blocks by looking at the disk block allocation diagram of the file system.

The file system allocates some of these blocks to record some of its own data, such as I nodes, disk distribution maps, indirect blocks, super blocks, etc. This data is invisible to most user-level programs, often referred to as Meta Data.

The du command is a user-level program that does not consider Meta Data, while the df command looks at the disk allocation diagram of the file system and considers Meta Data.

Therefore, under normal circumstances, the USED space calculated by df is slightly larger than that calculated by du.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report