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