Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux set the maximum number of open files nofile and nr_open, file-max Description     - How to create a secure and easy to remember password (Linux)

- Windows 7 hard disk to install Ubuntu 14.10 (Linux)

- C # compiler to achieve functional use in the runtime (Programming)

- VMware Workstation virtual machine startup error: Could not open / dev / vmmon in CentOS 6 (Linux)

- MD5 and simple to use (Linux)

- Deploy the project to the server from GitHub (Server)

- Java method to read and write files summary (Programming)

- How to implement large-scale distributed Yahoo depth study on the Hadoop cluster (Server)

- Log analysis is done with Grafana Elasticsearch (Server)

- The best tools and techniques to find data on a Unix system (Linux)

- KVM add virtual disks (Linux)

- Install Java 8 on Ubuntu using PPA (Linux)

- Iptables use examples (Linux)

- CentOS7 virtual machine creation failed Solution (Linux)

- VirtualBox 4.3 Can not open a new task for a virtual computer solution (Linux)

- TCP protocol flaw incomplete records (Linux)

- DDOS Attacks and Prevention (Linux)

- Python programmers most often committed ten errors (Programming)

- crontab cause CPU exception Analysis and Processing (Linux)

- [JavaScript] catch (ex) statements of ex (Programming)

 
         
  Linux set the maximum number of open files nofile and nr_open, file-max Description
     
  Add Date : 2018-11-21      
         
         
         
  In the development of operation and maintenance, when we often encounter similar "Socket / File: Can not open so many files", "Can not open more processes," or coredump too large and other issues, these can be set up to resolve the resource limits . Today, when a customer teaching method to set the maximum number of files when searching online method is not quite consistent with each discovery, he wrote this document.

Usually a Linux user to set the system resources, we already know that you can use to view and set the ulimit command.

Table 1. ulimit Parameter Description

Options [options] Examples of meaning
-H Hard set resource limits, once set can not be increased. ulimit - Hs 64; hard resource limit, thread stack size is 64K.
-S Soft set resource limits can be increased after the set, but can not exceed the hard-resource settings. ulimit - Sn 32; soft resource limit, 32 file descriptors.
-a displays all current limit information. ulimit - a; displays all current limit information.
-c maximum core file size, in units of blocks. ulimit - c unlimited; the generated core file size is not restricted.
-d Maximum size of the data segment of the process, in units of Kbytes. ulimit -d unlimited; to process data segment size is not restricted.
-f file process can create maximum value in units of blocks. ulimit - f 2048; limiting process can create the maximum file size is 2048 blocks.
-l maximum locked memory size in Kbytes units. ulimit - l 32; limit the maximum memory size can be locked to 32 Kbytes.
-m maximum memory size in Kbytes units. ulimit - m unlimited; maximum memory is not to be limiting.
-n can open the maximum number of file descriptors. ulimit - n 128; 128 may be used to limit the maximum file descriptors.
-p Pipe buffer size to Kbytes units. ulimit - p 512; restrictions pipe buffer size of 512 Kbytes.
-s thread stack size in Kbytes units. ulimit - s 512; restrictions thread stack size is 512 Kbytes.
-t Maximum CPU usage time, in seconds. ulimit - t unlimited; maximum CPU usage time is not restricted.
-u The maximum number of processes available to the user. ulimit - u 64; limit the user can use up to 64 processes.
-v maximum available process virtual memory in Kbytes units. ulimit - v 200000; limit the maximum available virtual memory 200000 Kbytes.
Of course, we all know that most of the Linux command set are temporary in effect and ulimit command takes effect only for the current terminal, if desired permanent effect, we have two ways, one is to write the command profile and bashrc, and in some web page said wrote rc.local, in fact, is wrong; Another is to add records (you need to restart to take effect, and the seesion in /etc/pam.d/ have to limit the use of the module) in the limits.conf. The next discussion is the maximum number of open files limits.conf user restrictions related content.

