| 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>DB_ENV->set_cachesize()</title> |
| 7 | <link rel="stylesheet" href="apiReference.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 C API Reference" /> |
| 10 | <link rel="up" href="memp.html" title="Chapter 8. The DB_MPOOLFILE Handle" /> |
| 11 | <link rel="prev" href="envset_cache_max.html" title="DB_ENV->set_cache_max()" /> |
| 12 | <link rel="next" href="mempset_mp_max_openfd.html" title="DB_ENV->set_mp_max_openfd()" /> |
| 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">DB_ENV->set_cachesize()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="envset_cache_max.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 8. |
| 26 | The DB_MPOOLFILE Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="mempset_mp_max_openfd.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="envset_cachesize"></a>DB_ENV->set_cachesize()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db.h> |
| 42 | |
| 43 | int |
| 44 | DB_ENV->set_cachesize(DB_ENV *dbenv, |
| 45 | u_int32_t gbytes, u_int32_t bytes, int ncache); </pre> |
| 46 | <p> |
| 47 | Sets the size of the shared memory buffer pool — that is, the cache. |
| 48 | The cache should be the size of the normal working data set of the |
| 49 | application, with some small amount of additional memory for unusual |
| 50 | situations. (Note: the working set is not the same as the number of |
| 51 | pages accessed simultaneously, and is usually much larger.) |
| 52 | </p> |
| 53 | <p> |
| 54 | The default cache size is 256KB, and may not be specified as less than |
| 55 | 20KB. Any cache size less than 500MB is automatically increased by |
| 56 | 25% to account for cache overhead; cache sizes larger than 500MB |
| 57 | are used as specified. The maximum size of a single cache is 4GB on |
| 58 | 32-bit systems and 10TB on 64-bit systems. (All sizes are in |
| 59 | powers-of-two, that is, 256KB is 2^18 not 256,000.) For information on |
| 60 | tuning the Berkeley DB cache size, see |
| 61 | <a href="../../programmer_reference/general_am_conf.html#am_conf_cachesize" class="olink">Selecting a cache size</a>. |
| 62 | </p> |
| 63 | <p> |
| 64 | It is possible to specify caches to Berkeley DB large enough they |
| 65 | cannot be allocated contiguously on some architectures. For example, |
| 66 | some releases of Solaris limit the amount of memory that may be |
| 67 | allocated contiguously by a process. If <span class="bold"><strong>ncache</strong></span> is 0 or 1, the cache will be allocated |
| 68 | contiguously in memory. If it is greater than 1, the cache will be |
| 69 | split across <span class="bold"><strong>ncache</strong></span> separate regions, |
| 70 | where the <span class="bold"><strong>region size</strong></span> is equal to the |
| 71 | initial cache size divided by <span class="bold"><strong>ncache</strong></span>. |
| 72 | </p> |
| 73 | <p> |
| 74 | The cache may be resized by calling <code class="methodname">DB_ENV->set_cachesize()</code> |
| 75 | after the environment is open. The supplied size will be rounded to the nearest multiple |
| 76 | of the region size and may not be larger than the maximum size configured with |
| 77 | <a class="xref" href="envset_cache_max.html" title="DB_ENV->set_cache_max()">DB_ENV->set_cache_max()</a>. The |
| 78 | <span class="bold"><strong>ncache</strong></span> parameter is ignored when resizing the cache. |
| 79 | |
| 80 | </p> |
| 81 | <p> |
| 82 | The database environment's initial cache size may also be |
| 83 | configured using the environment's <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> file. The syntax of |
| 84 | the entry in that file is a single line with the string |
| 85 | "set_cachesize", one or more whitespace characters, and the |
| 86 | initial cache size specified in three parts: the gigabytes of |
| 87 | cache, the additional bytes of cache, and the number of caches, |
| 88 | also separated by whitespace characters. For example, |
| 89 | "set_cachesize 2 524288000 3" would create a 2.5GB logical cache, |
| 90 | split between three physical caches. Because the <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> file |
| 91 | is read when the database environment is opened, it will silently |
| 92 | overrule configuration done before that time. |
| 93 | </p> |
| 94 | <p> |
| 95 | The <code class="methodname">DB_ENV->set_cachesize()</code> method configures a database environment, |
| 96 | not only operations performed using the specified <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a> handle. |
| 97 | </p> |
| 98 | <p> |
| 99 | The <code class="methodname">DB_ENV->set_cachesize()</code> method may be called at any time during |
| 100 | the life of the application. |
| 101 | </p> |
| 102 | <p> |
| 103 | The <code class="methodname">DB_ENV->set_cachesize()</code> <span> |
| 104 | <span> |
| 105 | method returns a non-zero error value on failure and 0 on success. |
| 106 | </span> |
| 107 | |
| 108 | </span> |
| 109 | </p> |
| 110 | <div class="sect2" lang="en" xml:lang="en"> |
| 111 | <div class="titlepage"> |
| 112 | <div> |
| 113 | <div> |
| 114 | <h3 class="title"><a id="idp53338680"></a>Parameters</h3> |
| 115 | </div> |
| 116 | </div> |
| 117 | </div> |
| 118 | <div class="sect3" lang="en" xml:lang="en"> |
| 119 | <div class="titlepage"> |
| 120 | <div> |
| 121 | <div> |
| 122 | <h4 class="title"><a id="idp53338528"></a>gbytes</h4> |
| 123 | </div> |
| 124 | </div> |
| 125 | </div> |
| 126 | <p> |
| 127 | The size of the cache is set to <span class="bold"><strong>gbytes</strong></span> gigabytes plus <span class="bold"><strong>bytes</strong></span>. |
| 128 | </p> |
| 129 | </div> |
| 130 | <div class="sect3" lang="en" xml:lang="en"> |
| 131 | <div class="titlepage"> |
| 132 | <div> |
| 133 | <div> |
| 134 | <h4 class="title"><a id="idp53345176"></a>bytes</h4> |
| 135 | </div> |
| 136 | </div> |
| 137 | </div> |
| 138 | <p> |
| 139 | The size of the cache is set to <span class="bold"><strong>gbytes</strong></span> gigabytes plus <span class="bold"><strong>bytes</strong></span>. |
| 140 | </p> |
| 141 | </div> |
| 142 | <div class="sect3" lang="en" xml:lang="en"> |
| 143 | <div class="titlepage"> |
| 144 | <div> |
| 145 | <div> |
| 146 | <h4 class="title"><a id="idp53336336"></a>ncache</h4> |
| 147 | </div> |
| 148 | </div> |
| 149 | </div> |
| 150 | <p> |
| 151 | The <span class="bold"><strong>ncache</strong></span> parameter is the number of |
| 152 | caches to create. |
| 153 | </p> |
| 154 | </div> |
| 155 | </div> |
| 156 | <div class="sect2" lang="en" xml:lang="en"> |
| 157 | <div class="titlepage"> |
| 158 | <div> |
| 159 | <div> |
| 160 | <h3 class="title"><a id="idp53352048"></a>Errors</h3> |
| 161 | </div> |
| 162 | </div> |
| 163 | </div> |
| 164 | <p> |
| 165 | The <code class="methodname">DB_ENV->set_cachesize()</code> <span> |
| 166 | <span> |
| 167 | method may fail and return one of the following non-zero errors: |
| 168 | </span> |
| 169 | |
| 170 | </span> |
| 171 | </p> |
| 172 | <div class="sect3" lang="en" xml:lang="en"> |
| 173 | <div class="titlepage"> |
| 174 | <div> |
| 175 | <div> |
| 176 | <h4 class="title"><a id="idp53356760"></a>EINVAL</h4> |
| 177 | </div> |
| 178 | </div> |
| 179 | </div> |
| 180 | <p> |
| 181 | If the specified cache size was impossibly small; or if an invalid |
| 182 | flag value or parameter was specified. |
| 183 | </p> |
| 184 | </div> |
| 185 | </div> |
| 186 | <div class="sect2" lang="en" xml:lang="en"> |
| 187 | <div class="titlepage"> |
| 188 | <div> |
| 189 | <div> |
| 190 | <h3 class="title"><a id="idp53354672"></a>Class</h3> |
| 191 | </div> |
| 192 | </div> |
| 193 | </div> |
| 194 | <p> |
| 195 | <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a> |
| 196 | </p> |
| 197 | </div> |
| 198 | <div class="sect2" lang="en" xml:lang="en"> |
| 199 | <div class="titlepage"> |
| 200 | <div> |
| 201 | <div> |
| 202 | <h3 class="title"><a id="idp53358096"></a>See Also</h3> |
| 203 | </div> |
| 204 | </div> |
| 205 | </div> |
| 206 | <p> |
| 207 | <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> |
| 208 | </p> |
| 209 | </div> |
| 210 | </div> |
| 211 | <div class="navfooter"> |
| 212 | <hr /> |
| 213 | <table width="100%" summary="Navigation footer"> |
| 214 | <tr> |
| 215 | <td width="40%" align="left"><a accesskey="p" href="envset_cache_max.html">Prev</a> </td> |
| 216 | <td width="20%" align="center"> |
| 217 | <a accesskey="u" href="memp.html">Up</a> |
| 218 | </td> |
| 219 | <td width="40%" align="right"> <a accesskey="n" href="mempset_mp_max_openfd.html">Next</a></td> |
| 220 | </tr> |
| 221 | <tr> |
| 222 | <td width="40%" align="left" valign="top">DB_ENV->set_cache_max() </td> |
| 223 | <td width="20%" align="center"> |
| 224 | <a accesskey="h" href="index.html">Home</a> |
| 225 | </td> |
| 226 | <td width="40%" align="right" valign="top"> DB_ENV->set_mp_max_openfd()</td> |
| 227 | </tr> |
| 228 | </table> |
| 229 | </div> |
| 230 | </body> |
| 231 | </html> |