Berkeley DB Reference Guide: Memory Pool Subsystem
Полезная информация

Berkeley DB Reference Guide: Memory Pool Subsystem

Berkeley DB and the memory pool

The memory pool subsystem is the general-purpose shared memory buffer pool used by Berkeley DB. This module is useful outside of the Berkeley DB package for processes that require page-oriented, cached, shared file access.

A memory pool is a shared memory cache shared by any number of processes and threads within processes. The memp_open interface opens, and optionally creates, a memory pool. When that pool is no longer in use, it should be closed, using the memp_close interface.

The memp_fopen interface opens an underlying file within the memory pool. When that file is no longer in use, it should be closed, using the memp_fclose interface. The memp_fget interface is used to retrieve pages from files in the pool. All retrieved pages must be subsequently returned using the memp_fput interface. At the time that pages are returned, they may be marked dirty, which causes them to be written to the backing disk file before being discarded from the pool. If there is insufficient room to bring a new page in the pool, a page is selected to be discarded from the pool. If that page is dirty, it is first written to the backing file. The page is selected using a somewhat modified least-recently-used algorithm. Pages in files may also be explicitly marked clean or dirty using the memp_fset interface. All dirty pages in the pool from any underlying file may also be flushed as a group using the memp_fsync interface.

There are additional interfaces for manipulating the entire memory pool:

It is possible to gradually flush buffers from the pool in order to maintain a consistent percentage of clean buffers in the pool using the memp_trickle interface.

The db_stat utility uses the memp_stat interface to display statistics about the efficiency of the pool.

As some conversion may be necessary when pages are read into, or written from, the pool, the memp_register function allows applications to specify automatic input and output processing in these cases.

There is one additional interface that is intended for manipulating the memory pool, but which is specific to database systems. The memp_sync interface flushes dirty pages from all files held in the pool up to the current database log sequence number.

Finally, the entire pool may be discarded using the memp_unlink interface.