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

Brian Schau (bsc@fleggaard.dk)
Sun, 08 Nov 1998 20:21:23 +0100


Hello Riley,

Riley Williams wrote:
>
> Hi Brian.
>
> >>> 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)
> > Point is, the program in question isn't started from a shell. I could
> > do a work-around.
>
> If it's not started from a shell, how is it started then?

Got me! It is started from a shell - during the boot of the machine.
When started the daemon forks, detaches itself from the controlling tty
- the standard way. And then the shell exits ...

>
> 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.

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

#!/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

'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 ...

>
> > Still, I hate the idea that user-processes can eat all memory,
> > leaving nothing to root in case of problems .........
>
> It's certainly something to consider...
>
> 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/