| 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 xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Shared memory regions</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="env_naming.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 9. |
| 26 | The Berkeley DB Environment |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="env_security.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="env_region"></a>Shared memory regions</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p> |
| 42 | Each of the Berkeley DB subsystems within an environment is described by |
| 43 | one or more regions, or chunks of memory. The regions contain all of |
| 44 | the per-process and per-thread shared information (including mutexes), |
| 45 | that comprise a Berkeley DB environment. These regions are created in |
| 46 | one of three types of memory, depending on the flags specified to the |
| 47 | <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> method: |
| 48 | </p> |
| 49 | <div class="orderedlist"> |
| 50 | <ol type="1"> |
| 51 | <li> |
| 52 | <p> |
| 53 | If the <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a> flag is specified to the <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> method, |
| 54 | regions are created in per-process heap memory; that is, memory |
| 55 | returned by <code class="literal">malloc</code>(3). |
| 56 | </p> |
| 57 | <p> |
| 58 | If this flag is specified, then you cannot open more than a |
| 59 | single handle for the environment. For example, if |
| 60 | both a server application and Berkeley DB utilities (for |
| 61 | example, the <a href="../api_reference/C/db_archive.html" class="olink">db_archive</a> utility, the <a href="../api_reference/C/db_checkpoint.html" class="olink">db_checkpoint</a> utility or the <a href="../api_reference/C/db_stat.html" class="olink">db_stat</a> utility) |
| 62 | are expected to access the environment, the <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a> flag |
| 63 | should not be specified because the second attempt to open |
| 64 | the environment will fail. |
| 65 | </p> |
| 66 | </li> |
| 67 | <li> |
| 68 | <p> |
| 69 | 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/envopen.html" class="olink">DB_ENV->open()</a>, shared |
| 70 | regions are created in system memory rather than files. This is |
| 71 | an alternative mechanism for sharing the Berkeley DB environment |
| 72 | among multiple processes and multiple threads within processes. |
| 73 | </p> |
| 74 | <p> |
| 75 | The system memory used by Berkeley DB is potentially useful past |
| 76 | the lifetime of any particular process. Therefore, additional |
| 77 | cleanup may be necessary after an application fails because |
| 78 | there may be no way for Berkeley DB to ensure that system |
| 79 | resources backing the shared memory regions are returned to the |
| 80 | system. |
| 81 | </p> |
| 82 | <p> |
| 83 | The system memory that is used is architecture-dependent. For |
| 84 | example, on systems supporting X/Open-style shared memory |
| 85 | interfaces, such as UNIX systems, the |
| 86 | <code class="literal">shmget</code>(2) and related System V IPC interfaces |
| 87 | are used. Additionally, VxWorks systems use system memory. In |
| 88 | these cases, an initial segment ID must be specified by the |
| 89 | application to ensure that applications do not overwrite each |
| 90 | other's database environments, so that the number of segments |
| 91 | created does not grow without bounds. See the <a href="../api_reference/C/envset_shm_key.html" class="olink">DB_ENV->set_shm_key()</a> |
| 92 | method for more information. |
| 93 | </p> |
| 94 | <p> |
| 95 | 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 |
| 96 | problematic because the operating system uses reference counting |
| 97 | to clean up shared objects in the paging file automatically. In |
| 98 | addition, the default access permissions for shared objects are |
| 99 | different from files, which may cause problems when an |
| 100 | environment is accessed by multiple processes running as |
| 101 | different users. See the <a href="../installation/build_win_notes.html" class="olink">Windows Notes</a> section in the |
| 102 | Berkeley DB Installation and Build Guide for more information. |
| 103 | </p> |
| 104 | </li> |
| 105 | <li> |
| 106 | If no memory-related flags are specified to <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a>, memory backed |
| 107 | by the filesystem is used to store the regions. On UNIX systems, |
| 108 | the Berkeley DB library will use the POSIX mmap interface. If mmap |
| 109 | is not available, the UNIX shmget interfaces may be used instead, if |
| 110 | they are available. |
| 111 | </li> |
| 112 | </ol> |
| 113 | </div> |
| 114 | <p> |
| 115 | Any files created in the filesystem to back the regions are created in |
| 116 | the environment home directory specified to the <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> call. These |
| 117 | files are named __db.### (for example, __db.001, __db.002 and so on). |
| 118 | When region files are backed by the filesystem, one file per region is |
| 119 | created. When region files are backed by system memory, a single file |
| 120 | will still be created because there must be a well-known name in the |
| 121 | filesystem so that multiple processes can locate the system shared |
| 122 | memory that is being used by the environment.</p> |
| 123 | <p>Statistics |
| 124 | about the shared memory regions in the environment can be displayed |
| 125 | using the <span class="bold"><strong>-e</strong></span> option to the |
| 126 | <a href="../api_reference/C/db_stat.html" class="olink">db_stat</a> utility. |
| 127 | </p> |
| 128 | </div> |
| 129 | <div class="navfooter"> |
| 130 | <hr /> |
| 131 | <table width="100%" summary="Navigation footer"> |
| 132 | <tr> |
| 133 | <td width="40%" align="left"><a accesskey="p" href="env_naming.html">Prev</a> </td> |
| 134 | <td width="20%" align="center"> |
| 135 | <a accesskey="u" href="env.html">Up</a> |
| 136 | </td> |
| 137 | <td width="40%" align="right"> <a accesskey="n" href="env_security.html">Next</a></td> |
| 138 | </tr> |
| 139 | <tr> |
| 140 | <td width="40%" align="left" valign="top">File naming </td> |
| 141 | <td width="20%" align="center"> |
| 142 | <a accesskey="h" href="index.html">Home</a> |
| 143 | </td> |
| 144 | <td width="40%" align="right" valign="top"> Security</td> |
| 145 | </tr> |
| 146 | </table> |
| 147 | </div> |
| 148 | </body> |
| 149 | </html> |