home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / clipper / clsupbul.arj / WMMTXT.TXT < prev   
Encoding:
Text File  |  1992-06-01  |  18.6 KB  |  396 lines

  1. Clipper Support Bulletin #3
  2. Clipper 5.0 runtime memory management
  3.  
  4. Copyright (c) 1991, 1992 Nantucket Corporation.  All rights reserved.
  5.  
  6.  
  7. Version:  Clipper 5.0, revisions 1.00 - 1.03
  8. Date:     4th October, 1990
  9. Revised:  21st May, 1992
  10. Status:   Active
  11.  
  12. ================================================================================
  13.  
  14. This Support Bulletin covers the following topics:
  15.  
  16.    1. Virtual Memory Manager (VMM)
  17.        1.1  Use of Lim 3.2 Expanded Memory (EMM)
  18.        1.2  Disk Swapping
  19.        1.3  Swap Space
  20.    2. Object Memory (SVOS)
  21.    3. Dynamic Overlaying
  22.        3.1  Configuration
  23.    4. Data File Buffering
  24.    5. Segment Locking
  25.    6. Fixed-Memory Allocator
  26.    7. MEMVAR Tables
  27.    8. Symbol Tables
  28.    9. The Extend System
  29.        9.1  Configuration
  30.  
  31. Note: this document makes several references to the CLIPPER environment
  32. variable.  For general information on how to configure the runtime environment,
  33. refer to the Clipper 5.0 "Programming and Utilities Guide."
  34.  
  35. ================================================================================
  36. 1. Virtual Memory Manager (VMM)
  37.    
  38.    "Virtual memory" is a generic term for hardware or software
  39.    techniques that allow a limited amount of "real" memory to
  40.    emulate a much larger "virtual" memory.
  41.    
  42.    The Clipper 5.0 Virtual Memory Manager (VMM) is implemented in
  43.    software.  The system runs in real mode on any 8086-compatible
  44.    processor; it does not directly use the protected mode virtual
  45.    memory capabilities of the Intel 286 and 386 processors.
  46.    
  47.    The VMM is a "segmented" memory manager.  Virtual memory is
  48.    allocated in segments, each of which may contain from 1K to 64K
  49.    of data.  Initially, the VMM works somewhat like a normal memory
  50.    allocator (although it has an extra advantage: most VM segments
  51.    are movable; the VMM can reorganize them to get maximum
  52.    utilization of real memory).  Unlike a normal memory allocator,
  53.    however, the VMM does not "run out" when the available real
  54.    memory can no longer contain all of the allocated segments.
  55.    Instead, one or more of the least recently used (LRU) segments
  56.    are "swapped out" into secondary storage (or otherwise removed
  57.    from real memory, see below) to make room for new segments.
  58.    Later, if data in a swapped segment must be accessed, it is
  59.    swapped back in, displacing segments that are not currently
  60.    needed.
  61.    
  62.    The maximum virtual address space of the Clipper 5.0 VMM is
  63.    64MB.
  64.    
  65.    ----------------------------------------------------------------------------
  66.    1.1  Use of Lim 3.2 Expanded Memory (EMM)
  67.    
  68.    By default, the Clipper 5.0 VMM uses LIM 3.2 Expanded Memory
  69.    (EMM) as secondary storage.  EMM provides fast access to swapped
  70.    segments.  Up to 8MB of EMM can be used.
  71.    
  72.    Configuration
  73.    -------------
  74.    EMM usage can be controlled using the E setting in the CLIPPER
  75.    environment variable.  Valid settings are from 0 to 8192 (units
  76.    of 1K).  A setting of 0 disables the use of EMM altogether.
  77.    (Note: disabling EMM is not recommended under Clipper 5.0.
  78.    Although EMM is not required, it allows increased performance
  79.    for most applications.  In a few cases, limiting EMM usage may
  80.    be desirable--see the note below under Disk Buffering System.)
  81.    
  82.    Example:  SET CLIPPER=E2048
  83.    
  84.    Some disk caching programs use EMM to cache disk sectors.
  85.    Certain cache programs may cause conflicts with the Clipper 5.0
  86.    VMM system if they assume that application programs never use
  87.    EMM.  The BADCACHE setting in the CLIPPER environment variable
  88.    causes the VMM to preserve and restore the state of the EMM
  89.    "page frame" before and after every EMM access (the EMM page
  90.    frame is an area in real address space through which EMM data is
  91.    accessed).  This should make Clipper's use of EMM undetectable
  92.    to any other process using EMM.  (Note: on some EMM systems the
  93.    BADCACHE setting may adversely affect VMM performance.  It
  94.    should only be used if you experience disk or file corruption
  95.    because of a conflict with a disk cache or other resident
  96.    software.)
  97.    
  98.    Example:  SET CLIPPER=BADCACHE
  99.    
  100.    ----------------------------------------------------------------------------
  101.    1.2  Disk Swapping
  102.    
  103.    If insufficient EMM is available to contain swapped segments, a
  104.    temporary disk file (the "swap file") is created to hold them.
  105.    By default, the VMM will use a maximum of 8MB of disk space for
  106.    the swap file.  Disk space is used only as needed.
  107.    
  108.    Configuration
  109.    -------------
  110.    The maximum size of the disk swap file can be controlled using
  111.    the SWAPK setting in the CLIPPER environment variable.  Valid
  112.    settings are from 256 to 64000 (256K to 64MB).  The SWAPK
  113.    setting has no effect on VMM swapping activity; it merely serves
  114.    to establish an upper limit on the size of the swap file.  If
  115.    the limit is exceeded, the VMM will terminate the application.
  116.    
  117.    Example:  SET CLIPPER=SWAPK:16000
  118.    
  119.    The disk drive and directory where the VMM swap file is created
  120.    can be controlled using the SWAPPATH setting in the CLIPPER
  121.    environment variable.  By default, the swap file is created in
  122.    the current DOS directory.
  123.    
  124.    Example:  SET CLIPPER=SWAPPATH:"C:\SWAP"
  125.    
  126.    ----------------------------------------------------------------------------
  127.    1.3  Swap Space
  128.    
  129.    The term "swap space" refers to the region of real memory where
  130.    the VMM loads virtual memory segments.
  131.    
  132.    Configuration
  133.    -------------
  134.    The VMM allocates the swap space from DOS at startup.  By
  135.    default, all available DOS memory is used for swap space.  Real
  136.    memory usage can be restricted using the X setting of the
  137.    CLIPPER environment variable.  The setting specifies an amount
  138.    of DOS memory (in 1K units) which is to be excluded from the
  139.    VMM.  Valid settings are from 0 to 256.  The X setting is
  140.    provided as a way to reserve DOS memory for other uses (e.g.
  141.    allocation by memory-resident software).  In general, its use is
  142.    undesirable because limiting the swap space decreases VMM
  143.    performance.
  144.    
  145.    Example:  SET CLIPPER=X8
  146.    
  147. ========================================================================
  148. 2. Object Memory (SVOS)
  149.    
  150.    An "object memory" is a special type of memory manager designed to
  151.    manage complex data values such as character strings and arrays.
  152.    
  153.    The Clipper 5.0 object memory is called the Segmented Virtual
  154.    Object Store (SVOS).  SVOS uses virtual memory to store data
  155.    values, including character strings, arrays, and dynamically
  156.    created (macro-compiled) code blocks.
  157.    
  158.    SVOS provides two important functions beyond the basic
  159.    capabilities offered by the VMM:
  160.    
  161.    1. Memory compaction: stored values are automatically compacted on
  162.    an ongoing basis.  This eliminates fragmentation of the virtual
  163.    memory and reduces swapping.
  164.    
  165.    2. Garbage collection: Some Clipper 5.0 values (e.g. arrays) may
  166.    be referred to by several program variables (or array elements) at
  167.    the same time.  The garbage collection algorithms automatically
  168.    reclaim space occupied by "unreachable" values (values which are
  169.    no longer accessible through any variable or array).
  170.    
  171.    3. To minimize delays associated with memory compaction and
  172.    garbage collection, the SVOS algorithms are dynamically adjusted
  173.    based on the type, size, and persistence of data being stored, the
  174.    amount of memory available (real and EMM), and the overall
  175.    performance of the system.  The algorithms attempt to manage
  176.    memory in such a way that the VMM can swap out infrequently used
  177.    data, freeing up real address space for time-critical operations.
  178.    
  179.    The dynamic nature of the SVOS algorithms makes it difficult to
  180.    precisely state its maximum capacity.  The worst case capacity is
  181.    in excess of 1MB.  The theoretical maximum is in excess of 16MB.
  182.    
  183. ========================================================================
  184. 3. Dynamic Overlaying
  185.    
  186.    Clipper 5.0, using the supplied special version of .RTLink,
  187.    manages compiled Clipper code using a technique called dynamic
  188.    overlaying.  This technique eliminates the need for complicated
  189.    overlay structures and allows flexible runtime management of
  190.    compiled code.
  191.    
  192.    During linking, .RTLink breaks compiled Clipper modules into fixed-
  193.    size "pages."  These pages are stored either in the executable
  194.    file or in separate overlay files.  The paging architecture
  195.    eliminates restrictions and memory calculations based on the size
  196.    of compiled functions or modules.  Large modules are broken into
  197.    multiple pages; small functions are grouped together in a single
  198.    page.
  199.    
  200.    At execution time, the dynamic overlay manager loads pages based
  201.    on information embedded in the .EXE by the linker.  The dynamic
  202.    pages are loaded into VM segments, allowing the VMM to manage the
  203.    overlay pages on a competetive basis with other uses of memory.
  204.    The paging architecture allows the system to discard low-use
  205.    sections of code even if the code is associated with a pending
  206.    active function; overlays are not required to "nest" in parallel
  207.    with function activations.  Code pages that are being heavily used
  208.    are maintained in memory by the VMM's LRU swapping policy.
  209.    
  210.    When possible, the VMM will place dynamic overlay pages in EMM,
  211.    reducing overlay reads.  Overlay pages are never written to the
  212.    VMM disk swap file, however.  If a VM segment containing an
  213.    overlay page is to be removed from memory altogether, it is simply
  214.    discarded.  If it is needed subsequently, it is re-read from the
  215.    overlay file.
  216.    
  217.    ----------------------------------------------------------------------------
  218.    3.1  Configuration
  219.    
  220.    In addition to virtual memory, the dynamic overlay manager uses a
  221.    dedicated area of real memory to cache the most active dynamic
  222.    overlay pages.  The default size of this area ranges from 4K to
  223.    16K, depending on the amount of real memory available at startup.
  224.    For low memory situations, the size of this area can be restricted
  225.    using the DYNK setting of the CLIPPER environment variable.  Valid
  226.    values are from 4 to 63.  (Note: restricting the size of this area
  227.    may reduce execution speed.)
  228.    
  229.    Example:  SET CLIPPER=DYNK:4
  230.    
  231.    The dynamic overlay manager will hold overlay pages in virtual
  232.    memory only as long as it can maintain an active file handle for
  233.    the disk file containing the pages.  If the file is closed, the
  234.    pages are discarded from virtual memory.  The maximum number of
  235.    file handles used by the dynamic overlay manager can be controlled
  236.    using the DYNF setting of the CLIPPER environment variable.  Valid
  237.    settings are from 1 to 8.  The default setting is 2.  For
  238.    applications which use many separate overlay files, increasing
  239.    this setting can improve performance.
  240.    
  241.    Example:  SET CLIPPER=DYNF:4
  242.    
  243. ========================================================================
  244. 4. Data File Buffering
  245.    
  246.    The Clipper 5.0 database drivers use virtual memory segments to
  247.    contain database and index file buffers.  This allows the VMM to
  248.    manage these buffers on a competetive basis with other uses of
  249.    memory.  As with dynamic overlay segments, the VMM will swap
  250.    buffer segments into EMM but not to the disk swap file.  If a VM
  251.    segment containing a disk buffer is to be removed from memory
  252.    altogether, it is written back to the appropriate data file.
  253.    
  254.    The file buffering system allocates buffer management tables in
  255.    fixed memory (see FIXED MEMORY ALLOCATOR below).  The actual
  256.    amount used depends on the combined total of real memory and EMM
  257.    available at startup.  The tables use 14 bytes per 1K of real or
  258.    Expanded memory (the tables never exceed 8K, however).  Because
  259.    these tables are allocated in fixed memory, they have an effect on
  260.    the amount of swap space available to the VMM.  In some low-memory
  261.    situations, reducing the amount of available EMM may help to avoid
  262.    "swap space exhausted" errors. (Note: reducing EMM availability
  263.    may seriously degrade VMM performance in very low memory
  264.    situations due to increased disk swapping--see Use of Lim 3.2
  265.    Expanded Memory above.)
  266.    
  267. ========================================================================
  268. 5. Segment Locking
  269.    
  270.    From time to time, certain VM segments are "locked" by a
  271.    subsystem.  This prevents the VMM from moving or swapping those
  272.    segments until the subsystem unlocks them.  This capability is
  273.    used sparingly to keep the swap space from becoming cluttered with
  274.    locked segments.
  275.    
  276. ========================================================================
  277. 6. Fixed-Memory Allocator
  278.    
  279.    Clipper 5.0 subsystems use virtual memory to contain code or data
  280.    that needs to be dynamically managed.  Some allocations are not
  281.    appropriate for VM (e.g. system tables which must remain in the
  282.    same location throughout execution).  A C-style fixed memory
  283.    allocator is included for this purpose.  The fixed memory system
  284.    allocates one or more VM segments and permanently locks them in
  285.    real memory.  Space within these segments is then parceled out as
  286.    needed.  Since fixed segments are never unlocked, the VMM locates
  287.    them at the low end of the swap space to prevent them from
  288.    interfering with other operations.
  289.    
  290. ========================================================================
  291. 7. MEMVAR Tables
  292.    
  293.    Clipper 5.0 offers several different storage classes for program
  294.    variables.  Local and static variables are stored in a dedicated
  295.    area of real memory.  Private and public (MEMVAR) variables are
  296.    stored in VM segments.
  297.    
  298.    Since MEMVAR variables are created and destroyed dynamically
  299.    during execution, the associated VM segments grow dynamically
  300.    depending on how many MEMVAR variables are in use.  For
  301.    performance reasons, these segments remain locked during most
  302.    operations (they are unlocked during RUN commands and certain
  303.    other memory intensive operations).  In low memory situations, the
  304.    MEMVAR tables may have a significant effect on the amount of
  305.    available swap space (each MEMVAR variable uses 20 bytes in the
  306.    MEMVAR segments, which grow in increments of 1K or more).
  307.    
  308.    MEMVAR variables also require symbol information to be maintained
  309.    at runtime (see below).  Converting private and public variables
  310.    to local and static variables may reduce memory requirements for
  311.    some applications.
  312.    
  313. ========================================================================
  314. 8. Symbol Tables
  315.    
  316.    Clipper maintains symbol information at runtime in order to
  317.    support symbolic references to variables and functions.  Some
  318.    symbol information is embedded in the .EXE file (the Clipper 5.0
  319.    version of .RTLink eliminates duplication among symbols from
  320.    compiled Clipper modules).  Other symbols are created dynamically
  321.    at runtime.
  322.    
  323.    Memory for symbol tables and related information is allocated
  324.    using the fixed-memory allocator.  The symbols are allocated in
  325.    blocks and do not fragment memory.  However, excessive dynamic
  326.    symbol creation (e.g. large numbers of MEMVAR variables created
  327.    via macros) may cause the symbol tables to grow, reducing swap
  328.    space.
  329.    
  330. ========================================================================
  331. 9. The Extend System
  332.    
  333.    The Extend system is a set of functions that are used by C and
  334.    assembly language programs to interface with Clipper programs.
  335.    The Extend system includes two memory allocation functions,
  336.    _xalloc() and _xgrab(), which allow C programs to allocate memory
  337.    from Clipper.  These functions call the fixed-memory allocator
  338.    (see above).
  339.    
  340.    The Extend system also allows C programs to gain access to Clipper
  341.    data values.  The Extend system _parc() function, used to inspect
  342.    character values passed from Clipper, is defined as returning an
  343.    address in real memory.  Since character values are stored in
  344.    virtual memory under SVOS (see above), the Extend system
  345.    automatically locks the appropriate VM segments in response to
  346.    _parc() requests.  The segments are automatically unlocked when
  347.    the C function returns control to Clipper (they may also be
  348.    unlocked manually from C, see below).
  349.    
  350.    A conflict can occur if a C function locks a VM segment via
  351.    _parc() and then attempts to allocate a large amount of memory
  352.    using the Extend allocators.  If the segment is locked near the
  353.    low end of the swap space, the fixed allocator may be unable to
  354.    lock or expand a fixed segment to satisfy the allocation request.
  355.    If this occurs, a new fixed segment is created and locked higher
  356.    in memory.  This reduces memory efficiency because the VMM is not
  357.    allowed to move fixed segments (in severe cases, the VMM may issue
  358.    a "swap space exhausted" error because the swap space has become
  359.    too cluttered with fixed segments).  To prevent this, the VMM
  360.    maintains a "safety zone" at the low end of the swap space.
  361.    _parc() requests are prevented from locking segments within this
  362.    zone.
  363.    
  364.    ----------------------------------------------------------------------------
  365.    9.1  Configuration
  366.    
  367.    The size of the Extend "safety zone" can be adjusted using the
  368.    EXTHEAP setting of the CLIPPER environment variable.  The default
  369.    setting is 8K.  Valid settings are from 2 to 256 (units of 1K).
  370.    Increasing the safety zone allows C programs to allocate large
  371.    amounts of memory without creating "holes" in the swap space.
  372.    (Note: the default EXTHEAP setting should be sufficient for most
  373.    applications; increasing the value too much may cause the VMM to
  374.    fail when trying to lock a segment in response to a _parc()
  375.    request.)
  376.    
  377.    ----------------------------------------------------------------------------
  378.    9.2  New Extend Function
  379.    
  380.    The Clipper 5.0 VMM defines an entry point called _xunlock().
  381.    This function can be called from C or assembly language programs
  382.    to unlock SVOS segments when large amounts of memory are to be
  383.    allocated after _parc() has been called.  CAUTION: calling
  384.    _xunlock() causes any pointers returned from previous _parc()
  385.    calls to become invalid.  To access a Clipper character value
  386.    after calling _xunlock(), you must make another call to _parc() to
  387.    get a new pointer.
  388.    
  389.    Nantucket will be publishing an API (Application Program
  390.    Interface) for the Clipper 5.0 VMM so that C and Assembly language
  391.    programs can allocate virtual memory directly, reducing demands on
  392.    swap space.
  393.    
  394.  
  395.                               *  *  *
  396.