|
Home > Archive > alt.os.linux > June 2002 > ulimit and malloc
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Stéphane Perroy 2002-06-24, 7:13 pm |
| Hi,
I'm running Mandrake 7.2 and I'm trying to use the ulimit command:
$ ulimit -Ha
core file size (blocks) 0
data seg size (kbytes) 1024
file size (blocks) unlimited
max locked memory (kbytes) 1024
max memory size (kbytes) 1024
open files 1024
pipe size (512 bytes) 8
stack size (kbytes) 1024
cpu time (seconds) unlimited
max user processes 2048
virtual memory (kbytes) unlimited
$ ulimit -Sa
core file size (blocks) 0
data seg size (kbytes) 1024
file size (blocks) unlimited
max locked memory (kbytes) 1024
max memory size (kbytes) 1024
open files 1024
pipe size (512 bytes) 8
stack size (kbytes) 1024
cpu time (seconds) unlimited
max user processes 2048
virtual memory (kbytes) unlimited
When trying to run the following program, ulimit
works fine and the program do a segmentation fault:
#include <unistd.h>
#include <stdlib.h>
main ()
{
char ent[1];
char p[4*1024*1024];
printf("Press Enter\n");
gets(ent);
}
When trying to run a program with "malloc" memory
allocation, there is no problem: limits from ulimit are
inactives. After the "malloc" command I do a "memset"
to use memory and check memory usage.
#include <unistd.h>
#include <stdlib.h>
main ()
{
char ent[1];
char *p;
int i_len=1024*1024*200;
p = malloc(i_len);
if (p==NULL) {
printf("Alloc Error\n"); }
else {
printf("Alloc OK\n");
memset (p,0,i_len); }
printf("Press Enter\n");
gets(ent);
free (p);
}
My box have 1gb RAM and linux can allocate 200Mb.
I check memory usage with the "top" command:
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
1306 stp 1 0 200M 200M 300 S 0.0 19.5 0:00 tst
Which rules should be respect to limit malloc memory usage?
I'm tryning to set limits from the Bash and PAM and I see no differences.
I can't understand why memory allocation from malloc can't be
detected and the top command has the correct RSS size!
Thanks for your help,
Stephane.
| |
| Nils O. =?iso-8859-1?Q?Sel=E5sdal?= 2002-06-24, 7:13 pm |
| In article <af72na$rhf$3@wanadoo.fr>, Stéphane Perroy wrote:
> Hi,
>
> I'm running Mandrake 7.2 and I'm trying to use the ulimit command:
>
> $ ulimit -Ha
> core file size (blocks) 0
> data seg size (kbytes) 1024
> file size (blocks) unlimited
> max locked memory (kbytes) 1024
> max memory size (kbytes) 1024
> open files 1024
> pipe size (512 bytes) 8
> stack size (kbytes) 1024
> cpu time (seconds) unlimited
> max user processes 2048
> virtual memory (kbytes) unlimited
>
> $ ulimit -Sa
> core file size (blocks) 0
> data seg size (kbytes) 1024
> file size (blocks) unlimited
> max locked memory (kbytes) 1024
> max memory size (kbytes) 1024
> open files 1024
> pipe size (512 bytes) 8
> stack size (kbytes) 1024
> cpu time (seconds) unlimited
> max user processes 2048
> virtual memory (kbytes) unlimited
>
> When trying to run the following program, ulimit
> works fine and the program do a segmentation fault:
>
> #include <unistd.h>
> #include <stdlib.h>
> main ()
> {
> char ent[1];
> char p[4*1024*1024];
> printf("Press Enter\n");
> gets(ent);
> }
>
> When trying to run a program with "malloc" memory
> allocation, there is no problem: limits from ulimit are
> inactives. After the "malloc" command I do a "memset"
> to use memory and check memory usage.
>
> #include <unistd.h>
> #include <stdlib.h>
> main ()
> {
> char ent[1];
> char *p;
> int i_len=1024*1024*200;
> p = malloc(i_len);
>
> if (p==NULL) {
> printf("Alloc Error\n"); }
> else {
> printf("Alloc OK\n");
> memset (p,0,i_len); }
>
> printf("Press Enter\n");
> gets(ent);
> free (p);
> }
>
> My box have 1gb RAM and linux can allocate 200Mb.
> I check memory usage with the "top" command:
>
> PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
> 1306 stp 1 0 200M 200M 300 S 0.0 19.5 0:00 tst
Might be that the memory isnt actually backed by physical memory yet..
Try looping through the array setting one byte at a time, and see
if/where it stops.
>
|
|
|
|
|