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