Consultor Eletrônico



Kbase 15018: Detailed description of -hs Heap option on Unix
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
Detailed description of -hs Heap option on Unix

INTRODUCTION:
=============

The -hs Heap Size startup option. (Single user or Server option.)

This parameter controls how much *extra* Progress should expand the
heap allocated to a process. This option was implemented to allow
end users to influence how the operating system allocates
shared-memory areas within the address space of a Unix process.


DESCRIPTION:
============

The heap is a pool of memory that is used to allocate and free
data structures at run time. The library functions that use this
area of memory are called malloc() and free(). Nearly all C
programs use them explicitly and the C runtime library uses them
extensively also.

Memory allocated to a process is composed of several different
segments, depending on contents and usage. Some of these areas are
allocated statically, by the linker and others dynamically at
execution time.

Below is a possible arrangement for how these areas could be
arrange within a process's 4GB virtual address space.

Lowest possible address
Nothing in the very first page
Text segment (contains code)
Initialized static data
Uninitialized static data
Heap
Nothing
Shared-memory segments (attached at run time)
Nothing
Dynamically linked text (shared libraries, attached at run time)
Stack (grows toward heap at run time)
Command line parameters
Highest possible address


Notice that the heap, stack, shared libraries, and shared-memory
segments can all vary in size depending on what the program does
when it executes. So there is the problem of where in the
process's virtual address space to put all these things. Once you
map a shared memory segment to some address, the heap cannot grow
past it. A smart operating system might be able to fragment the
heap and put some of it below shared memory and some above. Not all
are smart and that only solves part of the problem. The stack could
run into something as well.

Ok, so what does -hs do? Well if you specify -hs 1024, we will
allocate and then free and extra 1024*1024 bytes of memory at
startup. This will cause the heap to expand to at least 1 MB of
free space. Shared memory will then be attached high enough so it
won't get in the way later when we try to malloc() memory for
something.

The initial heap size does not matter much, since it expands as
needed. So it starts out at zero or possibly a very small size,
like 4096 bytes, but as soon as the program starts executing, it
will allocate memory for various things (file control blocks, exit
handlers, all sorts of things) and the heap will expand.

To further complicate things, the order in which the segments are
laid out in memory is not the same on all Unix versions. Also,
there may be other segment types in some systems.


REFERENCES TO WRITTEN DOCUMENTATION:
====================================

Version 6: System Administration II: General
Chapter 3, Startup Options, -hs Heap Size

Version 7: System Administration Reference
Chapter 3, Startup Parameters, -hs Heap Size

Progress Software Technical Support Note # 15018