You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowCacheConfig.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (C) 2009, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  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
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  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.
  23. *
  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
  27. * written permission.
  28. *
  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.
  42. */
  43. package org.eclipse.jgit.storage.file;
  44. import org.eclipse.jgit.lib.Config;
  45. import org.eclipse.jgit.storage.pack.PackConfig;
  46. /** Configuration parameters for {@link WindowCache}. */
  47. public class WindowCacheConfig {
  48. /** 1024 (number of bytes in one kibibyte/kilobyte) */
  49. public static final int KB = 1024;
  50. /** 1024 {@link #KB} (number of bytes in one mebibyte/megabyte) */
  51. public static final int MB = 1024 * KB;
  52. private int packedGitOpenFiles;
  53. private long packedGitLimit;
  54. private int packedGitWindowSize;
  55. private boolean packedGitMMAP;
  56. private int deltaBaseCacheLimit;
  57. private int streamFileThreshold;
  58. /** Create a default configuration. */
  59. public WindowCacheConfig() {
  60. packedGitOpenFiles = 128;
  61. packedGitLimit = 10 * MB;
  62. packedGitWindowSize = 8 * KB;
  63. packedGitMMAP = false;
  64. deltaBaseCacheLimit = 10 * MB;
  65. streamFileThreshold = PackConfig.DEFAULT_BIG_FILE_THRESHOLD;
  66. }
  67. /**
  68. * @return maximum number of streams to open at a time. Open packs count
  69. * against the process limits. <b>Default is 128.</b>
  70. */
  71. public int getPackedGitOpenFiles() {
  72. return packedGitOpenFiles;
  73. }
  74. /**
  75. * @param fdLimit
  76. * maximum number of streams to open at a time. Open packs count
  77. * against the process limits
  78. */
  79. public void setPackedGitOpenFiles(final int fdLimit) {
  80. packedGitOpenFiles = fdLimit;
  81. }
  82. /**
  83. * @return maximum number bytes of heap memory to dedicate to caching pack
  84. * file data. <b>Default is 10 MB.</b>
  85. */
  86. public long getPackedGitLimit() {
  87. return packedGitLimit;
  88. }
  89. /**
  90. * @param newLimit
  91. * maximum number bytes of heap memory to dedicate to caching
  92. * pack file data.
  93. */
  94. public void setPackedGitLimit(final long newLimit) {
  95. packedGitLimit = newLimit;
  96. }
  97. /**
  98. * @return size in bytes of a single window mapped or read in from the pack
  99. * file. <b>Default is 8 KB.</b>
  100. */
  101. public int getPackedGitWindowSize() {
  102. return packedGitWindowSize;
  103. }
  104. /**
  105. * @param newSize
  106. * size in bytes of a single window read in from the pack file.
  107. */
  108. public void setPackedGitWindowSize(final int newSize) {
  109. packedGitWindowSize = newSize;
  110. }
  111. /**
  112. * @return true enables use of Java NIO virtual memory mapping for windows;
  113. * false reads entire window into a byte[] with standard read calls.
  114. * <b>Default false.</b>
  115. */
  116. public boolean isPackedGitMMAP() {
  117. return packedGitMMAP;
  118. }
  119. /**
  120. * @param usemmap
  121. * true enables use of Java NIO virtual memory mapping for
  122. * windows; false reads entire window into a byte[] with standard
  123. * read calls.
  124. */
  125. public void setPackedGitMMAP(final boolean usemmap) {
  126. packedGitMMAP = usemmap;
  127. }
  128. /**
  129. * @return maximum number of bytes to cache in {@link DeltaBaseCache}
  130. * for inflated, recently accessed objects, without delta chains.
  131. * <b>Default 10 MB.</b>
  132. */
  133. public int getDeltaBaseCacheLimit() {
  134. return deltaBaseCacheLimit;
  135. }
  136. /**
  137. * @param newLimit
  138. * maximum number of bytes to cache in
  139. * {@link DeltaBaseCache} for inflated, recently accessed
  140. * objects, without delta chains.
  141. */
  142. public void setDeltaBaseCacheLimit(final int newLimit) {
  143. deltaBaseCacheLimit = newLimit;
  144. }
  145. /** @return the size threshold beyond which objects must be streamed. */
  146. public int getStreamFileThreshold() {
  147. return streamFileThreshold;
  148. }
  149. /**
  150. * @param newLimit
  151. * new byte limit for objects that must be streamed. Objects
  152. * smaller than this size can be obtained as a contiguous byte
  153. * array, while objects bigger than this size require using an
  154. * {@link org.eclipse.jgit.lib.ObjectStream}.
  155. */
  156. public void setStreamFileThreshold(final int newLimit) {
  157. streamFileThreshold = newLimit;
  158. }
  159. /**
  160. * Update properties by setting fields from the configuration.
  161. * <p>
  162. * If a property is not defined in the configuration, then it is left
  163. * unmodified.
  164. *
  165. * @param rc configuration to read properties from.
  166. */
  167. public void fromConfig(final Config rc) {
  168. setPackedGitOpenFiles(rc.getInt("core", null, "packedgitopenfiles", getPackedGitOpenFiles()));
  169. setPackedGitLimit(rc.getLong("core", null, "packedgitlimit", getPackedGitLimit()));
  170. setPackedGitWindowSize(rc.getInt("core", null, "packedgitwindowsize", getPackedGitWindowSize()));
  171. setPackedGitMMAP(rc.getBoolean("core", null, "packedgitmmap", isPackedGitMMAP()));
  172. setDeltaBaseCacheLimit(rc.getInt("core", null, "deltabasecachelimit", getDeltaBaseCacheLimit()));
  173. long maxMem = Runtime.getRuntime().maxMemory();
  174. long sft = rc.getLong("core", null, "streamfilethreshold", getStreamFileThreshold());
  175. sft = Math.min(sft, maxMem / 4); // don't use more than 1/4 of the heap
  176. sft = Math.min(sft, Integer.MAX_VALUE); // cannot exceed array length
  177. setStreamFileThreshold((int) sft);
  178. }
  179. }