1<!--$Id: env_set_cachesize.so,v 10.51 2007/07/06 00:22:52 mjc Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB: DbEnv::set_cachesize</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td> 13<b>DbEnv::set_cachesize</b> 14</td> 15<td align=right> 16<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a> 17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td> 18</tr></table> 19<hr size=1 noshade> 20<tt> 21<b><pre> 22#include <db_cxx.h> 23<p> 24int 25DbEnv::set_cachesize(u_int32_t gbytes, u_int32_t bytes, int ncache); 26<p> 27int 28DbEnv::get_cachesize(u_int32_t *gbytesp, u_int32_t *bytesp, int *ncachep); 29</pre></b> 30<hr size=1 noshade> 31<b>Description: DbEnv::set_cachesize</b> 32<p>Set the size of the shared memory buffer pool -- that is, the cache. 33The cache should be the size of the normal working data set of the 34application, with some small amount of additional memory for unusual 35situations. (Note: the working set is not the same as the number of 36pages accessed simultaneously, and is usually much larger.)</p> 37<p>The default cache size is 256KB, and may not be specified as less than 3820KB. Any cache size less than 500MB is automatically increased by 25% 39to account for buffer pool overhead; cache sizes larger than 500MB are 40used as specified. The maximum size of a single cache is 4GB on 32-bit 41systems and 10TB on 64-bit systems. (All sizes are in powers-of-two, 42that is, 256KB is 2^18 not 256,000.) For information on tuning the Berkeley DB 43cache size, see <a href="../ref/am_conf/cachesize.html">Selecting a 44cache size</a>.</p> 45<p>It is possible to specify caches to Berkeley DB large enough they cannot be 46allocated contiguously on some architectures. For example, some 47releases of Solaris limit the amount of memory that may be allocated 48contiguously by a process. If <b>ncache</b> is 0 or 1, the cache will 49be allocated contiguously in memory. If it is greater than 1, the cache 50will be split across <b>ncache</b> separate regions, where the 51<b>region size</b> is equal to the initial cache size divided by 52<b>ncache</b>.</p> 53<p>The memory pool may be resized by calling DbEnv::set_cachesize 54after the environment is open. The supplied size will be rounded to 55the nearest multiple of the region size and may not be larger than the 56maximum size configured with <a href="../api_cxx/env_set_cache_max.html">DbEnv::set_cache_max</a>. The 57<b>ncache</b> parameter is ignored when resizing the cache.</p> 58<p>The database environment's initial cache size may also be configured using the 59environment's <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> file. The syntax of the entry in that 60file is a single line with the string "set_cachesize", one or more whitespace 61characters, and the initial cache size specified in three parts: the gigabytes of 62cache, the additional bytes of cache, and the number of caches, also 63separated by whitespace characters. For example, "set_cachesize 2 64524288000 3" would create a 2.5GB logical cache, split between three 65physical caches. 66Because the <a href="../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> file is read when the database environment 67is opened, it will silently overrule configuration done before that 68time.</p> 69<p>The DbEnv::set_cachesize method configures a database environment, not only operations 70performed using the specified <a href="../api_cxx/env_class.html">DbEnv</a> handle.</p> 71<p>The DbEnv::set_cachesize method may be called at any time during the life of the 72application.</p> 73<p>The DbEnv::set_cachesize method 74either returns a non-zero error value 75or throws an exception that encapsulates a non-zero error value on 76failure, and returns 0 on success. 77</p> 78<b>Parameters</b> <br> 79 <b>bytes</b><ul compact><li>The size of the cache is set to <b>gbytes</b> gigabytes plus <b>bytes</b>.</ul> 80 <b>gbytes</b><ul compact><li>The size of the cache is set to <b>gbytes</b> gigabytes plus <b>bytes</b>.</ul> 81 <b>ncache</b><ul compact><li>The <b>ncache</b> parameter is the number of caches to create.</ul> 82<br> 83<br><b>Errors</b> 84<p>The DbEnv::set_cachesize method 85may fail and throw 86<a href="../api_cxx/except_class.html">DbException</a>, 87encapsulating one of the following non-zero errors, or return one of 88the following non-zero errors:</p> 89<br> 90<b>EINVAL</b><ul compact><li>If the specified cache size was impossibly small; 91; or if an 92invalid flag value or parameter was specified.</ul> 93<br> 94<hr size=1 noshade> 95<b>Description: DbEnv::get_cachesize</b> 96<p>The DbEnv::get_cachesize method returns the current size and composition of the 97cache.</p> 98<p>The DbEnv::get_cachesize method may be called at any time during the life of the 99application.</p> 100<p>The DbEnv::get_cachesize method 101either returns a non-zero error value 102or throws an exception that encapsulates a non-zero error value on 103failure, and returns 0 on success. 104</p> 105<b>Parameters</b> <br> 106 <b>bytesp</b><ul compact><li>The <b>bytesp</b> parameter references memory into which 107 the additional bytes of memory in the cache is copied.</ul> 108 <b>gbytesp</b><ul compact><li>The <b>gbytesp</b> parameter references memory into which 109 the gigabytes of memory in the cache is copied.</ul> 110 <b>ncachep</b><ul compact><li>The <b>ncachep</b> parameter references memory into which 111 the number of caches is copied.</ul> 112<br> 113<hr size=1 noshade> 114<br><b>Class</b> 115<a href="../api_cxx/env_class.html">DbEnv</a> 116<br><b>See Also</b> 117<a href="../api_cxx/env_list.html">Database Environments and Related Methods</a> 118</tt> 119<table width="100%"><tr><td><br></td><td align=right> 120<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a> 121</td></tr></table> 122<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 123</body> 124</html> 125