Limit the maximum number of open files for the user, in limits.conf corresponding nofile, whether man or manual document describing just the word "maximum number of open files", which in fact corresponds to the maximum number of files that can be opened in a single process, usually in order to save time, we want to abolish its restrictions, according to the man page, "values ​​-1, unlimited or infinity indicating no limit", - 1, unlimited, infinity is not to show limitations, but when you actually set to nofile this value, so you will find the restart can not log in the system.

Thus, nofile there is an upper limit, but with ulimit test:

#ulimit -n unlimited

bash: ulimit: open files: can not modify limit: Operation not permitted

Write a simple for loop drawn:

#for V in `seq 100000 10000000`; do ulimit -n $ V; [[$ = 0]?!] && break; done

Then execute ulimit -n, you can see that the maximum nofile of 1048576, but why is this value? 1048576 1024 * 1024, of course, and no eggs available. . . Then tracking what we will find that this value is actually defined by the kernel parameter nr_open:

# Cat / proc / sys / fs / nr_open

1048576

We will talk about this nr_open, and file-max, the Internet when it comes to setting the maximum number of files occasional post also says that you want to modify file-max, literally like a true file-max corresponds to the maximum number of files, in the Linux kernel documentation they explain two are:

file-max:

The value in file-max denotes the maximum number of file-
handles that the Linux kernel will allocate. When you get lots
of error messages about running out of file handles, you might
want to increase this limit

Executive: grep -r MemTotal / proc / meminfo | awk '{printf ( "% d", $ 2/10)}', can see the file-max is similar;

nr_open:

This denotes the maximum number of file-handles a process can
allocate. Default value is 1024 * 1024 (1048576) which should be
enough for most machines. Actual limit depends on RLIMIT_NOFILE
resource limit.

Amount, this writer a little dizzy, file-handles (that is, file handle), and then compared in terms of UNIX / LINUX, we are contacting more file discriptor (FD, ie file descriptor), Baidu search seemed file -handle in windows in a similar file discrptor stuff, but we are talking about linux, then google it, we can be accurate to the difference between these two concepts in the c language, according to their discussion of file-handle should be a high-level objects, use fopen, fread, etc. function to call, and FD is an object underlying, can be called open, read and other functions.

At this point, we should be under a general conclusions, file-max is the maximum number of files the kernel can be allocated, nr_open is the maximum number of files that can be assigned a single process, so when we use the ulimit or limits.conf set, if nr_open need to increase the value (sysctl -w fs.nr_open = 100000000 or write directly to sysctl.conf file) 1048576 to exceed the default value. Of course, one million level single-process maximum number of open file-handle should be enough of it. .
     
         
         
         
  More:      
 
- error 1819 (HY000): your password does not satisfy the current policy requirements (Database)
- Linux SVN account password to save your settings (Linux)
- Linux System Getting Started Tutorial: mounted directly in Linux LVM partition (Linux)
- How to install Linux Kernel 4.4 on Ubuntu (Linux)
- Oracle View Object Information (Database)
- Oracle to start to solve the error ORA-27102 (Database)
- Linux install and configure Heartbeat (Server)
- How to clean up your Ubuntu 14.10 / 14.04 / 13.10 system (Linux)
- C ++ precision performance test function (Programming)
- Oracle Migration partition table (Database)
- 10 Nginx safety tips (Linux)
- Specifies the open ports of the SUSE firewall settings (Linux)
- CentOS 7.0 local address and configure yum source address priority (Linux)
- Linux LVM Logical Volume Management to resize partitions (Linux)
- Linux operating system log system (Linux)
- KVM usb passthrough configuration (Linux)
- CentOS / RedHat system partition essential requirements and partition scheme (Linux)
- dmidecode command Detailed (Hardware information) (Linux)
- Linux system security configuration Collection (Linux)
- Can not empty the Recycle Bin to repair problems in Ubuntu 14.04 (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.