diff options
author | Jim Meyering <meyering@redhat.com> | 2008-12-09 08:49:41 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2010-07-04 08:40:40 +0200 |
commit | 4cb826802413516852a89739454a73c7a6ad0bd8 (patch) | |
tree | 37f170e325309d5fc6d6fde1efda7ff0944f9412 /src/install.c | |
parent | f42496b72b4f829744c279d9e51fe698a52fbbfc (diff) | |
download | coreutils-4cb826802413516852a89739454a73c7a6ad0bd8.tar.xz |
du: use less than half as much memory when tracking hard links
When processing a hard-linked file, du must keep track of the file's
device and inode numbers in order to avoid counting its storage
more than once. When du would process many hard linked files --
as are created by some backup tools -- the amount of memory required
for the supporting data structure could become prohibitively large.
This patch takes advantage of the fact that the amount of information
in the numbers of the typical dev,inode pair is far less than even
32 bits, and hence usually fits in the space of a pointer, be it
32 or 64 bits wide. A typical du traversal examines files on no
more than a handful of distinct devices, so the device number can
be encoded in just a few bits. Similarly, few inode numbers use
all of the high bits in an ino_t. Before, we would represent the
dev,inode pair using a naive struct, and allocate space for each.
Thus, an entry in the hash table consisted of a pointer (to that
struct) and a "next" pointer. With this change, we encode the
dev,inode information and put those bits in place of the pointer,
and thus do away with the need to allocate additional space for
each dev,inode pair.
* src/du.c: Include "di-set.h".
Don't include "hash.h"; it's no longer used.
(INITIAL_DI_SET_SIZE): Define.
(di_set): New global, to replace "htab".
(entry_hash, entry_compare, hash_init): Remove functions.
(hash_ins): Use di-set functions, rather than ones from the hash module.
(main): Likewise.
* bootstrap.conf (gnulib_modules): Add the new di-set module.
* NEWS (New features): Mention it.
Diffstat (limited to 'src/install.c')
0 files changed, 0 insertions, 0 deletions