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 not 65536.

/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的更多相关文章

  1. Soft Drinking(水)

    A. Soft Drinking time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. 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 ...

  3. BNU27937——Soft Kitty——————【扩展前缀和】

    Soft Kitty Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class n ...

  4. Process Kill Technology && Process Protection Against In Linux

    目录 . 引言 . Kill Process By Kill Command && SIGNAL . Kill Process By Resource Limits . Kill Pr ...

  5. AIX日常维护

    1  /etc/security/limits与limit命令 AIX 5.3上 下面是文件/etc/security/limits文件里面有关软限制和硬限制的部分. * * Sizes are in ...

  6. Oracle安装基本步骤

    安装数据库 .建立用户组及用户 groupadd oinstall groupadd dba groupadd oper useradd -g oinstall -G dba oracle passw ...

  7. AIX stack_hard参数

    OS:AIX 7.1 root.oracle.grid用户查看资源限制,其中stack受限,需要在/etc/security/limits中增加stack_hard = -1,受硬限制限制! [ora ...

  8. 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 ...

  9. Redis源代码分析(二十二)--- networking网络协议传输

    上次我仅仅分析了Redis网络部分的代码一部分,今天我把networking的代码实现部分也学习了一遍,netWorking的代码很多其它偏重的是Clientclient的操作.里面addReply( ...

随机推荐

  1. 火爆全网的《鱿鱼游戏》,今天用 Python 分析一波影评

    Hello,各位读者朋友们好啊,我是小张~ 这不国庆嘛,就把最近很火的一个韩剧<鱿鱼游戏>刷了下,这部剧整体剧情来说还是非常不错的,很值得一看, 作为一个技术博主,当然不能在这儿介绍这部剧 ...

  2. SpringCloud升级之路2020.0.x版-25.OpenFeign简介与使用

    本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent OpenFeign 的由来和实现思路 在微服务系统中,我们经常会进行 RPC 调用.在 S ...

  3. 关于dp那些事

    拿到一道题,先写出状态转移方程,再优化时间复杂度 状态优化: 对于状态可累加 \(e.g.dp[i+j]=dp[i]+dp[j]+i+j\) 的,用倍增优化 决策优化: \(e.g.dp[i][j]= ...

  4. 题解 [SHOI2012]随机树

    题目传送门 Description \(n\le 100\) Solution Problem 1 不难看出,答案就是: \[1+\sum_{i=1}^{n-1} 2/(i+1) \] Problem ...

  5. appium启动ios系统上面的app需求的参数

    Appium启动APP至少需要7个参数  'platformVersion','deviceName'.'udid'.'bundleId'.'platformName'.'automationName ...

  6. Java(9)数组详解

    作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15201564.html 博客主页:https://www.cnblogs.com/testero ...

  7. NXOpen.BlockStyler的一些用法

    关于BLOCK UI的一些控件的用法,本人曾经使用的代码,拿出来共享: Option Strict Off Imports NXOpen Imports NXOpen.BlockStyler Impo ...

  8. /usr/bin/python^M: bad interpreter: No such file or directory

    利用如下命令查看文件格式 :set ff 或 :set fileformat 可以看到如下信息 fileformat=dos 或 fileformat=unix 利用如下命令修改文件格式 :set f ...

  9. 【死磕 NIO】— Reactor 模式就一定意味着高性能吗?

    大家好,我是大明哥,我又来了. 为什么是 Reactor 一般所有的网络服务,一般分为如下几个步骤: 读请求(read request) 读解析(read decode) 处理程序(process s ...

  10. 『学了就忘』Linux基础 — 6、VMware虚拟机安装Linux系统(超详细)

    目录 1.打开VMware虚拟机软件 2.选择Linux系统的ISO安装镜像 3.开启虚拟机安装系统 (1)进入Linux系统安装界面 (2)硬件检测 (3)检测光盘 (4)欢迎界面 (5)选择语言 ...