アイテムを削除してもアイテム数が多いディレクトリのサイズが小さくならないのはなぜですか?

アイテムを削除してもアイテム数が多いディレクトリのサイズが小さくならないのはなぜですか?

問題はなぜディレクトリエントリを削除した後、ディレクトリは縮小されますか?ext4ディレクトリメタデータを保存するようにファイルシステムを設定する方法ですか?明らかに、ディレクトリを削除して再作成するのは、元のinodeを削除して新しいinodeを作成することなので、解決策ではありません。数量を手動で減らすにはどうすればよいですか?

ベストアンサー1

開発者の言葉を引用すると(Linuxカーネルスレッドで大量のファイルを削除しても、ext3 / ext4ディレクトリは減りません。):

On Thu, May 14, 2009 at 08:45:38PM -0400, Timo Sirainen wrote:
>
> I was rather thinking something that I could run while the system was  
> fully operational. Otherwise just moving the files to a temp directory +
> rmdir() + rename() would have been fine too.
>
> I just tested that xfs, jfs and reiserfs all shrink the directories  
> immediately. Is it more difficult to implement for ext* or has no one  
> else found this to be a problem?

It's probably fairest to say no one has thought it worth the effort.
It would require some fancy games to swap out block locations in the
extent trees (life would be easier with non-extent-using inodes), and
in the case of htree, we would have to keep track of the index block
so we could remove it from the htree index.  So it's all doable, if a
bit tricky in terms of the technical details; it's just that the
people who could do it have been busy enough with other things.

It's hasn't been considered high priority because most of the time
directories don't go from holding thousands of files down to a small
handful.  

                                                - Ted

おすすめ記事