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
63536and 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( ...
随机推荐
- go语言游戏服务端开发(四)——RPC机制
五邑隐侠,本名关健昌,12年游戏生涯. 本教程以Go语言为例. RPC指远程方法调用,游戏里引入RPC目的是降低跨进程交互的复杂度. 游戏业务设计为多go routine,一个玩家一个go routi ...
- 基础篇——Pycharm的安装与使用 初学者此篇够用
简介 Pycharm是python编程过程中最为推荐的编辑调试软件之一,其使用简单,界面友好,也成了学习Python路上必须学会的软件之一,本篇教程简单介绍一下windows用户从安装到日常使用的基本 ...
- windows下编译caffe出现错误 C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe?
解决方案来自http://blog.csdn.net/u012556077/article/details/50353818
- Java基础之(八):顺序结构与选择结构
顺序结构 Java的基本结构就是顺序结构 顺序结构是最简单的算法结构 它是任何一个算法都离不开的一种基本算法结构. 例子: public static void main(String[] args) ...
- 第6次 Beta Scrum Meeting
本次会议为Beta阶段第6次Scrum Meeting会议 会议概要 会议时间:2021年6月8日 会议地点:「腾讯会议」线上进行 会议时长:15min 会议内容简介:对完成工作进行阶段性汇报:对下一 ...
- 在Vue前端项目中,附件展示的自定义组件开发
在Vue前端界面中,自定义组件很重要,也很方便,我们一般是把一些通用的界面模块进行拆分,创建自己的自定义组件,这样操作可以大大降低页面的代码量,以及提高功能模块的开发效率,本篇随笔继续介绍在Vue&a ...
- SpringCloud 2020.0.4 系列之服务降级的其他用法与熔断
1. 概述 老话说的好:控制好自己的情绪,才能控制好自己的人生.冲动是魔鬼,冷静才最重要. 言归正传,之前聊了在 Feign 调用时,如何给整个 Feign接口类 增加降级策略. 今天我们来聊一下 H ...
- reactnative实现qq聊天消息气泡拖拽消失效果
前言(可跳过) 我在开发自己的APP时遇到了一个类似于qq聊天消息气泡拖拽消息的需求,因为在网上没有找到相关的组件,所以自己动手实现了一下 需求:对聊天消息气泡拖拽到一定长度松开时该气泡会消失(可自行 ...
- .NET Core TLS 协议指定被我钻了空子~~~
前言 此前,测试小伙伴通过工具扫描,平台TLS SSL协议支持TLS v1.1,这不安全,TLS SSL协议至少是v1.2以上才行,想到我们早已将其协议仅支持v1.3,那应该非我们平台问题.我依然自信 ...
- PHP笔记3__简易计算器
<?php header("Content-type: text/html; charset=utf-8"); error_reporting(E_ALL & ~E_ ...