How to Increase Ulimit Values in Linux easily

This post will help you with How To Increase Ulimit Values in Linux easily.

The ulimit command provides control over the resources available to the shell and/or to processes started by it, on systems that allow such control.

One normal user may utilize the complete system resources and system won’t be available for other users.So setting the limit to users is very important and you need to be very careful before granting shell limits to them.

You need to be always make sure that system is not going out its system wide limit. For an example , if the maximum system process limit is 64K and if you grated process limit to 4 users as 24K. When these all four users try to use the maximum no of process, system will run out of its limit and you will see fork errors on the system.

How to Increase Ulimit Values in Linux easily

We can set up two limits as shown in the below image.

How To Increase Ulimit Values in Linux easily

Here we are going to see how to set the soft limit and hard limit to the users and also we will see how to increase the system limit.

1. Check the user shell’s soft limit ? Here my user is user1.
[user1@learnitguide ~]$ ulimit -Sa
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 11949
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 8192
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 4096
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[user1@learnitguide ~]$

2. Check the user shell’s hard limit ? Here is the user is user1.
[user1@learnitguide ~]$ ulimit -Ha
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 11949
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 8192
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) 4096
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[user1@learnitguide ~]$

3. User can set their own soft limit ?

Yes. They can able to set their own soft limit up to the hard limit value. Hard limit’s are managed by root user. You can reduce the hardlimit but you can;t increase being a normal user.

You will get the below error, If you try to increase the hard limit from normal user.
[user1@learnitguide ~]$ ulimit -H -u 12288
-bash: ulimit: max user processes: cannot modify limit: Operation not permitted

4.How to increase the hard and soft limit value for user from root login?

To increase the soft & hard limit values to the users, we need to edit “/etc/security/limits.conf” file. Here is the user1’s user’s configuration in limits.conf.
[user1@learnitguide ~]$ tail -7 /etc/security/limits.conf
# End of file
user1   soft   nofile    8192
user1   hard   nofile    8192
user1   soft   nproc    4096
user1   hard   nproc    8192
user1   soft   core    unlimited
user1   hard   core    unlimited
[user1@learnitguide ~]$

After modifying the file, user need to logoff and login again to see the new values.

5.limits.conf file will be used to set the user level limit.Where to set the system level limits ?

To set the system-wide limit, you need to edit the “/etc/sysctl.conf”.For an example, if you want to set number of open files system-wide, edit sysctl.conf and re-load the configuration. Existing system-wide open files limit,
[root@learnitguide ~]# cat /proc/sys/fs/file-max
6815744
[root@learnitguide ~]#

Edit the open files value in  sysctl.conf like below,
[root@learnitguide ~]# cat /etc/sysctl.conf |grep file-max
fs.file-max = 6816768
[root@learnitguide ~]#

Re-load the configuration,and check the system-wide open files value
[root@learnitguide ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.sem = 250 32000 100 128
kernel.shmmax = 4294967295
fs.file-max = 6816768
[root@learnitguide ~]# cat /proc/sys/fs/file-max
6816768
[root@learnitguide ~]#

We have successfully changed the system-wide open files (File descriptor) value.
You can also simply execute the single command to modify these value,but that change will not persist across the system reboot.
[root@learnitguide ~]# sysctl -w fs.file-max=6816768
fs.file-max = 6816768
[root@learnitguide ~]# cat /proc/sys/fs/file-max
6816768
[root@learnitguide ~]#

Hope now you are clear with modifying the ulimit values for user and setting the new resource limit in sysctl.conf file.

Related Content on Linux might be useful to you to improve your Linux Skills.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

Post a Comment

0 Comments