[9] | 1 | .TH CHMEM 1
|
---|
| 2 | .SH NAME
|
---|
| 3 | chmem \- change memory allocation
|
---|
| 4 | .SH SYNOPSIS
|
---|
| 5 | \fBchmem\fR [\fB+\fR]\fR [\fB\-\fR] [\fB=\fR] \fIamount file\fR
|
---|
| 6 | .br
|
---|
| 7 | .de FL
|
---|
| 8 | .TP
|
---|
| 9 | \\fB\\$1\\fR
|
---|
| 10 | \\$2
|
---|
| 11 | ..
|
---|
| 12 | .de EX
|
---|
| 13 | .TP 20
|
---|
| 14 | \\fB\\$1\\fR
|
---|
| 15 | # \\$2
|
---|
| 16 | ..
|
---|
| 17 | .SH EXAMPLES
|
---|
| 18 | .EX "chmem =50000 a.out" "Give \fIa.out\fP 50K of stack space"
|
---|
| 19 | .EX "chmem \-4000 a.out" "Reduce the stack space by 4000 bytes"
|
---|
| 20 | .EX "chmem +1000 file1" "Increase each stack by 1000 bytes"
|
---|
| 21 | .SH DESCRIPTION
|
---|
| 22 | .PP
|
---|
| 23 | When a program is loaded into memory, it is allocated enough memory
|
---|
| 24 | for the text and data+bss segments, plus
|
---|
| 25 | an area for the stack.
|
---|
| 26 | Data segment growth using
|
---|
| 27 | .I malloc ,
|
---|
| 28 | .I brk ,
|
---|
| 29 | or
|
---|
| 30 | .I sbrk
|
---|
| 31 | eats up stack space from the low end.
|
---|
| 32 | The amount of stack space to allocate is derived
|
---|
| 33 | from a field in the executable program's file header.
|
---|
| 34 | If the combined stack and data segment growth exceeds the stack space
|
---|
| 35 | allocated, the program will be terminated.
|
---|
| 36 | .PP
|
---|
| 37 | It is therefore important to set the amount of stack space carefully.
|
---|
| 38 | If too little is provided, the program may crash.
|
---|
| 39 | If too much is provided, memory will be wasted, and fewer programs will be able
|
---|
| 40 | to fit in memory and run simultaneously.
|
---|
| 41 | \s-1MINIX 3\s-1
|
---|
| 42 | does not swap, so that when memory is full, subsequent attempts to fork will
|
---|
| 43 | fail.
|
---|
| 44 | The compiler sets the stack space
|
---|
| 45 | to the largest possible value (for the Intel CPUs, 64K \- text \- data).
|
---|
| 46 | For many programs, this value is far too large.
|
---|
| 47 | Nonrecursive programs that do not call
|
---|
| 48 | .I brk ,
|
---|
| 49 | .I sbrk ,
|
---|
| 50 | or
|
---|
| 51 | .I malloc ,
|
---|
| 52 | and do not have any local arrays usually do not need more than 8K of stack
|
---|
| 53 | space.
|
---|
| 54 | .PP
|
---|
| 55 | The
|
---|
| 56 | .I chmem
|
---|
| 57 | command changes the value of the header field that determines the stack allocation, and
|
---|
| 58 | thus indirectly the total memory required to run the program.
|
---|
| 59 | The = option sets the stack size
|
---|
| 60 | to a specific value; the + and \- options increment and decrement the
|
---|
| 61 | current value by the indicated amount.
|
---|
| 62 | The old and new stack sizes are printed.
|
---|
| 63 | .SH "SEE ALSO"
|
---|
| 64 | .BR install (1),
|
---|
| 65 | .BR brk (2).
|
---|