|
Memory-only or Flash configurations
Berkeley DB supports a variety of memory-based configurations for systems where filesystem space is either limited in availability or entirely replaced by some combination of memory and Flash. In addition, Berkeley DB can be configured to minimize writes to the filesystem when the filesystem is backed by Flash memory.
There are three parts of the Berkeley DB database environment normally written to the filesystem: the database environment region files, the database files and the database environment log files. Each of these items can be configured to live in memory rather than in the filesystem:
To create the database environment in heap memory, specify the DB_PRIVATE flag to the DB_ENV->open method. Note that database environments created in heap memory are only accessible to the threads of a single process, however.
To create the database environment in system shared memory, specify the DB_SYSTEM_MEM flag to the DB_ENV->open method. Database environments created in system memory are accessible to multiple processes, but note that database environments created in system shared memory do create a small (roughly 8 byte) file in the filesystem, read by the processes to identify which system shared memory segments to use.
For more information, see Shared memory regions.
In applications running on systems without any form of stable storage, durability must be accomplished through replication. In this case, database environments should be configured to maintain database logs in memory, rather than in the filesystem, by specifying the DB_LOG_IN_MEMORY flag to the DB_ENV->set_flags method.
In systems where the filesystem is backed by Flash memory, the number of times the Flash memory is written may be a concern. Each of the three parts of the Berkeley DB database environment normally written to the filesystem can be configured to minimize the number of times the filesystem is written:
To avoid unnecessary writes of Flash memory due to checkpoints, applications should decrease the frequency of their checkpoints. This is especially important in applications which repeatedly modify a specific database page, as repeatedly writing a database page to the backing physical file will repeatedly update the same blocks of the filesystem.
To avoid unnecessary writes of the filesystem due to closing a database handle, applications should specify the DB_NOSYNC flag to the DB->close method.
To avoid unnecessary writes of the filesystem due to flushing the cache, applications should not explicitly flush the cache under normal conditions -- flushing the cache is rarely if ever needed in a normally-running application.
However, as Berkeley DB does not write log records in filesystem block sized pieces, it is probable that sequential transaction commits (each of which flush the log file to the backing filesystem), will write a block of Flash memory twice, as the last log record from the first commit will write the same block of Flash memory as the first log record from the second commit. Applications not requiring absolute durability should specify the DB_TXN_WRITE_NOSYNC or DB_TXN_NOSYNC flags to the DB_ENV->set_flags method to avoid this overwrite of a block of Flash memory.
Copyright (c) 1996,2008 Oracle. All rights reserved.