1<!--$Id: intro.so,v 10.26 2007/04/05 20:54:56 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Introduction to the memory pool subsystem</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<a name="2"><!--meow--></a><a name="3"><!--meow--></a><a name="4"><!--meow--></a> 12<table width="100%"><tr valign=top> 13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Memory Pool Subsystem</dl></b></td> 14<td align=right><a href="/log/limits.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/mp/config.html"><img src="/images/next.gif" alt="Next"></a> 15</td></tr></table> 16<p align=center><b>Introduction to the memory pool subsystem</b></p> 17<p>The Memory Pool subsystem is the general-purpose shared memory buffer 18pool used by Berkeley DB. This module is useful outside of the Berkeley DB package 19for processes that require page-oriented, shared and cached file access.</p> 20<p>A <i>memory pool</i> is a memory cache shared among any number of 21threads of control. The <a href="/api_c/env_open.html#DB_INIT_MPOOL">DB_INIT_MPOOL</a> flag to the 22<a href="/api_c/env_open.html">DB_ENV->open</a> method opens and optionally creates a memory pool. When 23that pool is no longer in use, it should be closed using the 24<a href="/api_c/env_close.html">DB_ENV->close</a> method.</p> 25<p>The <a href="/api_c/memp_fcreate.html">DB_ENV->memp_fcreate</a> method returns a <a href="/api_c/mempfile_class.html">DB_MPOOLFILE</a> handle on an 26underlying file within the memory pool. The file may be opened using 27the <a href="/api_c/memp_fopen.html">DB_MPOOLFILE->open</a> method. The <a href="/api_c/memp_fget.html">DB_MPOOLFILE->get</a> method is used to retrieve 28pages from files in the pool. All retrieved pages must be subsequently 29returned using the <a href="/api_c/memp_fput.html">DB_MPOOLFILE->put</a> method. At the time pages are returned, 30they may be marked <b>dirty</b>, which causes them to be written to 31the underlying file before being discarded from the pool. If there is 32insufficient room to bring a new page in the pool, a page is selected 33to be discarded from the pool using a least-recently-used algorithm. 34All dirty pages in the pool from the file may be flushed using the 35<a href="/api_c/memp_fsync.html">DB_MPOOLFILE->sync</a> method. When the file handle is no longer in use, it 36should be closed using the <a href="/api_c/memp_fclose.html">DB_MPOOLFILE->close</a> method.</p> 37<p>There are additional configuration interfaces that apply when opening 38a new file in the memory pool:</p> 39<p><ul type=disc> 40<li>The <a href="/api_c/memp_set_clear_len.html">DB_MPOOLFILE->set_clear_len</a> method specifies the number of bytes to clear 41when creating a new page in the memory pool. 42<li>The <a href="/api_c/memp_set_fileid.html">DB_MPOOLFILE->set_fileid</a> method specifies a unique ID associated with the file. 43<li>The <a href="/api_c/memp_set_ftype.html">DB_MPOOLFILE->set_ftype</a> method specifies the type of file for the purposes of 44page input and output processing. 45<li>The <a href="/api_c/memp_set_lsn_offset.html">DB_MPOOLFILE->set_lsn_offset</a> method specifies the byte offset of each page's 46log sequence number (<a href="/api_c/lsn_class.html">DB_LSN</a>) for the purposes of transaction 47checkpoints. 48<li>The <a href="/api_c/memp_set_pgcookie.html">DB_MPOOLFILE->set_pgcookie</a> method specifies an application provided argument 49for the purposes of page input and output processing. 50</ul> 51<p>There are additional interfaces for the memory pool as a whole:</p> 52<p><ul type=disc> 53<li>It is possible to gradually flush buffers from the pool in order to 54maintain a consistent percentage of clean buffers in the pool using 55the <a href="/api_c/memp_trickle.html">DB_ENV->memp_trickle</a> method. 56<li>Because special-purpose processing may be necessary when pages are read 57or written (for example, endian conversion, or page checksums), the 58<a href="/api_c/memp_register.html">DB_ENV->memp_register</a> function allows applications to specify automatic 59input and output processing in these cases. 60<li>The <a href="/utility/db_stat.html">db_stat</a> utility uses the <a href="/api_c/memp_stat.html">DB_ENV->memp_stat</a> method to display 61statistics about the efficiency of the pool. 62<li>All dirty pages in the pool may be flushed using the <a href="/api_c/memp_sync.html">DB_ENV->memp_sync</a> method. 63In addition, <a href="/api_c/memp_sync.html">DB_ENV->memp_sync</a> takes an argument that is specific to 64database systems, and which allows the memory pool to be flushed up to 65a specified log sequence number (<a href="/api_c/lsn_class.html">DB_LSN</a>). 66<li>The entire pool may be discarded using the <a href="/api_c/env_remove.html">DB_ENV->remove</a> method. 67</ul> 68<!--$Id: m4.methods,v 1.11 2007/07/06 00:22:53 mjc Exp $--> 69<table border=1 align=center> 70<tr><th>Memory Pools and Related Methods</th><th>Description</th></tr> 71<!--Db::mpf--><tr><td><a href="/api_c/db_get_mpf.html">DB->get_mpf</a></td><td>Return <a href="/api_c/db_class.html">DB</a>'s underlying <a href="/api_c/mempfile_class.html">DB_MPOOLFILE</a> handle</td></tr> 72<!--DbEnv::memp_stat--><tr><td><a href="/api_c/memp_stat.html">DB_ENV->memp_stat</a></td><td>Return memory pool statistics</td></tr> 73<!--DbEnv::memp_sync--><tr><td><a href="/api_c/memp_sync.html">DB_ENV->memp_sync</a></td><td>Flush pages from a memory pool</td></tr> 74<!--DbEnv::memp_trickle--><tr><td><a href="/api_c/memp_trickle.html">DB_ENV->memp_trickle</a></td><td>Trickle flush pages from a memory pool</td></tr> 75<!--DbMemoryException--> 76<tr><th>Memory Pool Configuration</th><th><br></th></tr> 77<!--DbEnv::memp_register--><tr><td><a href="/api_c/memp_register.html">DB_ENV->memp_register</a></td><td>Register input/output functions for a file in a memory pool</td></tr> 78<!--DbEnv::set_cachesize--><tr><td><a href="/api_c/env_set_cachesize.html">DB_ENV->set_cachesize</a></td><td>Set the environment cache size</td></tr> 79<!--DbEnv::set_cache_max--><tr><td><a href="/api_c/env_set_cache_max.html">DB_ENV->set_cache_max</a></td><td>Set the maximum cache size</td></tr> 80<!--DbEnv::set_mp_max_openfd--><tr><td><a href="/api_c/memp_openfd.html">DB_ENV->set_mp_max_openfd</a></td><td>Set the maximum number of open file descriptors</td></tr> 81<!--DbEnv::set_mp_max_write--><tr><td><a href="/api_c/memp_maxwrite.html">DB_ENV->set_mp_max_write</a></td><td>Set the maximum number of sequential disk writes</td></tr> 82<!--DbEnv::set_mp_mmapsize--><tr><td><a href="/api_c/env_set_mp_mmapsize.html">DB_ENV->set_mp_mmapsize</a></td><td>Set maximum mapped-in database file size</td></tr> 83<tr><th>Memory Pool Files</th><th><br></th></tr> 84<!--DbEnv::memp_fcreate--><tr><td><a href="/api_c/memp_fcreate.html">DB_ENV->memp_fcreate</a></td><td>Create a memory pool file handle</td></tr> 85<!--DbMpoolFile::--> 86<!--DbMpoolFile::close--><tr><td><a href="/api_c/memp_fclose.html">DB_MPOOLFILE->close</a></td><td>Close a file in a memory pool</td></tr> 87<!--DbMpoolFile::get--><tr><td><a href="/api_c/memp_fget.html">DB_MPOOLFILE->get</a></td><td>Get page from a file in a memory pool</td></tr> 88<!--DbMpoolFile::open--><tr><td><a href="/api_c/memp_fopen.html">DB_MPOOLFILE->open</a></td><td>Open a file in a memory pool</td></tr> 89<!--DbMpoolFile::put--><tr><td><a href="/api_c/memp_fput.html">DB_MPOOLFILE->put</a></td><td>Return a page to a memory pool</td></tr> 90<!--DbMpoolFile::sync--><tr><td><a href="/api_c/memp_fsync.html">DB_MPOOLFILE->sync</a></td><td>Flush pages from a file in a memory pool</td></tr> 91<tr><th>Memory Pool File Configuration</th><th><br></th></tr> 92<!--DbMpoolFile::set_clear_len--><tr><td><a href="/api_c/memp_set_clear_len.html">DB_MPOOLFILE->set_clear_len</a></td><td>Set file page bytes to be cleared</td></tr> 93<!--DbMpoolFile::set_fileid--><tr><td><a href="/api_c/memp_set_fileid.html">DB_MPOOLFILE->set_fileid</a></td><td>Set file unique identifier</td></tr> 94<!--DbMpoolFile::set_flags--><tr><td><a href="/api_c/memp_set_flags.html">DB_MPOOLFILE->set_flags</a></td><td>General memory pool file configuration</td></tr> 95<!--DbMpoolFile::set_ftype--><tr><td><a href="/api_c/memp_set_ftype.html">DB_MPOOLFILE->set_ftype</a></td><td>Set file type</td></tr> 96<!--DbMpoolFile::set_lsn_offset--><tr><td><a href="/api_c/memp_set_lsn_offset.html">DB_MPOOLFILE->set_lsn_offset</a></td><td>Set file log-sequence-number offset</td></tr> 97<!--DbMpoolFile::set_maxsize--><tr><td><a href="/api_c/memp_set_maxsize.html">DB_MPOOLFILE->set_maxsize</a></td><td>Set maximum file size</td></tr> 98<!--DbMpoolFile::set_pgcookie--><tr><td><a href="/api_c/memp_set_pgcookie.html">DB_MPOOLFILE->set_pgcookie</a></td><td>Set file cookie for pgin/pgout</td></tr> 99<!--DbMpoolFile::set_priority--><tr><td><a href="/api_c/memp_set_priority.html">DB_MPOOLFILE->set_priority</a></td><td>Set memory pool file priority</td></tr> 100</table> 101<table width="100%"><tr><td><br></td><td align=right><a href="/log/limits.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/mp/config.html"><img src="/images/next.gif" alt="Next"></a> 102</td></tr></table> 103<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 104</body> 105</html> 106