Re: [PATCH] Patch to Memory Subsystem ... (Needed?)

Riley Williams (rhw@bigfoot.com)
Sun, 8 Nov 1998 19:28:01 +0000 (GMT)


Hi Brian.

Alan: Can you comment on this please?

>>>>> Oh! The cobol-applications are usually run during night when
>>>>> nobody uses the servers - so no 'bash', 'ps' or the like are in
>>>>> the cache. The next morning when somebody tries to login (s)he
>>>>> will be denied access ....

>>>> What about limiting memory using ulimit()?

>>> With clever usage it could be used - but I am not sure how ;o)

>> The obvious fix here, assuming the current program is called PROG
>> and is in the current directory, would be something along the
>> lines of:

>> Q> mv PROG PROG.1
>> Q> cat > PROG <<.EOF
>> Q> #!/bin/bash
>> Q> FM="\`free | grep '^[MS]' | tr -s ' ' | cut -d ' ' -f 4\`"
>> Q> FM=\$[\`echo -n \$FM | tr ' ' '+'\`]
>> Q> ulimit -l \`echo \$FM '3*4096/p' | dc\`
>> Q> PROG.1 \$\*
>> Q> .EOF
>> Q> chmod 700 PROG

>> Of course, change the mode in the last line to suit...the above
>> should limit that process to 75% of the [combined real and swap]
>> memory free when the program was first run...

> I don't think that's the way to do it - it would mean that one
> would have to write a wrapper for each program one suspect of being
> able to eat all memory.

A simple variant thereof would make it work similar to the 'time'
command, in that it takes the command to run as parameters...

> NEWSFLASH! I just tried your script - I had to modify it a bit
> (hopefully I didn't break anything ...):

8-) You obviously didn't realise that if you typed each line as
listed at the bash prompt, you'd get the intended script - certain
characters had to be escaped that way to get the correct characters in
the target script...

> #!/bin/bash
> FM="$(free | grep '^[MS]' | tr -s ' ' | cut -d ' ' -f 4)"
> FM=$[$(echo $FM | tr ' ' '+')]
> ulimit -l $(echo $FM '3*4096/p' | dc)
> ulimit -l
> read an
> eat

Take the second 'ulimit' line out - it reverses the effect of the
first line...

Also, try the following variant thereof...

Q> #!/bin/bash
Q> FM="`free | grep '^[MS]' | tr -s ' ' | cut -d ' ' -f 4`"
Q> FM=$[`echo $FM | tr ' ' '+'`]
Q> ulimit -l `echo $FM '3*4096/p' | dc`
Q> exec $*

Then feed that the relevant command as a parameter and advise re the
result...

> 'eat' is the program I supplied in my initial mail .... And it does
> what it is asked to do: eat all available memory (ulimit -l
> couldn't stop it ....)

> I've even tried to play around with ulimit:

> bsc@cryo:/home/bsc > ulimit -l 2048 # max size any prog can get in this
> shell
> # is 2Mb (hopefully)
> bsc@cryo:/home/bsc > ./eat # goodbye available memory

> ... it might be I who uses the ulimit command wrongly ...

I don't think so - if that is indeed true, there would appear to be a
kernel bug in the MM subsystem...

Best wishes from Riley.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/