aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java
diff options
context:
space:
mode:
authorGravatar Eric Fellheimer <felly@google.com>2015-08-31 22:54:53 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-09-01 00:21:05 +0000
commit5c54bdcc5b6d686687120b19be710d08e5186da8 (patch)
tree24ad24797bc65bb4ae6da0389895a8b387c0702b /src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java
parent663f7c4ab9cfa4cb68f4f8ef83be7a66d1634da5 (diff)
Allow for customization of the per-build system call caches used in Skyframe.
-- MOS_MIGRATED_REVID=101984361
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java
index 5116a6ff64..2d05fd8e47 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java
@@ -29,15 +29,29 @@ import java.util.Collection;
/**
* A per-build cache of filesystem operations for Skyframe invocations of legacy package loading.
*/
-class PerBuildSyscallCache implements UnixGlob.FilesystemCalls {
+public class PerBuildSyscallCache implements UnixGlob.FilesystemCalls {
- private final LoadingCache<Pair<Path, Symlinks>, FileStatus> statCache =
- newStatMap();
+ private final LoadingCache<Pair<Path, Symlinks>, FileStatus> statCache;
private final LoadingCache<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>>
- readdirCache = newReaddirMap();
+ readdirCache;
private static final FileStatus NO_STATUS = new FakeFileStatus();
+ /**
+ * Create a new per-build filesystem cache.
+ *
+ * @param maxStats Max stat results to keep in cache, or -1 for unbounded.
+ * @param maxReaddirs Max readdir results to keep in cache, or -1 for unbounded.
+ */
+ public PerBuildSyscallCache(int maxStats, int maxReaddirs) {
+ statCache = newStatMap(maxStats);
+ readdirCache = newReaddirMap(maxReaddirs);
+ }
+
+ public static PerBuildSyscallCache newUnboundedCache() {
+ return new PerBuildSyscallCache(-1, -1);
+ }
+
@Override
public Collection<Dirent> readdir(Path path, Symlinks symlinks) throws IOException {
Pair<Collection<Dirent>, IOException> result =
@@ -98,8 +112,8 @@ class PerBuildSyscallCache implements UnixGlob.FilesystemCalls {
* Input: (path, following_symlinks)
* Output: FileStatus
*/
- private static LoadingCache<Pair<Path, Symlinks>, FileStatus> newStatMap() {
- return CacheBuilder.newBuilder().build(
+ private static LoadingCache<Pair<Path, Symlinks>, FileStatus> newStatMap(int maxStats) {
+ return builderWithOptionalMax(maxStats).build(
new CacheLoader<Pair<Path, Symlinks>, FileStatus>() {
@Override
public FileStatus load(Pair<Path, Symlinks> p) {
@@ -115,12 +129,15 @@ class PerBuildSyscallCache implements UnixGlob.FilesystemCalls {
* Output: A union of (Dirents, IOException).
*/
private static
- LoadingCache<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>> newReaddirMap() {
- return CacheBuilder.newBuilder().build(
+ LoadingCache<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>> newReaddirMap(
+ int maxReaddirs) {
+ return builderWithOptionalMax(maxReaddirs).build(
new CacheLoader<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>>() {
@Override
public Pair<Collection<Dirent>, IOException> load(Pair<Path, Symlinks> p) {
try {
+ // TODO(bazel-team): Consider storing the Collection of Dirent values more compactly
+ // by reusing DirectoryEntryListingStateValue#CompactSortedDirents.
return Pair.of(p.first.readdir(p.second), null);
} catch (IOException e) {
return Pair.of(null, e);
@@ -128,4 +145,12 @@ class PerBuildSyscallCache implements UnixGlob.FilesystemCalls {
}
});
}
+
+ private static CacheBuilder<Object, Object> builderWithOptionalMax(int maxEntries) {
+ CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
+ if (maxEntries >= 0) {
+ builder = builder.maximumSize(maxEntries);
+ }
+ return builder;
+ }
}