Author Topic: Changing the default limits of server  (Read 4728 times)


  • Administrator
  • Full Member
  • *****
  • Posts: 94
  • Karma: 1
Changing the default limits of server
« on: June 22, 2010, 05:03:04 AM »
We know that we have limits for number of open files, number of processes, memory etc. We can see all the details by command ulimit -a, which gives output for example;

core file size                           (blocks, -c) 0
data seg size                          (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                                  (blocks, -f) unlimited
pending signals                     (-i) 8127
max locked memory              (kbytes, -l) 64
max memory size                  (kbytes, -m) unlimited
open files                              (-n) 1024
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) 1024
virtual memory                     (kbytes, -v) unlimited
file locks                               (-x) unlimited

We can change limit by giving commands like;

ulimit -n 10000 ; for changing the number of open files
ulimit -f 4096 ; for changing the size of a file from unlimited to 4MB
ulimit -l 256 ; for changing the size of memory locked in KB

But changed made by all above commands will reset to defaults whenever our server reboots. For keeping these changes permanently we have to define these into the limits configuration file which is located as /etc/security/limits.conf.

In /etc/security/limits.conf we can specify limits to user or groups or to all by specifying the user name or group name or even we can use wild card like * to apply it to all user on the server. We can specify limits as soft or hard.

The syntax for entries in file is;
<domain> <type> <item> <value>
    * <domain> can be:
          o an user name
          o a group name, with @group syntax
          o the wildcard *, for default entry
          o the wildcard %, can be also used with %group syntax, for maxlogin limit
    * <type> can have the two values:
          o "soft" for enforcing the soft limits
          o "hard" for enforcing hard limits
    * <item> can be one of the following:
          o core - limits the core file size (KB)
    * <value> can be one of the following:
          o core - limits the core file size (KB)
          o data - max data size (KB)
          o fsize - maximum filesize (KB)
          o memlock - max locked-in-memory address space (KB)
          o nofile - max number of open files
          o rss - max resident set size (KB)
          o stack - max stack size (KB)
          o cpu - max CPU time (MIN)
          o nproc - max number of processes
          o as - address space limit
          o maxlogins - max number of logins for this user
          o maxsyslogins - max number of logins on the system
          o priority - the priority to run user process with
          o locks - max number of file locks the user can hold
          o sigpending - max number of pending signals
          o msgqueue - max memory used by POSIX message queues (bytes)
          o nice - max nice priority allowed to raise to
          o rtprio - max realtime priority
          o chroot - change root to directory (Debian-specific)

Now as we had example of three changes in limits, we will do the same entries in limits.conf to make them permanent.

* hard nofile 10000
* soft fsize 4096
* - memlock 256

First entry makes default limit of number of open files to 10000 which was 1024
Second entry makes default limit of maximum file size to 4MB from unlimited
Third entry makes default limit of memory locked to 256 KB which was 64 KB.

Always be cautious before changing any default limits. Changing wrong limit could stop your server working.