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. 怎样将.h文件添加到项目中

    作为C++的初学者,在运行别人的程序时,第一个遇到的问题就是无法将程序中写到的.h文件包含到项目中来.下面来写一下处理方法.本文以easyx.h为例进行说明 首先右键你的工程 选择Properties ...

  2. C#开发BIMFACE系列43 服务端API之图纸拆分

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在上一篇博客<C#开发BIMFACE系列42 服务端API之图纸对比>的最后留了一个问题,在常规业务场景下,一 ...

  3. js 判断一个变量是否有值

    最近遇到一个面试题,判断一个变量是否有值,当时有点蒙,其实很简单,就是判断 变量是否为 undefined或者null function isFlag(val) { if(Object.prototy ...

  4. 巧用 CSS3 filter(滤镜) 属性

    原文链接:CSS3 filter(滤镜) 属性 效果预览 filter: grayscale(100%); 定义和使用 filter 属性定义了元素(通常是<img>)的可视效果(例如:模 ...

  5. Coursera Deep Learning笔记 卷积神经网络基础

    参考1 参考2 1. 计算机视觉 使用传统神经网络处理机器视觉的一个主要问题是输入层维度很大.例如一张64x64x3的图片,神经网络输入层的维度为12288. 如果图片尺寸较大,例如一张1000x10 ...

  6. Scrum Meeting 0503

    零.说明 日期:2021-5-3 任务:简要汇报两日内已完成任务,计划后两日完成任务 一.进度情况 组员 负责 两日内已完成的任务 后两日计划完成的任务 qsy PM&前端 完成登录.后端管理 ...

  7. 2021.9.18考试总结[NOIP模拟56]

    T1 爆零 贪心地想,肯定要先走完整个子树再走下一个,且要尽量晚地走深度大的叶子.所以对每个点的儿子以子树树高为关键字排序$DFS$即可. 也可$DP$. $code:$ T1 #include< ...

  8. 2021.7.21考试总结[NOIP模拟22]

    终于碾压小熠了乐死了 T1 d 小贪心一波直接出正解,没啥好说的(bushi 好像可以主席树暴力找,但我怎么可能会呢?好像可以堆优化简单找,但我怎么可能想得到呢? 那怎么办?昨天两道单调指针加桶,我直 ...

  9. 21.6.29 test

    \(NOI\) 模拟赛 \(T1\) 正解是个题解难以理解的数论,结果是组合数相加.暴力分拿满了,尝试打了 \(20*20\) 的表,最后大概打出了个三角形的表,并且帮我找到了一些性质.\(45\)p ...

  10. 实验6:开源控制器实践——RYU

    实验目的 能够独立部署RYU控制器 能够理解RYU控制器实现软件定义的集线器原理 能够理解RYU控制器实现软件定义的交换机原理 二.实验环境 下载虚拟机软件Oracle VisualBox或VMwar ...