On Wed, Jan 27, 2010 at 9:23 PM, bofh <goodb...@gmail.com> wrote:
>> The idea is to limit memory such that running out of RAM+swap is not
>> possible, or unlikely. You can set the limit on the allowed number of
>> processes as well.
>
>
> $ ulimit -m
> 971876
> $ dmesg | grep real\ mem
> real mem  = 1039691776 (991MB)
>
> So... this box should run only one process?
>
> $ ps -auxww|wc
>      54     713    4936
>
> If I were to use the max memory usage of each process, I would need a
> 53Gig ram machine?

Hmm seems like someone is playing dumb or trolling... Have you read
the man pages? Read setrlimit(2), read your shell's man page. Read the
login.conf man page.

$ man ksh:

[snip]

-d n   Impose a size limit of n kilobytes on the size of the data
                    area.

             -f n   Impose a size limit of n blocks on files written by the
                    shell and its child processes (files of any size may be
                    read).

             -H     Set the hard limit only (the default is to set both hard
                    and soft limits).

             -l n   Impose a limit of n kilobytes on the amount of locked
                    (wired) physical memory.

             -m n   Impose a limit of n kilobytes on the amount of physical
                    memory used.

             -n n   Impose a limit of n file descriptors that can be open at
                    once.

             -p n   Impose a limit of n processes that can be run by the user
                    at any one time.

             -S     Set the soft limit only (the default is to set both hard
                    and soft limits).

             -s n   Impose a size limit of n kilobytes on the size of the
                    stack area.

             -t n   Impose a time limit of n CPU seconds spent in user mode
to
                    be used by each process.

[/snip]


I use 'chpst' from the runit package in my run scripts though.
$ man chpst

[snip]

 -m bytes
              limit memory.  Limit the data segment,  stack  seg-
              ment,  locked physical pages, and total of all seg-
              ment per process to bytes bytes each.

       -d bytes
              limit data segment.  Limit  the  data  segment  per
              process to bytes bytes.

       -o n   limit  open  files.   Limit the number of open file
              descriptors per process to n.

       -p n   limit processes.  Limit the number of processes per
              uid to n.

       -f bytes
              limit  output  size.  Limit the output file size to
              bytes bytes.

       -c bytes
              limit core size.  Limit the core file size to bytes
              bytes.

[/snip]

I just use '-m' with it.

An additional layer of protection from setrlimit() is great to have
even if your daemon limits itself. If there's a bug and a process
starts eating away at memory, it will be killed.

Services as run by 'runit' are supervised by 'runsv' so if a daemon
dies (for any reason, just think of some reasons) it will get
restarted in a second. With runit you can configure some services not
to get restarted, run a script when a service exits, etc, etc. More
features than 'daemontools', but daemontools-compatible.

smarden.org/runit

Reply via email to