Skip to contentSkip to conversation

Directories > 2GB

DISCUSSION Andreas Dilger 8 participants 12 messages Oct 4, 2006 – Oct 16, 2006 1 message not in the archive VFS

lore
Share & tools
lore
#0 lore raw

For ext4 we are exploring the possibility of directories being larger than 2GB in size. For ext3/ext4 the 2GB limit is about 50M files, and the 2-level htree limit is about 25M files (this is a kernel code and not disk format limit).

Amusingly (or not) some users of very large filesystems hit this limit with their HPC batch jobs because they have 10,000 or 128,000 processes creating files in a directory on an hourly basis (job restart files, data dumps for visualization, etc) and it is not always easy to change the apps.

My question (esp. for XFS folks) is if anyone has looked at this problem before, and what kind of problems they might have hit in userspace and in the kernel due to "large" directory sizes (i.e. > 2GB). It appears at first glance that 64-bit systems will do OK because off_t is a long (for telldir output), but that 32-bit systems would need to use O_LARGEFILE when opening the file in order to be able to read the full directory contents. It might also be possible to return -EFBIG only in the case that telldir is used beyond 2GB (the LFS spec doesn't really talk about large directories at all).

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.

#1 lore raw
Quoted 11 lines · Andreas Dilger

For ext4 we are exploring the possibility of directories being larger than 2GB in size. For ext3/ext4 the 2GB limit is about 50M files, and the 2-level htree limit is about 25M files (this is a kernel code and not disk format limit).

Amusingly (or not) some users of very large filesystems hit this limit with their HPC batch jobs because they have 10,000 or 128,000 processes creating files in a directory on an hourly basis (job restart files, data dumps for visualization, etc) and it is not always easy to change the apps.

Quoted 9 lines

My question (esp. for XFS folks) is if anyone has looked at this problem before, and what kind of problems they might have hit in userspace and in the kernel due to "large" directory sizes (i.e. > 2GB). It appears at first glance that 64-bit systems will do OK because off_t is a long (for telldir output), but that 32-bit systems would need to use O_LARGEFILE when opening the file in order to be able to read the full directory contents. It might also be possible to return -EFBIG only in the case that telldir is used beyond 2GB (the LFS spec doesn't really talk about large directories at all).

ext3 directory entries are always multiples of 4 bytes in length. So the lowest 2 bits of the offset are always zero. Right? Why not shift the returned offset and f_pos 2 bits right?

JFS uses an index into an array for the position (which isn't even in the directory traversal order) so it can handle about 2G files in a directory (although deleted entries aren't reused).

Signature · 2 lines
David Kleikamp
IBM Linux Technology Center
#2 lore raw
In reply to Andreas Dilger
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On Wed, 4 Oct 2006 10:56:56 -0600, Andreas Dilger
<[email protected]> said:

adilger> For ext4 we are exploring the possibility of adilger> directories being larger than 2GB in size. For adilger> ext3/ext4 the 2GB limit is about 50M files, and the adilger> 2-level htree limit is about 25M files (this is a adilger> kernel code and not disk format limit).

H-trees here have some serious performance problems:

http://WWW.sabi.co.UK/Notes/anno05-4th.html#051204

which is perhaps because of poor locality, and I suspect that large hash trees would suffer from it even more.

adilger> Amusingly (or not) some users of very large filesystems adilger> hit this limit with their HPC batch jobs because they adilger> have 10,000 or 128,000 processes creating files in a adilger> directory on an hourly basis (job restart files, data adilger> dumps for visualization, etc) and it is not always easy adilger> to change the apps.

Perhaps the users should be gently introduced to the recent idea of subdirectories or, if the apps can be changed, the even more novel and experimental notion of DBMSes... :-). And even if apps cannot be changed one can always use 'LD_PRELOAD' and ''advise'' the 'open' call suitably...

adilger> [ ... ] but that 32-bit systems would need to use adilger> O_LARGEFILE when opening the file in order to be able adilger> to read the full directory contents. It might also be adilger> possible to return -EFBIG only in the case that telldir adilger> is used beyond 2GB [ ... ]

Well, in theory apps use 'readdir' and 'getdents' so they should be immunized from exactly how directories are represented. On my 32 bit system with Fedora with GNU LIBC 2.4 I see:

  $ strace ls /
  [ ... ]
  open("/", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
  fstat64(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
  fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
  getdents64(3, /* 38 entries */, 4096)   = 1024
  getdents64(3, /* 0 entries */, 4096)    = 0
  close(3)                                = 0
  [ ... ]

and this should give some hope.

#3 lore raw
In reply to Andreas Dilger
Quoted 11 lines · Andreas Dilger

For ext4 we are exploring the possibility of directories being larger than 2GB in size. For ext3/ext4 the 2GB limit is about 50M files, and the 2-level htree limit is about 25M files (this is a kernel code and not disk format limit).

Amusingly (or not) some users of very large filesystems hit this limit with their HPC batch jobs because they have 10,000 or 128,000 processes creating files in a directory on an hourly basis (job restart files, data dumps for visualization, etc) and it is not always easy to change the apps.

Quoted 10 lines

My question (esp. for XFS folks) is if anyone has looked at this problem before, and what kind of problems they might have hit in userspace and in the kernel due to "large" directory sizes (i.e. > 2GB). It appears at first glance that 64-bit systems will do OK because off_t is a long (for telldir output), but that 32-bit systems would need to use O_LARGEFILE when opening the file in order to be able to read the full directory contents. It might also be possible to return -EFBIG only in the case that telldir is used beyond 2GB (the LFS spec doesn't really talk about large directories at all).

My first thought is to run screaming for the hills when user's want this. In a previous life we had a customer in the US Gov who decided to put all their 700 million files in one directory. Then they had a double disk unreported raid failure (raid vendors fault). The filesystem repair ran for 7 days and a heck of a lot of files ended up in lost+found. Fortunately they had the huge amount of memory and process address space available to run repair.

Anyone who does this and has any sense does not allow any sort of scanning of the namespace (i.e. anything using readdir). You tend to run out of process address space before you have read the directory.

You might want to think about keeping the directory a little more contiguous than individual disk blocks. XFS does have code in it to allocate the directory in chunks larger than a single file system block. It does not get used on linux because the code was written under the assumption you can see the whole chunk as a single piece of memory which does not work to well in the linux kernel.

Steve

#4 lore raw
Quoted 7 lines · Steve Lord

You might want to think about keeping the directory a little more contiguous than individual disk blocks. XFS does have code in it to allocate the directory in chunks larger than a single file system block. It does not get used on linux because the code was written under the assumption you can see the whole chunk as a single piece of memory which does not work to well in the linux kernel.

This code is enabled and seems to work in Linux. I don't know if it passes xfsqa so I don't know how reliable this feature is. TO check it all I did was run a quick test on a x86_64 kernel (4k page size) using 16k directory blocks (4 pages):

# mkfs.xfs -f -n size=16384 /dev/ubd/1
.....
# xfs_db -r -c "sb 0" -c "p dirblklog" /dev/ubd/1
dirblklog = 2
# mount /dev/ubd/1 /mnt/xfs
# for i in `seq 0 1 100000`; do touch fred.$i; done
# umount /mnt/xfs
# mount /mnt/xfs
# ls /mnt/xfs |wc -l
100000
# rm -rf /mnt/xfs/*
# ls /mnt/xfs |wc -l
0
# umount /mnt/xfs
#

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#5 lore raw
Quoted 11 lines · David Chinner
Quoted 7 lines · Steve Lord

You might want to think about keeping the directory a little more contiguous than individual disk blocks. XFS does have code in it to allocate the directory in chunks larger than a single file system block. It does not get used on linux because the code was written under the assumption you can see the whole chunk as a single piece of memory which does not work to well in the linux kernel.

This code is enabled and seems to work in Linux. I don't know if it passes xfsqa so I don't know how reliable this feature is.

It did at one point - though I've not tested that combination for awhile, I expect it will still work fine. It should - the artist-formerly-known-as-pagebuf does handle multiple discontiguous pages, and the dir2 code is using that memory in a way thats going to work correctly, IIRC.

cheer

Signature · 1 line
Nathan
#6 lore raw
In reply to David Chinner

Hi Dave,

My recollection is that it used to default to on, it was disabled because it needs to map the buffer into a single contiguous chunk of kernel memory. This was placing a lot of pressure on the memory remapping code, so we made it not default to on as reworking the code to deal with non contig memory was looking like a major effort.

Steve

Quoted 36 lines · David Chinner
Quoted 7 lines · Steve Lord

You might want to think about keeping the directory a little more contiguous than individual disk blocks. XFS does have code in it to allocate the directory in chunks larger than a single file system block. It does not get used on linux because the code was written under the assumption you can see the whole chunk as a single piece of memory which does not work to well in the linux kernel.

This code is enabled and seems to work in Linux. I don't know if it passes xfsqa so I don't know how reliable this feature is. TO check it all I did was run a quick test on a x86_64 kernel (4k page size) using 16k directory blocks (4 pages):

# mkfs.xfs -f -n size=16384 /dev/ubd/1
.....
# xfs_db -r -c "sb 0" -c "p dirblklog" /dev/ubd/1
dirblklog = 2
# mount /dev/ubd/1 /mnt/xfs
# for i in `seq 0 1 100000`; do touch fred.$i; done
# umount /mnt/xfs
# mount /mnt/xfs
# ls /mnt/xfs |wc -l
100000
# rm -rf /mnt/xfs/*
# ls /mnt/xfs |wc -l
0
# umount /mnt/xfs
#

Cheers,

Dave.

#7 lore raw
Quoted 8 lines · Steve Lord

Hi Dave,

My recollection is that it used to default to on, it was disabled because it needs to map the buffer into a single contiguous chunk of kernel memory. This was placing a lot of pressure on the memory remapping code, so we made it not default to on as reworking the code to deal with non contig memory was looking like a major effort.

Exactly. The code works but tends to go OOM pretty fast at least when the dir blocksize code is bigger than the page size. I should give the code a spin on my ppc box with 64k pages if it works better there.

#8 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Steve Lord

Hi Dave,

My recollection is that it used to default to on, it was disabled because it needs to map the buffer into a single contiguous chunk of kernel memory. This was placing a lot of pressure on the memory remapping code, so we made it not default to on as reworking the code to deal with non contig memory was looking like a major effort.

Quoted 4 lines

Exactly. The code works but tends to go OOM pretty fast at least when the dir blocksize code is bigger than the page size. I should give the code a spin on my ppc box with 64k pages if it works better there.

The pagebuf code doesn't use high-order allocations anymore; it uses scatter lists and remapping to allow physically discontiguous pages in a multi-page buffer. That is, the pages are sourced via find_or_create_page() from the address space of the backing device, and then mapped via vmap() to provide a virtually contigous mapping of the multi-page buffer.

So I don't think this problem exists anymore...

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#9 lore raw
Quoted 15 lines · David Chinner
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Steve Lord

Hi Dave,

My recollection is that it used to default to on, it was disabled because it needs to map the buffer into a single contiguous chunk of kernel memory. This was placing a lot of pressure on the memory remapping code, so we made it not default to on as reworking the code to deal with non contig memory was looking like a major effort.

Quoted 4 lines

Exactly. The code works but tends to go OOM pretty fast at least when the dir blocksize code is bigger than the page size. I should give the code a spin on my ppc box with 64k pages if it works better there.

Quoted 8 lines

The pagebuf code doesn't use high-order allocations anymore; it uses scatter lists and remapping to allow physically discontiguous pages in a multi-page buffer. That is, the pages are sourced via find_or_create_page() from the address space of the backing device, and then mapped via vmap() to provide a virtually contigous mapping of the multi-page buffer.

So I don't think this problem exists anymore...

I was not referring to high order allocations here, but the overhead of doing address space remapping every time a directory is accessed.

Steve

#10 lore raw
Quoted 23 lines · Steve Lord
Quoted 22 lines · David Chinner
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Steve Lord

Hi Dave,

My recollection is that it used to default to on, it was disabled because it needs to map the buffer into a single contiguous chunk of kernel memory. This was placing a lot of pressure on the memory remapping code, so we made it not default to on as reworking the code to deal with non contig memory was looking like a major effort.

Quoted 4 lines

Exactly. The code works but tends to go OOM pretty fast at least when the dir blocksize code is bigger than the page size. I should give the code a spin on my ppc box with 64k pages if it works better there.

The pagebuf code doesn't use high-order allocations anymore; it uses scatter lists and remapping to allow physically discontiguous pages in a multi-page buffer. That is, the pages are sourced via find_or_create_page() from the address space of the backing device, and then mapped via vmap() to provide a virtually contigous mapping of the multi-page buffer.

Quoted 4 lines
Quoted 1 line

So I don't think this problem exists anymore...

I was not referring to high order allocations here, but the overhead of doing address space remapping every time a directory is accessed.

Ah - ok. contig -> non-contig and OOM is usually discussed in the context of higher order allocations failing. FWIW, I've not noticed any extra overhead - the CPU usage seems to grow roughly linearly with the increase in directory operations done as a result of higher throughput for the same number of I/Os. I'll have a look at the Vm stats, though, next time I run a comparison to see how bad this is.

Thanks for the clarification, Steve.

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#12 lore raw
In reply to a message not in the archive
Quoted 23 lines · Steve Lord
Quoted 14 lines · David Chinner
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Steve Lord

Hi Dave,

My recollection is that it used to default to on, it was disabled because it needs to map the buffer into a single contiguous chunk of kernel memory. This was placing a lot of pressure on the memory remapping code, so we made it not default to on as reworking the code to deal with non contig memory was looking like a major effort.

Quoted 4 lines

Exactly. The code works but tends to go OOM pretty fast at least when the dir blocksize code is bigger than the page size. I should give the code a spin on my ppc box with 64k pages if it works better there.

Quoted 7 lines

The pagebuf code doesn't use high-order allocations anymore; it uses scatter lists and remapping to allow physically discontiguous pages in a multi-page buffer. That is, the pages are sourced via find_or_create_page() from the address space of the backing device, and then mapped via vmap() to provide a virtually contigous mapping of the multi-page buffer.
So I don't think this problem exists anymore...

Quoted 2 lines

I was not referring to high order allocations here, but the overhead of doing address space remapping every time a directory is accessed.

# grep -i vmalloc /proc/meminfo 
VmallocTotal: 34359738367 kB

At least on 64bit systems it would be reasonable to keep a large number of directories mapped this way over a longer time. vmap() space is cheap there.

-Andi