1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2009 Oracle.  All rights reserved.
5 *
6 */
7using System;
8using System.Collections.Generic;
9using System.Text;
10
11namespace BerkeleyDB {
12    /// <summary>
13    /// A class representing configuration parameters for a
14    /// <see cref="DatabaseEnvironment"/>'s memory pool subsystem.
15    /// </summary>
16    public class MPoolConfig {
17        /// <summary>
18        /// The size of the shared memory buffer pool � that is, the cache.
19        /// </summary>
20        /// <remarks>
21        /// <para>
22        /// The cache should be the size of the normal working data set of the
23        /// application, with some small amount of additional memory for unusual
24        /// situations. (Note: the working set is not the same as the number of
25        /// pages accessed simultaneously, and is usually much larger.)
26        /// </para>
27        /// <para>
28        /// The default cache size is 256KB, and may not be specified as less
29        /// than 20KB. Any cache size less than 500MB is automatically increased
30        /// by 25% to account for buffer pool overhead; cache sizes larger than
31        /// 500MB are used as specified. The maximum size of a single cache is
32        /// 4GB on 32-bit systems and 10TB on 64-bit systems. (All sizes are in
33        /// powers-of-two, that is, 256KB is 2^18 not 256,000.) For information
34        /// on tuning the Berkeley DB cache size, see Selecting a cache size in
35        /// the Programmer's Reference Guide.
36        /// </para>
37        /// </remarks>
38        public CacheInfo CacheSize;
39        /// <summary>
40        /// The maximum cache size.
41        /// </summary>
42        /// <remarks>
43        /// <para>
44        /// The specified size is rounded to the nearest multiple of the cache
45        /// region size, which is the initial cache size divided by
46        /// <see cref="CacheInfo.NCaches">CacheSize.NCaches</see>. If no value
47        /// is specified, it defaults to the initial cache size.
48        /// </para>
49        /// </remarks>
50        public CacheInfo MaxCacheSize;
51
52        internal bool maxOpenFDIsSet;
53        private int maxOpenFD;
54        /// <summary>
55        /// The number of file descriptors the library will open concurrently
56        /// when flushing dirty pages from the cache.
57        /// </summary>
58        public int MaxOpenFiles {
59            get { return maxOpenFD; }
60            set {
61                maxOpenFDIsSet = true;
62                maxOpenFD = value;
63            }
64        }
65
66        internal bool maxSeqWriteIsSet;
67        private int maxSeqWrites;
68        private uint maxSeqWritesPause;
69        /// <summary>
70        /// Limit the number of sequential write operations scheduled by the
71        /// library when flushing dirty pages from the cache.
72        /// </summary>
73        /// <param name="maxWrites">
74        /// The maximum number of sequential write operations scheduled by the
75        /// library when flushing dirty pages from the cache, or 0 if there is
76        /// no limitation on the number of sequential write operations.
77        /// </param>
78        /// <param name="pause">
79        /// The number of microseconds the thread of control should pause before
80        /// scheduling further write operations. It must be specified as an
81        /// unsigned 32-bit number of microseconds, limiting the maximum pause
82        /// to roughly 71 minutes.
83        /// </param>
84        public void SetMaxSequentialWrites(int maxWrites, uint pause) {
85            maxSeqWriteIsSet = true;
86            maxSeqWrites = maxWrites;
87            maxSeqWritesPause = pause;
88        }
89        /// <summary>
90        /// The number of microseconds the thread of control should pause before
91        /// scheduling further write operations.
92        /// </summary>
93        public uint SequentialWritePause { get { return maxSeqWritesPause; } }
94        /// <summary>
95        /// The number of sequential write operations scheduled by the library
96        /// when flushing dirty pages from the cache.
97        /// </summary>
98        public int MaxSequentialWrites { get { return maxSeqWrites; } }
99
100        internal bool mmapSizeSet;
101        private uint mmap_size;
102        /// <summary>
103        /// The maximum file size, in bytes, for a file to be mapped into the
104        /// process address space. If no value is specified, it defaults to
105        /// 10MB.
106        /// </summary>
107        /// <remarks>
108        /// Files that are opened read-only in the cache (and that satisfy a few
109        /// other criteria) are, by default, mapped into the process address
110        /// space instead of being copied into the local cache. This can result
111        /// in better-than-usual performance because available virtual memory is
112        /// normally much larger than the local cache, and page faults are
113        /// faster than page copying on many systems. However, it can cause
114        /// resource starvation in the presence of limited virtual memory, and
115        /// it can result in immense process sizes in the presence of large
116        /// databases.
117        /// </remarks>
118        public uint MMapSize {
119            get { return mmap_size; }
120            set {
121                mmapSizeSet = true;
122                mmap_size = value;
123            }
124        }
125
126    }
127}
128