Linux directory number and number of files limit __linux

Source: Internet
Author: User
Tags create directory parent directory

Today, a problem was encountered on the server, the subdirectory could not be created in the directory, exception:

mkdir: Unable to create directory "...": Too many connections

Before the original understanding is wrong, Linux on the directory of the number of files is basically unlimited (limited to the inode can be ignored), but for the directory of the number of subdirectories are indeed limited, up to 31,998.


The following content reproduced from: http://www.51testing.com/?uid-225738-action-viewspace-itemid-236959


A problem was detected in the KVM build system last night, followed by a discovery that failed to create the directory under a directory mkdir. I tried it manually, prompted as follows: Cannot create directory '/home/master/jaytemp ' too many links
I found that there is a limit to the number of subdirectories in a directory, so I did some experiments and investigations, With blogs written by other people on the Internet, you get some of the following conclusions about the number of directories and the limits of file numbers. The number of subdirectories at the
1.ext3 file system level defaults to 31998 (a), or 32,000, exactly.
Linux is defined for CPU search efficiency, and the kernel needs to be recompiled to change the number limit. I see this in the kernel code:
Include/linux/ext2_fs.h: #define ext2_link_max            32000
Include/linux/ext3_fs.h: #define ext3_link_max            32000
Why do you say 31,998? This is because when mkdir creates a directory, the directory will create two subdirectories by default, one is. Directory (representing current directory), and the other is. Directory (on behalf of the parent directory). These two subdirectories are not removed, "rm." "Will get" rm:cannot remove ". ' or ' ... '" The hint. So 32000-2=31998.
In addition, you can try it by following the script below.

#!/bin/bash
mkdir tmp
CD tmp
I=1
While [$i-lt 35000]
Todo
mkdir $i
If [$?-ne 0]; Then
echo "Cannot make dir $i"
Exit
Fi
((i++))
Done
Run this script and you end up with an error message for "Mkdir:cannot Create directory ' 31999 ': Too many links".
Also, it is not recommended to have too many files or directories in one directory, which reduces the file system's ability to find files or directories. Suddenly think of Alibaba's picture server in the image of the storage according to the year and so divided into different levels of subdirectories rather than in a directory, one of the reasons for the performance of the Linux operating system considerations.
The maximum number of files in a single directory under the 2.ext3 file system is not particularly limited, but is limited by the number of Inode in the file system.
I tested it in Rhel5u5 's ext3 file system, and it was fine to touch 1 million files in one directory. However, it is bound to be limited by the number of Inode in the file system.
Df-i/dev/sdax or use tune2fs-l/dev/sdax or dumpe2fs-h/dev/sdax to see the number of available inode, the latter two command output is the same, but with DF the number of available inode can be some error, the reason, I didn't get it.
There are two ways to resolve the number of inode restrictions on the internet, but I haven't tried it.
2.1 Adjust the number of inode when MKFS,MKFS (depending on the total number of files in FS), block size smaller (depending on the average size of each file)
2.2 Temporary resolution using the loopback file system: Create a large file in/usr (or elsewhere), then make a loopback file system, move the original file to the filesystem, and mount it to the appropriate location under/usr. This will greatly reduce the number of files in your/usr. But the system performance will be somewhat lost.
3. Default number of open files (file descriptor) limit (default is 1024)
The Ulimit-n command allows you to view
Modify this limit to use the Ulimt-shn 65535 command
You can also set the number of user open files, process number, CPU and other information in/etc/security/limit.conf
4.ext3File system maximum character length under filename(default 255 English characters)
Lenth= ' for i in {1..255};d o for x in A;do echo-n $x;d one;done '
Touch $LENTH
When you increase to 256, the touch complains, File name too long
Linux system under ext3 File/directory naming, the longest can only support 127 Chinese characters, English can support 255 characters

Reference Documentation:
http://bbs.chinaunix.net/viewthread.php?tid=1972687
Http://www.unixreference.net/articles/linux/fs/2007/1115/651.html
Http://it.chinawin.net/os/article-3958.html
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.