---
name: "DbMpoolFile"
section: "3db"
platform: "linux"
package: "libdb2++-dev"
version: "2.4.14-1"
release: "Debian 2.1 (Slink)"
platforms: ["linux"]
url: "https://new.carta.tech/DbMpoolFile"
---

# DbMpoolFile(3db)

shared memory buffer pool

## NAME

DbMpoolFile - shared memory buffer pool

## SYNOPSIS

```
#include <db2/db_cxx.h>
static int
DbMpoolFile::open(DbMpool *mp, char *file, u_int32_t flags, int mode,
size_t pagesize, DbMpoolFinfo *finfop, DbMpoolFile **mpf);
int
DbMpoolFile::close();
int
DbMpoolFile::get(db_pgno_t *pgnoaddr, u_int32_t flags, void **pagep);
int
DbMpoolFile::put(void *pgaddr, u_int32_t flags);
int
DbMpoolFile::set(void *pgaddr, u_int32_t flags);
int
DbMpoolFile::sync();
```

## DESCRIPTION

The DB library is a family of classes that provides a modular programming interface to transactions and record-oriented file access. The library includes support for transactions, locking, logging and file page caching, as well as various indexed access methods. Many of the classes (e.g., the file page caching class) are useful independent of the other DB classes, although some classes are explicitly based on other classes (e.g., transactions and logging). For a general description of the DB package, see *db\_intro*(3).

This manual page describes the specific details of the per-file memory pool interface.

