2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
using NGit.Storage.Pack;
49
namespace NGit.Storage.File
52
/// Configuration parameters for
53
/// <see cref="WindowCache">WindowCache</see>
56
public class WindowCacheConfig
58
/// <summary>1024 (number of bytes in one kibibyte/kilobyte)</summary>
59
public const int KB = 1024;
63
/// <see cref="KB">KB</see>
64
/// (number of bytes in one mebibyte/megabyte)
66
public const int MB = 1024 * KB;
68
private int packedGitOpenFiles;
70
private long packedGitLimit;
72
private int packedGitWindowSize;
74
private bool packedGitMMAP;
76
private int deltaBaseCacheLimit;
78
private int streamFileThreshold;
80
/// <summary>Create a default configuration.</summary>
81
/// <remarks>Create a default configuration.</remarks>
82
public WindowCacheConfig()
84
packedGitOpenFiles = 128;
85
packedGitLimit = 10 * MB;
86
packedGitWindowSize = 8 * KB;
87
packedGitMMAP = false;
88
deltaBaseCacheLimit = 10 * MB;
89
streamFileThreshold = PackConfig.DEFAULT_BIG_FILE_THRESHOLD;
93
/// maximum number of streams to open at a time. Open packs count
94
/// against the process limits. <b>Default is 128.</b>
96
public virtual int GetPackedGitOpenFiles()
98
return packedGitOpenFiles;
101
/// <param name="fdLimit">
102
/// maximum number of streams to open at a time. Open packs count
103
/// against the process limits
105
public virtual void SetPackedGitOpenFiles(int fdLimit)
107
packedGitOpenFiles = fdLimit;
111
/// maximum number bytes of heap memory to dedicate to caching pack
112
/// file data. <b>Default is 10 MB.</b>
114
public virtual long GetPackedGitLimit()
116
return packedGitLimit;
119
/// <param name="newLimit">
120
/// maximum number bytes of heap memory to dedicate to caching
123
public virtual void SetPackedGitLimit(long newLimit)
125
packedGitLimit = newLimit;
129
/// size in bytes of a single window mapped or read in from the pack
130
/// file. <b>Default is 8 KB.</b>
132
public virtual int GetPackedGitWindowSize()
134
return packedGitWindowSize;
137
/// <param name="newSize">size in bytes of a single window read in from the pack file.
139
public virtual void SetPackedGitWindowSize(int newSize)
141
packedGitWindowSize = newSize;
145
/// true enables use of Java NIO virtual memory mapping for windows;
146
/// false reads entire window into a byte[] with standard read calls.
147
/// <b>Default false.</b>
149
public virtual bool IsPackedGitMMAP()
151
return packedGitMMAP;
154
/// <param name="usemmap">
155
/// true enables use of Java NIO virtual memory mapping for
156
/// windows; false reads entire window into a byte[] with standard
159
public virtual void SetPackedGitMMAP(bool usemmap)
161
packedGitMMAP = usemmap;
165
/// maximum number of bytes to cache in
166
/// <see cref="DeltaBaseCache">DeltaBaseCache</see>
167
/// for inflated, recently accessed objects, without delta chains.
168
/// <b>Default 10 MB.</b>
170
public virtual int GetDeltaBaseCacheLimit()
172
return deltaBaseCacheLimit;
175
/// <param name="newLimit">
176
/// maximum number of bytes to cache in
177
/// <see cref="DeltaBaseCache">DeltaBaseCache</see>
178
/// for inflated, recently accessed
179
/// objects, without delta chains.
181
public virtual void SetDeltaBaseCacheLimit(int newLimit)
183
deltaBaseCacheLimit = newLimit;
186
/// <returns>the size threshold beyond which objects must be streamed.</returns>
187
public virtual int GetStreamFileThreshold()
189
return streamFileThreshold;
192
/// <param name="newLimit">
193
/// new byte limit for objects that must be streamed. Objects
194
/// smaller than this size can be obtained as a contiguous byte
195
/// array, while objects bigger than this size require using an
196
/// <see cref="NGit.ObjectStream">NGit.ObjectStream</see>
199
public virtual void SetStreamFileThreshold(int newLimit)
201
streamFileThreshold = newLimit;
204
/// <summary>Update properties by setting fields from the configuration.</summary>
206
/// Update properties by setting fields from the configuration.
208
/// If a property is not defined in the configuration, then it is left
211
/// <param name="rc">configuration to read properties from.</param>
212
public virtual void FromConfig(Config rc)
214
SetPackedGitOpenFiles(rc.GetInt("core", null, "packedgitopenfiles", GetPackedGitOpenFiles
216
SetPackedGitLimit(rc.GetLong("core", null, "packedgitlimit", GetPackedGitLimit())
218
SetPackedGitWindowSize(rc.GetInt("core", null, "packedgitwindowsize", GetPackedGitWindowSize
220
SetPackedGitMMAP(rc.GetBoolean("core", null, "packedgitmmap", IsPackedGitMMAP()));
221
SetDeltaBaseCacheLimit(rc.GetInt("core", null, "deltabasecachelimit", GetDeltaBaseCacheLimit
223
long maxMem = Runtime.GetRuntime().MaxMemory();
224
long sft = rc.GetLong("core", null, "streamfilethreshold", GetStreamFileThreshold
226
sft = Math.Min(sft, maxMem / 4);
227
// don't use more than 1/4 of the heap
228
sft = Math.Min(sft, int.MaxValue);
229
// cannot exceed array length
230
SetStreamFileThreshold((int)sft);