soft and hard limit
soft限制了资源使用上限; soft可调整; hard限制了soft上限; 普通用户可使用ulimit -H调低hard limit.
限制的是一个进程可用资源, 而不是某个用户总和.
man setrlimit
RLIMIT_MEMLOCK
This is the maximum number of bytes of memory that may be locked into RAM.
RLIMIT_NOFILE
This specifies a value one greater than the maximum file descriptor number that can be opened by this process.
https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html
ulimit provides control over the resources available to
processes started by the shell
, on systems that allow such control.
临时修改
ulimit命令默认查询/修改soft, 除非明确指定-H. 普通用户不能使用ulimit调大hard, root可以.
$ ulimit -S -n
1024
$ ulimit -H -n
4096
$ ulimit -H -n 2048
$ ulimit -H -n
2048
$ ulimit -S -n
1024
$ ulimit -n 512
$ ulimit -S -n
512
$ ulimit -H -n 4096
-bash: ulimit: open files: cannot modify limit: Operation not permitted
$ ulimit -H -n 3000
-bash: ulimit: open files: cannot modify limit: Operation not permitted
永久修改某个用户的limit
man limits.conf
vi /etc/security/limits.conf:
witness soft nproc 256
witness hard nproc 512
witness soft nofile 256
witness hard nofile 512
重新登录witness用户:
[witness@vm102 ~]$ ulimit -H -n
512
[witness@vm102 ~]$ ulimit -S -n
256
[witness@vm102 ~]$ ulimit -S -u
256
[witness@vm102 ~]$ ulimit -H -u
512
另一种方式: 把ulimit指令放在.bash_profile/.bashrc中[1][2].
proc文件系统可以看到进程当前的limits
$ cat /proc/23/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 1598 1598 processes
Max open files 1024 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 1598 1598 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
nofile/ulimit -n
碰到这个错误: too many open files, 就是这个值不够, 或程序资源没释放. 如果需要可以调大一点.
给别人留一点: hard limit应该小于/proc/sys/fs/file-max[2][3]:
It is not recommend to set the "hard" limit for nofile for the oracle user equal to /proc/sys/fs/file-max. If you do that and the user uses up all the file handles, then the entire system will run out of file handles. This may prevent users logging in as the system cannot open any PAM modules that are required for the login process. That is why the hard limit should be set to
63536
and not65536
.
/var/log/messages: VFS: file-max limit 131072 reached
由于这个是控制的单个进程的资源使用, 一些场景如多进程+多文件, 即每个进程都要打开那么多文件, 就容易超过file-max, 比如进程数200, 文件数500, 200x500=100000 > 65535
. 这时候需要调整file-max.
当前系统使用的fd总数: cat /proc/sys/fs/file-nr
进程使用fd数排序, 结果第二列是pid: lsof -n | awk '{print $2}' | sort -nr | uniq -c | sort -nr | more
core/ulimit -c
如果ulimit -c是unlimited
, 但是无法生成或找不到core文件, sysctl -a | grep core_pattern
.
参考
[1] https://access.redhat.com/solutions/61334
[2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/tuning_and_optimizing_red_hat_enterprise_linux_for_oracle_9i_and_10g_databases/chap-oracle_9i_and_10g_tuning_guide-setting_shell_limits_for_the_oracle_user
[3] https://serverfault.com/questions/235059/vfs-file-max-limit-1231582-reached, "I believe this to be an NFS server bug."
soft and hard limit的更多相关文章
- Soft Drinking(水)
A. Soft Drinking time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #107 (Div. 2)---A. Soft Drinking
Soft Drinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- BNU27937——Soft Kitty——————【扩展前缀和】
Soft Kitty Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class n ...
- Process Kill Technology && Process Protection Against In Linux
目录 . 引言 . Kill Process By Kill Command && SIGNAL . Kill Process By Resource Limits . Kill Pr ...
- AIX日常维护
1 /etc/security/limits与limit命令 AIX 5.3上 下面是文件/etc/security/limits文件里面有关软限制和硬限制的部分. * * Sizes are in ...
- Oracle安装基本步骤
安装数据库 .建立用户组及用户 groupadd oinstall groupadd dba groupadd oper useradd -g oinstall -G dba oracle passw ...
- AIX stack_hard参数
OS:AIX 7.1 root.oracle.grid用户查看资源限制,其中stack受限,需要在/etc/security/limits中增加stack_hard = -1,受硬限制限制! [ora ...
- FAQ of db2fmp messages in the db2diag.log
http://www-01.ibm.com/support/docview.wss?uid=swg21470035 Technote (FAQ) Question What do these mess ...
- Redis源代码分析(二十二)--- networking网络协议传输
上次我仅仅分析了Redis网络部分的代码一部分,今天我把networking的代码实现部分也学习了一遍,netWorking的代码很多其它偏重的是Clientclient的操作.里面addReply( ...
随机推荐
- javascriptRemke之深入迭代
javascriptRemke之深入迭代 前言:"迭代"意为按照顺序反复多次执行一段程序,ECMAscript6中新增了两个高级特性:迭代器与生成器,使用这两个特性能更高效地实现迭 ...
- selenium 4.0 发布
我们非常高兴地宣布Selenium 4的发布.这适用于Java..net.Python.Ruby和Javascript.你可以从你最喜欢的包管理器或GitHub下载它! https://github. ...
- C++ IDE或编辑器安装
IDE介绍 上节课我们讲了C++编译器,可是没有好的编辑器,只用记事本打代码,这谁受得了.Linux vim至少还有代码高亮(即我作文里经常会出现的"彩色的代码"),记事本连高亮都 ...
- props&attrs provide inject
defineComponent({ props: {// 1 } setup (props, {attrs, emit}) { } }) 一,组件传值: 父传子: 1.如果没有在定义的props中声明 ...
- 分享一份软件测试项目实战(web+app+h5+小程序)
大家好,我是谭叔. 本次,谭叔再度出马,给大家找了一个非常适合练手的软件测试项目,此项目涵盖web端.app端.h5端.小程序端,可以说非常之全面. 缘起 在这之前,谭叔已经推出了九套实战教程. 但是 ...
- vue3.x移动端适配px2rem
1.什么是px2rem px2rem是一个插件能将px自动转换为rem,以适配各种不同的屏幕尺寸.前端开发可以直接使用设计稿量出的尺寸或者蓝湖给出的px进行布局,这样极大的提高了开发效率. 2.前提条 ...
- Java:线程池
Java:线程池 本笔记是根据bilibili上 尚硅谷 的课程 Java大厂面试题第二季 而做的笔记 获取多线程的方法: 实现 Runnable 接口 实现 Callable 接口 实例化 Thre ...
- OO课第三单元总结
一.梳理JML语言的理论基础 (1)理论基础 JMl的出现很大程度上一为了行为接口的规范化,用这种语言来指定特定模块的特定功能.JML的核心部分分为三个部分:前置条件(requires).后置条件(e ...
- IPv6(诞生原因、数据报格式、与IPv4的不同、地址表现形式、基本地址类型、IPv6与IPv4的过渡策略)
文章转自:https://blog.csdn.net/weixin_43914604/article/details/105297642 学习课程:<2019王道考研计算机网络> 学习目的 ...
- Python课程笔记(二)
1.格式化输出 print("%d %d %s" % (15, 3.14, 12.8)) 对比C语言 printf("%d,%d,%s",15, 3.14, 1 ...