• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/docs/programmer_reference/
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6    <title>Shared memory regions</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9    <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
10    <link rel="up" href="env.html" title="Chapter��9.�� The Berkeley DB Environment" />
11    <link rel="prev" href="env_naming.html" title="File naming" />
12    <link rel="next" href="env_security.html" title="Security" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Shared memory regions</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="env_naming.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��9.��
23		The Berkeley DB Environment
24        </th>
25          <td width="20%" align="right">��<a accesskey="n" href="env_security.html">Next</a></td>
26        </tr>
27      </table>
28      <hr />
29    </div>
30    <div class="sect1" lang="en" xml:lang="en">
31      <div class="titlepage">
32        <div>
33          <div>
34            <h2 class="title" style="clear: both"><a id="env_region"></a>Shared memory regions</h2>
35          </div>
36        </div>
37      </div>
38      <p>Each of the Berkeley DB subsystems within an environment is described by one
39or more regions, or chunks of memory.  The regions contain all of the
40per-process and per-thread shared information (including mutexes), that
41comprise a Berkeley DB environment.  These regions are created in one of three
42types of memory, depending on the flags specified to the
43<a href="../api_reference/C/envopen.html" class="olink">DB_ENV-&gt;open()</a> method:</p>
44      <div class="orderedlist">
45        <p>The system memory used by Berkeley DB is potentially useful past the lifetime
46of any particular process.  Therefore, additional cleanup may be
47necessary after an application fails because there may be no way for
48Berkeley DB to ensure that system resources backing the shared memory regions
49are returned to the system.</p>
50        <p>The system memory that is used is architecture-dependent.  For example,
51on systems supporting X/Open-style shared memory interfaces, such as
52UNIX systems, the <code class="literal">shmget</code>(2) and related System V IPC
53interfaces are used. Additionally, VxWorks systems use system memory.
54In these cases, an initial segment ID must be specified by the
55application to ensure that applications do not overwrite each other's
56database environments, so that the number of segments created does not
57grow without bounds.  See the <a href="../api_reference/C/envset_shm_key.html" class="olink">DB_ENV-&gt;set_shm_key()</a> method for more
58information.</p>
59        <p>On Windows platforms, the use of the <a href="../api_reference/C/envopen.html#envopen_DB_SYSTEM_MEM" class="olink">DB_SYSTEM_MEM</a> flag is
60problematic because the operating system uses reference counting to
61clean up shared objects in the paging file automatically.  In addition,
62the default access permissions for shared objects are different from
63files, which may cause problems when an environment is accessed by
64multiple processes running as different users.  See
65<a class="xref" href="build_win_notes.html" title="Windows notes">Windows notes</a> for more
66information.</p>
67        <ol type="1">
68          <li>
69            <p>If the <a href="../api_reference/C/envopen.html#open_DB_PRIVATE" class="olink">DB_PRIVATE</a> flag is specified to the <a href="../api_reference/C/envopen.html" class="olink">DB_ENV-&gt;open()</a> method,
70regions are created in per-process heap memory; that is, memory returned
71by <code class="literal">malloc</code>(3).</p>
72            <p>This flag should not be specified if more than a single process is
73accessing the environment because it is likely to cause database
74corruption and unpredictable behavior.  For example, if both a server
75application and Berkeley DB utilities (for example, the <a href="../api_reference/C/db_archive.html" class="olink">db_archive utility</a>, 
76the <a href="../api_reference/C/db_checkpoint.html" class="olink">db_checkpoint utility</a> or the <a href="../api_reference/C/db_stat.html" class="olink">db_stat utility</a>) are expected to access the environment, 
77the <a href="../api_reference/C/envopen.html#open_DB_PRIVATE" class="olink">DB_PRIVATE</a> flag should not be specified.</p>
78          </li>
79          <li>If the <a href="../api_reference/C/envopen.html#envopen_DB_SYSTEM_MEM" class="olink">DB_SYSTEM_MEM</a> flag is specified to <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a>,
80shared regions are created in system memory rather than files.  This is
81an alternative mechanism for sharing the Berkeley DB environment among
82multiple processes and multiple threads within processes.</li>
83          <li>If no memory-related flags are specified to <a href="../api_reference/C/envopen.html" class="olink">DB_ENV-&gt;open()</a>, memory
84backed by the filesystem is used to store the regions.  On UNIX systems,
85the Berkeley DB library will use the POSIX mmap interface. If mmap is not available,
86the UNIX shmget interfaces may be used instead, if they are available.</li>
87        </ol>
88      </div>
89      <p>Any files created in the filesystem to back the regions are created in
90the environment home directory specified to the <a href="../api_reference/C/envopen.html" class="olink">DB_ENV-&gt;open()</a> call.
91These files are named __db.### (for example, __db.001, __db.002 and
92so on).  When region files are backed by the filesystem, one file per
93region is created.  When region files are backed by system memory, a
94single file will still be created because there must be a well-known
95name in the filesystem so that multiple processes can locate the system
96shared memory that is being used by the environment.</p>
97      <p>Statistics about the shared memory regions in the environment can be
98displayed using the <span class="bold"><strong>-e</strong></span> option to the <a href="../api_reference/C/db_stat.html" class="olink">db_stat utility</a>.</p>
99    </div>
100    <div class="navfooter">
101      <hr />
102      <table width="100%" summary="Navigation footer">
103        <tr>
104          <td width="40%" align="left"><a accesskey="p" href="env_naming.html">Prev</a>��</td>
105          <td width="20%" align="center">
106            <a accesskey="u" href="env.html">Up</a>
107          </td>
108          <td width="40%" align="right">��<a accesskey="n" href="env_security.html">Next</a></td>
109        </tr>
110        <tr>
111          <td width="40%" align="left" valign="top">File naming��</td>
112          <td width="20%" align="center">
113            <a accesskey="h" href="index.html">Home</a>
114          </td>
115          <td width="40%" align="right" valign="top">��Security</td>
116        </tr>
117      </table>
118    </div>
119  </body>
120</html>
121