public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] limit maximum memory size of any process
@ 2008-11-03 10:24 Zhang Weiwu
  2008-11-03 11:48 ` b.n.
  2008-11-03 12:54 ` Matthias Bethke
  0 siblings, 2 replies; 5+ messages in thread
From: Zhang Weiwu @ 2008-11-03 10:24 UTC (permalink / raw
  To: gentoo-user

Hello.

In my daily us of computer any process that takes more than 50% of the
memory (I read from top, not knowing if this is 50% of 384MB physical or
50% of having 800MB swap counted in) must have gone wrong, and usually
drag performance down to such extent that killing it is impossible
(because not possible to launch a terminal window to type kill -TERM).
Examples are:

   1. Firefox opens a broken website that wish to send 10M binary
      content to the browser window;
   2. OpenOffice opens a document incorrectly;
   3. Mistake in Java software (usually it keep eating memory);

I hope I can configure the system so that any process uses more than 50%
of memory are automatically killed. first I was recommend to use ulimit
by googling around. However this seems doesn't work even if I set both
-d and -m (here is my .xinitrc)

~$ cat .xinitrc
#export XMODIFIERS=@im=FCITX
#fcitx &
ulimit -d 300000
ulimit -m 300
exec /usr/bin/fluxbox


Result: OpenOffice stands still even when it takes 80% memory (read from
top).
So: is ulimit the solution? If so, what option should I set? My current
ulimit is:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) 300000
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3072
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) 300
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) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3072
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


-- 
Real Softservice

Huateng Tower, Unit 1788
Jia 302 3rd area of Jinsong, Chao Yang

Tel: +86 (10) 8773 0650 ext 603
Mobile: 159 1111 7382
http://www.realss.com




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] limit maximum memory size of any process
  2008-11-03 10:24 Zhang Weiwu
@ 2008-11-03 11:48 ` b.n.
  2008-11-03 12:54 ` Matthias Bethke
  1 sibling, 0 replies; 5+ messages in thread
From: b.n. @ 2008-11-03 11:48 UTC (permalink / raw
  To: gentoo-user

Zhang Weiwu ha scritto:

> So: is ulimit the solution? If so, what option should I set? My current
> ulimit is:
> 
> $ ulimit -a
> core file size          (blocks, -c) 0
> data seg size           (kbytes, -d) 300000
> scheduling priority             (-e) 0
> file size               (blocks, -f) unlimited
> pending signals                 (-i) 3072
> max locked memory       (kbytes, -l) 32
> max memory size         (kbytes, -m) 300
> 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) 8192
> cpu time               (seconds, -t) unlimited
> max user processes              (-u) 3072
> virtual memory          (kbytes, -v) unlimited
> file locks                      (-x) unlimited


On my machine I use "ulimit -v" and it works- however never tried it
inside a script.

m.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] limit maximum memory size of any process
  2008-11-03 10:24 Zhang Weiwu
  2008-11-03 11:48 ` b.n.
@ 2008-11-03 12:54 ` Matthias Bethke
  1 sibling, 0 replies; 5+ messages in thread
From: Matthias Bethke @ 2008-11-03 12:54 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1770 bytes --]

Hi Zhang,
on Mon, Nov 03, 2008 at 06:24:00PM +0800, you wrote:
> I hope I can configure the system so that any process uses more than 50%
> of memory are automatically killed. first I was recommend to use ulimit
> by googling around. However this seems doesn't work even if I set both
> -d and -m (here is my .xinitrc)
> 
> ~$ cat .xinitrc
> #export XMODIFIERS=@im=FCITX
> #fcitx &
> ulimit -d 300000
> ulimit -m 300
> exec /usr/bin/fluxbox
> 
> 
> Result: OpenOffice stands still even when it takes 80% memory (read from
> top).
> So: is ulimit the solution? If so, what option should I set?

I interpret the above as "use a maximum of 300,000 KiB of memory, of
which 300 may be resident (i.e. in physical memory) and 299,700 swapped
out." That doesn't sound good, although I'm not sure I'm reading it
correctly.
What I do is use /etc/sercurity/limits.conf (from pam_limits) with a
couple of entries like those:
| @users           hard    nproc           1000
| mb               hard    nproc           5000
| @users           hard    as              2097152
| mb               hard    as              6291456
| mb               hard    nice            -5
| mb               hard    rtprio          5
Meaning, everyone but me (mb) may use up to 1000 processes per login,
with a max. address space of 2 GiB each; for myself the limit is 6 GiB
and 5k processes. Myself I cannot accidentially set a negative
nice-value because I left the soft limit at its default (0 for non-root
users) but using ulimit I can set it to the hard limit of -5 and nice-up
processes even as a normal user.

cheers,
	Matthias
