Ravenbrook / Projects / Memory Pool System / Master Product Sources / Design Documents

Memory Pool System Project


                 THE DESIGN OF THE LOW-MEMORY RESERVOIR
                          design.mps.reservoir
                           incomplete design
                            tony 1998-07-30


INTRODUCTION:

The low-memory reservoir provides client support for implementing handlers for 
low-memory situations which allocate.  The reservoir is implemented inside the 
arena as a pool of unallocatable segments.


OVERVIEW:

This is just a placeholder at the moment.


ARCHITECTURE:

.adt: The reservoir interface looks (almost) like an abstract data type of type 
Reservoir.  It's not quite abstract because the arena embeds the structure of 
the reservoir (of type ReservoirStruct) into its own structure, for simplicity 
of initialization.

.align: The reservoir is implemented as a pool of available tracts, along with 
a size and limit which must always be aligned to the arena alignment.  The size 
corresponds to the amount of memory currently maintained in the reservoir.  The 
limit is the maximum amount that it is desired to maintain.

.wastage: When the reservoir limit is set by the client, the actual limit 
should be increased by an arena alignment amount for every active mutator 
buffer.

.really-empty: When the reservoir limit is set to 0, assume that the client 
really doesn't have a need for a reservoir at all.  In this case, the client 
won't even want an allowance to be made for wastage in active buffers.


IMPLEMENTATION:

.interface: The following functions comprise the interface to the reservoir 
module:


.interface.check: ReservoirCheck checks the reservoir for consistency:
extern Bool ReservoirCheck(Reservoir reservoir);

.interface.init: ReservoirInit initializes the reservoir and its associated 
pool, setting the size and limit to 0:
extern Res ReservoirInit(Reservoir reservoir, Arena arena);

.interface.finish: ReservoirFinish de-initializes the reservoir and its 
associated pool:
extern void ReservoirFinish (Reservoir reservoir);

.interface.limit: ReservoirLimit returns the limit of the reservoir:
extern Size ReservoirLimit(Reservoir reservoir);

.interface.set-limit: ReservoirSetLimit sets the limit of the reservoir, making 
an allowance for wastage in mutator buffers:
extern void ReservoirSetLimit(Reservoir reservoir, Size size);

.interface.available: ReservoirAvailable returns the available size of the 
reservoir:
extern Size ReservoirAvailable(Reservoir reservoir);

.interface.ensure-full: ReservoirEnsureFull attempts to fill the reservoir with 
memory from the arena, until it is full:
extern Res ReservoirEnsureFull(Reservoir reservoir);

.interface.deposit: ReservoirDeposit attempts to fill the reservoir with memory 
in the supplied range, until it is full.  This is called by the arena from 
ArenaFree if the reservoir is not known to be full.  Any memory which is not 
added to the reservoir (because the reservoir is full) is freed via the arena 
class's free method.
extern void ReservoirDeposit(Reservoir reservoir, Addr base, Size size);

.interface.withdraw: ReservoirWithdraw attempts to allocate memory of the 
specified size to the specified pool to the reservoir.  If no suitable memory 
can be found it returns ResMEMORY. 
extern Res ReservoirWithdraw(Addr *baseReturn, Tract *baseTractReturn,
                             Reservoir reservoir, Size size, Pool pool);

.interface.withdraw.align: Currently, ReservoirWithdraw can only withdraw 
memory in chunks of the size of the arena alignment.  This is because the 
reservoir doesn't attempt to coalesce adjacent memory blocks.  This deficiency 
should be fixed in the future.

.pool: The memory managed by the reservoir is owned by the reservoir pool.  
This memory is never sub-allocated.  Each tract belonging to the pool is linked 
onto a list.  The head of the list is in the Reservoir object.  Links are 
stored in the TractP fields of each tract object.


A. References

B. Document History

2002-06-07 RB Converted from MMInfo database design document.

C. Copyright and License

This document is copyright © 1995-2002 Ravenbrook Limited. All rights reserved. This is an open source license. Contact Ravenbrook for commercial licensing options.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Redistributions in any form must be accompanied by information on how to obtain complete source code for the this software and any accompanying software that uses this software. The source code must either be included in the distribution or be available for no more than the cost of distribution plus a nominal fee, and must be freely redistributable under reasonable conditions. For an executable file, complete source code means the source code for all modules it contains. It does not include source code for modules or files that typically accompany the major components of the operating system on which the executable file runs.

This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement, are disclaimed. In no event shall the copyright holders and contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.


$Id: //info.ravenbrook.com/project/mps/version/1.105/design/reservoir/index.html#1 $

Ravenbrook / Projects / Memory Pool System / Master Product Sources / Design Documents