From de7b26acfdfcd9c36ec957305a889ac29f0da30e Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 2 Dec 2022 14:26:11 -0800 Subject: [PATCH] Restrict syscall caching to paths backed by the build's main `FileSystem`. Avoids wasteful caching of in-memory and transient `FileSystem` types. PiperOrigin-RevId: 492560997 Change-Id: I19865c33f91566fb101c98508fe8897f9ad115f5 --- .../build/lib/runtime/WorkspaceBuilder.java | 11 +- .../lib/vfs/SingleFileSystemSyscallCache.java | 101 ++++++++++++++++++ 2 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/vfs/SingleFileSystemSyscallCache.java diff --git a/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java b/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java index e1a6244b4b01f0..f4fcabc377d8aa 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/WorkspaceBuilder.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.skyframe.SkyframeExecutorFactory; import com.google.devtools.build.lib.skyframe.SkyframeExecutorRepositoryHelpersHolder; import com.google.devtools.build.lib.util.AbruptExitException; +import com.google.devtools.build.lib.vfs.SingleFileSystemSyscallCache; import com.google.devtools.build.lib.vfs.SyscallCache; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -96,7 +97,8 @@ public static PerBuildSyscallCache createPerBuildSyscallCache() { BlazeWorkspace build( BlazeRuntime runtime, PackageFactory packageFactory, - SubscriberExceptionHandler eventBusExceptionHandler) throws AbruptExitException { + SubscriberExceptionHandler eventBusExceptionHandler) + throws AbruptExitException { // Set default values if none are set. if (skyframeExecutorFactory == null) { skyframeExecutorFactory = new SequencedSkyframeExecutorFactory(); @@ -105,6 +107,9 @@ BlazeWorkspace build( perCommandSyscallCache = createPerBuildSyscallCache(); } + SingleFileSystemSyscallCache singleFsSyscallCache = + new SingleFileSystemSyscallCache(perCommandSyscallCache, runtime.getFileSystem()); + SkyframeExecutor skyframeExecutor = skyframeExecutorFactory.create( packageFactory, @@ -114,7 +119,7 @@ BlazeWorkspace build( workspaceStatusActionFactory, diffAwarenessFactories.build(), skyFunctions.buildOrThrow(), - perCommandSyscallCache, + singleFsSyscallCache, skyframeExecutorRepositoryHelpersHolder, skyKeyStateReceiver == null ? SkyframeExecutor.SkyKeyStateReceiver.NULL_INSTANCE @@ -128,7 +133,7 @@ BlazeWorkspace build( workspaceStatusActionFactory, binTools, allocationTracker, - perCommandSyscallCache); + singleFsSyscallCache); } /** diff --git a/src/main/java/com/google/devtools/build/lib/vfs/SingleFileSystemSyscallCache.java b/src/main/java/com/google/devtools/build/lib/vfs/SingleFileSystemSyscallCache.java new file mode 100644 index 00000000000000..9befa7f1e9741f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/vfs/SingleFileSystemSyscallCache.java @@ -0,0 +1,101 @@ +// Copyright 2022 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.vfs; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.io.IOException; +import java.util.Collection; +import javax.annotation.Nullable; + +/** + * A {@link SyscallCache} that delegates to a caching implementation only for paths with a + * particular {@link FileSystem}. + * + *

Any calls that pass a {@link Path} backed by a different {@link FileSystem} are routed to + * {@link SyscallCache#NO_CACHE}. This can be used to ensure that only calls for the build's main + * {@link FileSystem} are cached. Common alternative filesystems for which caching is wasteful + * include: + * + *