-- 
I prefer encrypted and signed messages. KeyID: FAC37665
Fingerprint: 8C16 3F0A A6FC DF0D 19B0  8DEF 48D9 1700 FAC3 7665

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] limit maximum memory size of any process
       [not found] ` <bu7cp-jh-1@gated-at.bofh.it>
@ 2008-11-04  7:30   ` Zhang Weiwu
  2008-11-04 18:02     ` Matthias Bethke
  0 siblings, 1 reply; 5+ messages in thread
From: Zhang Weiwu @ 2008-11-04  7:30 UTC (permalink / raw
  To: gentoo-user

Matthias Bethke wrote:
> Hi Zhang,
> on Mon, Nov 03, 2008 at 06:24:00PM +0800, you wrote:
>> I hope I can configure the system so that any process uses more than 50%
>> of memory are automatically killed. first I was recommend to use ulimit
>> by googling around. However this seems doesn't work even if I set both
>> -d and -m (here is my .xinitrc)
>>
>> ~$ cat .xinitrc
>> #export XMODIFIERS=@im=FCITX
>> #fcitx &
>> ulimit -d 300000
>> ulimit -m 300
>> exec /usr/bin/fluxbox
>>
>>
>> Result: OpenOffice stands still even when it takes 80% memory (read from
>> top).
>> So: is ulimit the solution? If so, what option should I set?
> 
> I interpret the above as "use a maximum of 300,000 KiB of memory, of
> which 300 may be resident (i.e. in physical memory) and 299,700 swapped
> out." That doesn't sound good, although I'm not sure I'm reading it
> correctly.

Sorry, it seems I used these parameter without care. I guess I only need
to set physical memory limit, a.k.a. resident memory.

OT: I don't know why I have
max locked memory       (kbytes, -l) 32
But it has been like that before I set ulimit.


> What I do is use /etc/sercurity/limits.conf (from pam_limits) with a
> couple of entries like those:
> | @users           hard    nproc           1000
> | mb               hard    nproc           5000
> | @users           hard    as              2097152
> | mb               hard    as              6291456
> | mb               hard    nice            -5
> | mb               hard    rtprio          5
> Meaning, everyone but me (mb) may use up to 1000 processes per login,
> with a max. address space of 2 GiB each; for myself the limit is 6 GiB
> and 5k processes. Myself I cannot accidentially set a negative
> nice-value because I left the soft limit at its default (0 for non-root
> users) but using ulimit I can set it to the hard limit of -5 and nice-up
> processes even as a normal user.

I don't have a file called /etc/sercurity/limits.conf and neither can I
find information about it by using 'man limits.conf'. Further I couldn't
find a package called pam_limits to emerge. Can you give me some clue which
package I should emerge in order to set limits.conf ?

Thank you very much for prompt help!



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] limit maximum memory size of any process
  2008-11-04  7:30   ` [gentoo-user] limit maximum memory size of any process Zhang Weiwu
@ 2008-11-04 18:02     ` Matthias Bethke
  0 siblings, 0 replies; 5+ messages in thread
From: Matthias Bethke @ 2008-11-04 18:02 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1529 bytes --]

Hi Zhang,
on Tue, Nov 04, 2008 at 03:30:55PM +0800, you wrote:
> > I interpret the above as "use a maximum of 300,000 KiB of memory, of
> > which 300 may be resident (i.e. in physical memory) and 299,700 swapped
> > out." That doesn't sound good, although I'm not sure I'm reading it
> > correctly.
> 
> Sorry, it seems I used these parameter without care. I guess I only need
> to set physical memory limit, a.k.a. resident memory.

Yes, that sounds reasonable. Remember it's in kilobytes so that would be
300000.

> OT: I don't know why I have
> max locked memory       (kbytes, -l) 32
> But it has been like that before I set ulimit.

"Locked memory" is memory that a process has protected against being
swapped to disk. The best-known example is the memory gpg uses to store
keys and passphrases, it would be pretty bad if it got swapped and
someone could find your unprotected key on the disk later, so gpg tries
to lock this memory in RAM.

> I don't have a file called /etc/sercurity/limits.conf and neither can I
> find information about it by using 'man limits.conf'. Further I couldn't
> find a package called pam_limits to emerge. Can you give me some clue which
> package I should emerge in order to set limits.conf ?

The pam_limits module is part of the standard PAM distribution, here
it's sys-libs/pam-1.0.1. Maybe just re-emerge it?

cheers,
	Matthias
-- 
I prefer encrypted and signed messages. KeyID: FAC37665
Fingerprint: 8C16 3F0A A6FC DF0D 19B0  8DEF 48D9 1700 FAC3 7665

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-04 18:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <bu4Re-5qH-5@gated-at.bofh.it>
     [not found] ` <bu7cp-jh-1@gated-at.bofh.it>
2008-11-04  7:30   ` [gentoo-user] limit maximum memory size of any process Zhang Weiwu
2008-11-04 18:02     ` Matthias Bethke
2008-11-03 10:24 Zhang Weiwu
2008-11-03 11:48 ` b.n.
2008-11-03 12:54 ` Matthias Bethke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox