NAME

     chmem - change memory allocation


SYNOPSIS

     chmem [+] [-] [=] amount file


EXAMPLES

     chmem =50000 a.out  # Give a.out 50K of stack space

     chmem -4000 a.out   # Reduce the stack space by 4000 bytes

     chmem +1000 file1   # Increase each stack by 1000 bytes


DESCRIPTION

     When a program is loaded into memory, it is allocated enough
     memory  for the text and data+bss segments, plus an area for
     the stack.  Data segment growth using malloc , brk , or sbrk
     eats  up  stack space from the low end.  The amount of stack
     space to allocate is derived from a field in the  executable
     program's  file header.  If the combined stack and data seg-
     ment growth exceeds the stack space allocated,  the  program
     will be terminated.

     It is therefore important to set the amount of  stack  space
     carefully.   If  too  little  is  provided,  the program may
     crash.  If too much is provided, memory will be wasted,  and
     fewer  programs will be able to fit in memory and run simul-
     taneously.  MINIX 3 does not swap, so that  when  memory  is
     full,  subsequent  attempts to fork will fail.  The compiler
     sets the stack space to the largest possible value (for  the
     Intel  CPUs,  64K  -  text - data).  For many programs, this
     value is far too large.  Nonrecursive programs that  do  not
     call  brk  ,  sbrk  ,  or malloc , and do not have any local
     arrays usually do not need more than 8K of stack space.

     The chmem command changes the value of the header field that
     determines  the  stack  allocation,  and thus indirectly the
     total memory required to run the program.  The = option sets
     the  stack  size  to  a  specific value; the + and - options
     increment and decrement the current value by  the  indicated
     amount.  The old and new stack sizes are printed.


SEE ALSO

     install(1), brk(2).