Linux Limit For Resources

3994 ワード

今日は間違いに遭遇しました.
max file descriptors [65535] for  process is too low, increase to at least [65536]
max number of threads [1024] for user myersguo is too low, increase to at least [2048]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

ここでは、次のファイルに注目します.
まずこの文書/etc/security/limits.confを見てみましょう.
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#            
#
#Where:
# can be:
#        - an user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
# can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
# can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#                 
#

Soft Limits & Hard Limits


Oracleで見られる説明です.素晴らしいです.
You can set both soft and hard limits. The system will not allow a user to exceed his or her hard limit. However, a system administrator may set a soft limit (sometimes referred to as a quota) which can be temporarily exceeded by the user. The soft limit must be less than the hard limit.
Once the user exceeds the soft limit, a timer begins. While the timer is ticking, the user is allowed to operate above the soft limit but cannot exceed the hard limit. Once the user goes below the soft limit, the timer gets reset. However, if the user\s usage remains above the soft limit when the timer expires, the soft limit is enforced as a hard limit. By default, the soft limit timer is seven days.
つまり、soft limitの制限を超えると、タイマーがあり、タイマーが終わると、まだ超えています.KILLで、そうでなければOKです.

3つの制限


max file descriptor

maximum number of open files
ファイル記述子(file descriptor)は、リソース(ファイル、入出力ストリーム、ネットワークsocket接続、etc)の識別である.ファイル記述子が1つも開かれていない場合、システムは一定のメモリを割り当てるため、ファイル記述子の数を制限する必要があります.
プロセスID 3020のファイル記述子を表示するには:
lsof -p 3020  | wc -l
ls -a /proc/3020/fd  | wc -l


更新/etc/security/limits
 *       soft    nofile      65536
 *       hard    nofile      65536

これによりfile descriptorの制限が解決されます.
ulimit-aちょっと見て
*       soft    nproc       2048
*       hard    nproc       2048

あるいは、ulimit -u 2048は、ユーザ毎の最大プロセス数(max user process)を設定.
同じ仮想メモリを設定します.
sysctl -w vm.max_map_count=300000
cat /proc/sys/vm/max_map_count
cat /proc/1920/maps | moreからメモリマッピングを表示できます.
問題は解決したが、私たちにもっと多くの疑問を残したようだ.
微信公衆アカウント:myersguo

参考資料


https://docs.oracle.com/cd/E19455-01/805-7229/sysresquotas-1/index.html https://en.wikipedia.org/wiki/File_descriptor http://duartes.org/gustavo/blog/post/how-the-kernel-manages-your-memory/