mp_method.c
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 3k
Category:

MySQL

Development Platform:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1996, 1997, 1998, 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  */
  7. #include "db_config.h"
  8. #ifndef lint
  9. static const char revid[] = "$Id: mp_method.c,v 11.10 2000/04/04 20:12:04 bostic Exp $";
  10. #endif /* not lint */
  11. #ifndef NO_SYSTEM_INCLUDES
  12. #include <sys/types.h>
  13. #endif
  14. #ifdef  HAVE_RPC
  15. #include "db_server.h"
  16. #endif
  17. #include "db_int.h"
  18. #include "db_shash.h"
  19. #include "mp.h"
  20. #ifdef HAVE_RPC
  21. #include "gen_client_ext.h"
  22. #include "rpc_client_ext.h"
  23. #endif
  24. static int __memp_set_cachesize __P((DB_ENV *, u_int32_t, u_int32_t, int));
  25. static int __memp_set_mp_mmapsize __P((DB_ENV *, size_t));
  26. /*
  27.  * __memp_dbenv_create --
  28.  * Mpool specific creation of the DB_ENV structure.
  29.  *
  30.  * PUBLIC: void __memp_dbenv_create __P((DB_ENV *));
  31.  */
  32. void
  33. __memp_dbenv_create(dbenv)
  34. DB_ENV *dbenv;
  35. {
  36. /*
  37.  * We default to 32 8K pages.  We don't default to a flat 256K, because
  38.  * some systems require significantly more memory to hold 32 pages than
  39.  * others.  For example, HP-UX with POSIX pthreads needs 88 bytes for
  40.  * a POSIX pthread mutex and almost 200 bytes per buffer header, while
  41.  * Solaris needs 24 and 52 bytes for the same structures.
  42.  */
  43. dbenv->mp_bytes = 32 * ((8 * 1024) + sizeof(BH));
  44. dbenv->mp_ncache = 1;
  45. dbenv->set_mp_mmapsize = __memp_set_mp_mmapsize;
  46. dbenv->set_cachesize = __memp_set_cachesize;
  47. #ifdef HAVE_RPC
  48. /*
  49.  * If we have a client, overwrite what we just setup to
  50.  * point to client functions.
  51.  */
  52. if (F_ISSET(dbenv, DB_ENV_RPCCLIENT)) {
  53. dbenv->set_cachesize = __dbcl_env_cachesize;
  54. dbenv->set_mp_mmapsize = __dbcl_set_mp_mmapsize;
  55. }
  56. #endif
  57. }
  58. /*
  59.  * __memp_set_cachesize --
  60.  * Initialize the cache size.
  61.  */
  62. static int
  63. __memp_set_cachesize(dbenv, gbytes, bytes, ncache)
  64. DB_ENV *dbenv;
  65. u_int32_t gbytes, bytes;
  66. int ncache;
  67. {
  68. ENV_ILLEGAL_AFTER_OPEN(dbenv, "set_cachesize");
  69. dbenv->mp_gbytes = gbytes + bytes / GIGABYTE;
  70. dbenv->mp_bytes = bytes % GIGABYTE;
  71. dbenv->mp_ncache = ncache == 0 ? 1 : ncache;
  72. /*
  73.  * If the application requested less than 500Mb, increase the
  74.  * cachesize by 25% to account for our overhead.  (I'm guessing
  75.  * that caches over 500Mb are specifically sized, i.e., it's
  76.  * a large server and the application actually knows how much
  77.  * memory is available.)
  78.  *
  79.  * There is a minimum cache size, regardless.
  80.  */
  81. if (dbenv->mp_gbytes == 0) {
  82. if (dbenv->mp_bytes < 500 * MEGABYTE)
  83. dbenv->mp_bytes += dbenv->mp_bytes / 4;
  84. if (dbenv->mp_bytes < DB_CACHESIZE_MIN)
  85. dbenv->mp_bytes = DB_CACHESIZE_MIN;
  86. }
  87. return (0);
  88. }
  89. /*
  90.  * __memp_set_mp_mmapsize --
  91.  * Set the maximum mapped file size.
  92.  */
  93. static int
  94. __memp_set_mp_mmapsize(dbenv, mp_mmapsize )
  95. DB_ENV *dbenv;
  96. size_t mp_mmapsize;
  97. {
  98. dbenv->mp_mmapsize = mp_mmapsize;
  99. return (0);
  100. }