The *DbMpool*(3) and *DbMpoolFile*(3) classes are the library interface intended to provide general-purpose, page-oriented buffer management of one or more files. While designed to work with the other Db functions, these functions are also useful for more general purposes. The memory pools (*DbMpool::*'s) are referred to in this document as simply \`\`pools''. Pools may be shared between processes. Pools are usually filled by pages from one or more files (*DbMpoolFile*'s). Pages in the pool are replaced in LRU (least-recently-used) order, with each new page replacing the page that has been unused the longest. Pages retrieved from the pool using *DbMpoolFile::get* are \`\`pinned'' in the pool, by default, until they are returned to the pool's control using the *DbMpoolFile::put* method.

*DbMpoolFile::open* The *DbMpoolFile::open* method opens a file in the pool specified by the *DbMpool* argument, copying the DbMpoolFile pointer representing it into the memory location referenced by *mpf*.

The *file* argument is the name of the file to be opened. If *file* is NULL, a private file is created that cannot be shared with any other process (although it may be shared with other threads).

The *flags* and *mode* arguments specify how files will be opened and/or created when they don't already exist. The flags value is specified by **or**'ing together one or more of the following values:

- DB\_CREATE

  Create any underlying files, as necessary. If the files do not already exist and the DB\_CREATE flag is not specified, the call will fail.

-

  - DB\_NOMMAP

  Always copy this file into the local cache instead of mapping it into process memory (see the description of the *mp\_mmapsize* field of the DbEnv object for further information).

-

  - DB\_RDONLY

  Open any underlying files for reading only. Any attempt to write the file using the pool functions will fail, regardless of the actual permissions of the file.

All files created by the method *DbMpoolFile::open* are created with mode *mode* (as described in [*chmod*(2)](/chmod/2.md)) and modified by the process' umask value at the time of creation (see [*umask*(2)](/umask/2.md)). The group ownership of created files is based on the system and directory defaults, and is not further specified by DB.

The *pagesize* argument is the size, in bytes, of the unit of transfer between the application and the pool, although it is not necessarily the unit of transfer between the pool and the source file.

Files opened in the pool may be further configured based on the *finfop* argument to *memp\_fopen*, which is a pointer to a structure of type DB\_MPOOL\_FINFO (typedef'd in \<db2/db.h\>). No references to the *finfop* structure are maintained by DB, so it may be discarded when the *memp\_fopen* function returns. In order to ensure compatibility with future releases of DB, all fields of the DB\_MPOOL\_FINFO structure that are not explicitly set should be initialized to 0 before the first time the structure is used. Do this by declaring the structure external or static, or by calling the C library routine [*bzero*(3)](/bzero/3.md) or [*memset*(3)](/memset/3.md).

The fields of the DB\_MPOOL\_FINFO structure used by *DbMpoolFile::open* are described  below. If *finfop* is NULL or any of its fields are set to their default value, defaults appropriate for the system are used.

- int ftype;

  The *ftype* field should be the same as a *ftype* argument previously specified to the *DbMpool::db\_register* method, unless no input or output processing of the file's pages are necessary, in which case it should be 0. (See the description of the *DbMpool::db\_register* method for more information.)

- DBT \*pgcookie;

  The *pgcookie* argument contains the byte string that is passed to the *pgin* and *pgout* functions for this file, if any. If no *pgin* or *pgout* functions are specified, the *pgcookie* field should be NULL. (See the description of the *DbMpool::db\_register* method for more information.)

- u\_int8\_t \*fileid;

  The *fileid* field is a unique identifier for the file. The mpool functions must be able to uniquely identify files in order that multiple processes sharing a file will correctly share its underlying pages. Normally, the *fileid* field should be NULL and the mpool functions will use the file's device and inode numbers (see [*stat*(2)](/stat/2.md)) for this purpose. On some filesystems, (e.g., FAT or NFS) file device and inode numbers are not necessarily unique across system reboots. **Applications wanting to maintain a shared memory buffer pool across system** **reboots, where the pool contains pages from files stored on such filesystems,** **must specify a unique file identifier to the** *DbMpoolFile::open* **call and each process opening or registering the file must provide the same** **unique identifier.** If the *fileid* field is non-NULL, it must reference a DB\_FILE\_ID\_LEN (as defined in \<db2/db\_cxx.h\>) length array of bytes that will be used to uniquely identify the file. This should not be necessary for most applications. Specifically, it is not necessary if the memory pool is re-instantiated after each system reboot, the application is using the Db access methods instead of calling the pool functions explicitly, or the files in the memory pool are stored on filesystems where the file device and inode numbers do not change across system reboots.

- int32\_t lsn\_offset;

  The *lsn\_offset* argument is the zero-based byte offset in the page of the page's log sequence number (LSN), or -1 if no LSN offset is specified. (See the description of the *DbMpool::sync* method for more information.)

- u\_int32\_t clear\_len;

  The *clear\_len* field is the number of initial bytes in a page that should be set to zero when the page is created as a result of the DB\_MPOOL\_CREATE or DB\_MPOOL\_NEW flags being specified to *DbMpoolFile::get*. If *finfop* is NULL or *clear\_len* is 0, the entire page is cleared.

The *DbMpoolFile::open* method throws a *DbException*(3) or returns the value of *errno* on failure and 0 on success.

*DbMpoolFile::close* The *DbMpoolFile::close* method closes the source file indicated by the DbMpoolFile object. This method does not imply a call to *DbMpoolFile::sync*, i.e. no pages are written to the source file as as a result of calling *DbMpoolFile::close*.

In addition, if the *file* argument to *DbMpoolFile::open* was NULL, any underlying files created for this DbMpoolFile will be removed.

The *DbMpoolFile::close* method throws a *DbException*(3) or returns the value of *errno* on failure and 0 on success.

*DbMpoolFile::get* The *DbMpoolFile::get* method copies a pointer to the page with the page number specified by *pgnoaddr*, from the source file specified by the DbMpoolFile object into the memory location referenced by *pagep*. If the page does not exist or cannot be retrieved, *DbMpoolFile::get* will fail.

The returned page is size\_t type aligned.

**Page numbers begin at 0, e.g., the first page in the file is page number 0,** **not page number 1.**

The *flags* argument is specified by **or**'ing together one or more of the following values:

-

  - DB\_MPOOL\_CREATE

  If the specified page does not exist, create it. In this case, the *pgin* method, if specified, is called.

-

  - DB\_MPOOL\_LAST

  Return the last page of the source file and copy its page number to the location referenced by *pgnoaddr*.

-

  - DB\_MPOOL\_NEW

  Create a new page in the file and copy its page number to the location referenced by *pgnoaddr*. In this case, the *pgin* method, if specified, is not called.

The DB\_MPOOL\_CREATE, DB\_MPOOL\_LAST and DB\_MPOOL\_NEW flags are mutually exclusive.

Created pages have all their bytes set to 0, unless otherwise specified when the file was opened.

All pages returned by *DbMpoolFile::get* will be retained (i.e. \`\`pinned'') in the pool until a subsequent call to *DbMpoolFile::put*.

The *DbMpoolFile::get* method throws a *DbException*(3) or returns the value of *errno* on failure and 0 on success.

*DbMpoolFile::put* The *DbMpoolFile::put* method indicates that the page referenced by *pgaddr* can be evicted from the pool. *Pgaddr* must be an address previously returned by *DbMpoolFile::get*.

The *flags* argument is specified by **or**'ing together one or more of the following values:

-

  - DB\_MPOOL\_CLEAN

  Clear any previously set modification information (i.e., don't bother writing the page back to the source file).

-

  - DB\_MPOOL\_DIRTY

  The page has been modified and must be written to the source file before being evicted from the pool.

-

  - DB\_MPOOL\_DISCARD

  The page is unlikely to be useful in the near future, and should be discarded before other pages in the pool.

The DB\_MPOOL\_CLEAN and DB\_MPOOL\_DIRTY flags are mutually exclusive.

The *DbMpoolFile::put* method throws a *DbException*(3) or returns the value of *errno* on failure and 0 on success.

*DbMpoolFile::set* The *DbMpoolFile::set* method sets the flags associated with the page referenced by *pgaddr* without unpinning it from the pool. *Pgaddr* must be an address previously returned by *DbMpoolFile::get*. The *flags* argument to *DbMpoolFile::set* is specified by **or**'ing together one or more of the values specified as flags for the *DbMpoolFile::put* call.

The *DbMpoolFile::set* method throws a *DbException*(3) or returns the value of *errno* on failure and 0 on success.

*DbMpoolFile::sync* The *DbMpoolFile::sync* method writes all pages associated with the DbMpoolFile object that were marked as modified using *DbMpoolFile::put* or *DbMpoolFile::set*, back to the source file. If any of the modified pages are also pinned (i.e., currently referenced by this or another process) *DbMpoolFile::sync* will ignore them.

The *DbMpoolFile::sync* method throws a *DbException*(3) or returns the value of *errno* on failure, 0 on success, and DB\_INCOMPLETE if there were pages which were modified but which *DbMpoolFile::sync* was unable to write.

## ERRORS

Methods marked as returning *errno* will, by default, throw an exception that encapsulates the error information. The default error behavior can be changed, see *DbException*(3).

The *DbMpoolFile::open* method may fail and throw a *DbException*(3) or return *errno* for any of the errors specified for the following DB and library functions: DBmemp-\>pgin(3),  DBmemp-\>pgout(3),  DbLog::compare(3),  DbLog::flush(3),  [close(2)](/close/2.md),  [fcntl(2)](/fcntl/2.md),  [fflush(3)](/fflush/3.md),  [fsync(2)](/fsync/2.md),  [lseek(2)](/lseek/2.md),  [malloc(3)](/malloc/3.md),  [memcmp(3)](/memcmp/3.md),  [memcpy(3)](/memcpy/3.md),  [memset(3)](/memset/3.md),  [mmap(2)](/mmap/2.md),  [open(2)](/open/2.md),  [sigfillset(3)](/sigfillset/3.md),  [sigprocmask(2)](/sigprocmask/2.md),  [stat(2)](/stat/2.md),  [strcpy(3)](/strcpy/3.md),  [strdup(3)](/strdup/3.md),  [strerror(3)](/strerror/3.md),  [strlen(3)](/strlen/3.md),  [time(3)](/time/3.md),  [unlink(2)](/unlink/2.md),  and [write(2)](/write/2.md).

In addition, the *DbMpoolFile::open* method may fail and throw a *DbException*(3) or return *errno* for the following conditions:

- \[EINVAL\]

  An invalid flag value or parameter was specified.

  The file has already been entered into the pool, and the *pagesize* value is not the same as when the file was entered into the pool, or the length of the file is not zero or a multiple of the *pagesize*.

  The DB\_RDONLY flag was specified for an in-memory pool.

The *DbMpoolFile::close* method may fail and throw a *DbException*(3) or return *errno* for any of the errors specified for the following DB and library functions: [close(2)](/close/2.md),  [fcntl(2)](/fcntl/2.md),  [fflush(3)](/fflush/3.md),  [munmap(2)](/munmap/2.md),  and [strerror(3)](/strerror/3.md).

The *DbMpoolFile::get* method may fail and throw a *DbException*(3) or return *errno* for any of the errors specified for the following DB and library functions: DBmemp-\>pgin(3),  DBmemp-\>pgout(3),  DbLog::compare(3),  DbLog::flush(3),  [close(2)](/close/2.md),  [fcntl(2)](/fcntl/2.md),  [fflush(3)](/fflush/3.md),  [fsync(2)](/fsync/2.md),  [lseek(2)](/lseek/2.md),  [malloc(3)](/malloc/3.md),  [memcmp(3)](/memcmp/3.md),  [memcpy(3)](/memcpy/3.md),  [memset(3)](/memset/3.md),  [mmap(2)](/mmap/2.md),  [open(2)](/open/2.md),  [read(2)](/read/2.md),  [sigfillset(3)](/sigfillset/3.md),  [sigprocmask(2)](/sigprocmask/2.md),  [stat(2)](/stat/2.md),  [strcpy(3)](/strcpy/3.md),  [strdup(3)](/strdup/3.md),  [strerror(3)](/strerror/3.md),  [strlen(3)](/strlen/3.md),  [time(3)](/time/3.md),  [unlink(2)](/unlink/2.md),  and [write(2)](/write/2.md).

In addition, the *DbMpoolFile::get* method may fail and throw a *DbException*(3) or return *errno* for the following conditions:

- \[EAGAIN\]

  The page reference count has overflowed. (This should never happen unless there's a bug in the application.)

- \[EINVAL\]

  An invalid flag value or parameter was specified.

  The DB\_MPOOL\_NEW flag was set and the source file was not opened for writing.

  The requested page does not exist and DB\_MPOOL\_CREATE was not set.

  More than one of DB\_MPOOL\_CREATE, DB\_MPOOL\_LAST and DB\_MPOOL\_NEW was set.

- \[ENOMEM\]

  The cache is full and no more pages will fit in the pool.

The *DbMpoolFile::put* method may fail and throw a *DbException*(3) or return *errno* for any of the errors specified for the following DB and library functions: DBmemp-\>pgin(3),  DBmemp-\>pgout(3),  DbLog::compare(3),  DbLog::flush(3),  [close(2)](/close/2.md),  [fcntl(2)](/fcntl/2.md),  [fflush(3)](/fflush/3.md),  [fsync(2)](/fsync/2.md),  [lseek(2)](/lseek/2.md),  [malloc(3)](/malloc/3.md),  [memcmp(3)](/memcmp/3.md),  [memcpy(3)](/memcpy/3.md),  [memset(3)](/memset/3.md),  [mmap(2)](/mmap/2.md),  [open(2)](/open/2.md),  [sigfillset(3)](/sigfillset/3.md),  [sigprocmask(2)](/sigprocmask/2.md),  [stat(2)](/stat/2.md),  [strcpy(3)](/strcpy/3.md),  [strdup(3)](/strdup/3.md),  [strerror(3)](/strerror/3.md),  [strlen(3)](/strlen/3.md),  [time(3)](/time/3.md),  [unlink(2)](/unlink/2.md),  and [write(2)](/write/2.md).

In addition, the *DbMpoolFile::put* method may fail and throw a *DbException*(3) or return *errno* for the following conditions:

- \[EACCES\]

  The DB\_MPOOL\_DIRTY flag was set and the source file was not opened for writing.

- \[EINVAL\]

  An invalid flag value or parameter was specified.

  The *pgaddr* parameter does not reference a page returned by *DbMpoolFile::get*.

  More than one of DB\_MPOOL\_CLEAN and DB\_MPOOL\_DIRTY was set.

The *DbMpoolFile::set* method may fail and throw a *DbException*(3) or return *errno* for any of the errors specified for the following DB and library functions: [fcntl(2)](/fcntl/2.md),  and [fflush(3)](/fflush/3.md).

In addition, the *DbMpoolFile::set* method may fail and throw a *DbException*(3) or return *errno* for the following conditions:

- \[EINVAL\]

  An invalid flag value or parameter was specified.

The *DbMpoolFile::sync* method may fail and throw a *DbException*(3) or return *errno* for any of the errors specified for the following DB and library functions: DBmemp-\>pgin(3),  DBmemp-\>pgout(3),  DbLog::compare(3),  DbLog::flush(3),  [close(2)](/close/2.md),  [fcntl(2)](/fcntl/2.md),  [fflush(3)](/fflush/3.md),  [fsync(2)](/fsync/2.md),  [lseek(2)](/lseek/2.md),  [malloc(3)](/malloc/3.md),  [memcpy(3)](/memcpy/3.md),  [memset(3)](/memset/3.md),  [open(2)](/open/2.md),  [qsort(3)](/qsort/3.md),  [realloc(3)](/realloc/3.md),  [sigfillset(3)](/sigfillset/3.md),  [sigprocmask(2)](/sigprocmask/2.md),  [stat(2)](/stat/2.md),  [strcpy(3)](/strcpy/3.md),  [strdup(3)](/strdup/3.md),  [strerror(3)](/strerror/3.md),  [strlen(3)](/strlen/3.md),  [unlink(2)](/unlink/2.md),  and [write(2)](/write/2.md).

## SEE ALSO

[*db\_archive*(1)](/db_archive/1.md), [*db\_checkpoint*(1)](/db_checkpoint/1.md), [*db\_deadlock*(1)](/db_deadlock/1.md), [*db\_dump*(1)](/db_dump/1.md), [*db\_load*(1)](/db_load/1.md), [*db\_recover*(1)](/db_recover/1.md), [*db\_stat*(1)](/db_stat/1.md), *db\_intro*(3), *db\_internal*(3), *db\_thread*(3), *Db*(3), *Dbc*(3), *DbEnv*(3), *DbException*(3), *DbInfo*(3), *DbLock*(3), *DbLockTab*(3), *DbLog*(3), *DbLsn*(3), *DbMpool*(3), *DbMpoolFile*(3), *Dbt*(3), *DbTxn*(3), *DbTxnMgr*(3)
