[llvm] [Support][Caching] Don't use `mmap` in `localCache`, on NFS (PR #220936)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 00:21:11 PDT 2026
https://github.com/jmmartinez updated https://github.com/llvm/llvm-project/pull/220936
>From 92dd65f09773d98e360bddc7025a3ee4c632c57b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?=
<jmartinezcaamao at gmail.com>
Date: Wed, 24 Jun 2026 13:39:24 +0200
Subject: [PATCH 1/3] [Support][Caching] Don't use `mmap` in `localCache`, on
NFS
When the cache directory is on an NFS, we may hit a SIGBUS signal
when there is contention on the cache.
This happens typically with MPI jobs running on an NFS mounted $HOME
directory.
If we execute through the regular `read()` path, we also fail with a
`Stale file descriptor` error. But at least this path is properly handled
and we can continue without using the cache.
To achieve this, we pass `OnNFS` to `IsVolatile` and `RequiresNullTerminator`,
which makes `shouldUseMmap` return `false`.
---
llvm/lib/Support/Caching.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 5f801e1c21142d..a59bfaf380e522 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -38,6 +38,8 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
TempFilePrefixRef.toVector(TempFilePrefix);
CacheDirectoryPathRef.toVector(CacheDirectoryPath);
+ bool OnNFS = !sys::fs::is_local(CacheDirectoryPath);
+
auto Func = [=](unsigned Task, StringRef Key,
const Twine &ModuleName) -> Expected<AddStreamFn> {
// This choice of file name allows the cache to be pruned (see pruneCache()
@@ -53,7 +55,8 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
MemoryBuffer::getOpenFile(*FDOrErr, EntryPath,
/*FileSize=*/-1,
- /*RequiresNullTerminator=*/false);
+ /*RequiresNullTerminator=*/OnNFS,
+ /*IsVolatile=*/OnNFS);
sys::fs::closeFile(*FDOrErr);
if (MBOrErr) {
AddBuffer(Task, ModuleName, std::move(*MBOrErr));
>From 691b2a15ee52d97da297244d1a898f9e54d19182 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?=
<jmartinezcaamao at gmail.com>
Date: Mon, 7 Sep 2026 10:46:33 +0200
Subject: [PATCH 2/3] review: OnNFS -> IsNFS
---
llvm/lib/Support/Caching.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index a59bfaf380e522..694c48d8c88907 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -38,7 +38,7 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
TempFilePrefixRef.toVector(TempFilePrefix);
CacheDirectoryPathRef.toVector(CacheDirectoryPath);
- bool OnNFS = !sys::fs::is_local(CacheDirectoryPath);
+ bool IsNFS = !sys::fs::is_local(CacheDirectoryPath);
auto Func = [=](unsigned Task, StringRef Key,
const Twine &ModuleName) -> Expected<AddStreamFn> {
@@ -55,8 +55,8 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
MemoryBuffer::getOpenFile(*FDOrErr, EntryPath,
/*FileSize=*/-1,
- /*RequiresNullTerminator=*/OnNFS,
- /*IsVolatile=*/OnNFS);
+ /*RequiresNullTerminator=*/IsNFS,
+ /*IsVolatile=*/IsNFS);
sys::fs::closeFile(*FDOrErr);
if (MBOrErr) {
AddBuffer(Task, ModuleName, std::move(*MBOrErr));
>From 6b9916eca6ee2115bd9754fae4aef0865304200f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?=
<jmartinezcaamao at gmail.com>
Date: Mon, 7 Sep 2026 11:11:31 +0200
Subject: [PATCH 3/3] review: sink is_local condition to ensure the cache
directory path is already created
---
llvm/lib/Support/Caching.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 694c48d8c88907..abfba54e7a334c 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -38,8 +38,6 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
TempFilePrefixRef.toVector(TempFilePrefix);
CacheDirectoryPathRef.toVector(CacheDirectoryPath);
- bool IsNFS = !sys::fs::is_local(CacheDirectoryPath);
-
auto Func = [=](unsigned Task, StringRef Key,
const Twine &ModuleName) -> Expected<AddStreamFn> {
// This choice of file name allows the cache to be pruned (see pruneCache()
@@ -52,6 +50,7 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
Twine(EntryPath), sys::fs::OF_UpdateAtime, &ResultPath);
std::error_code EC;
if (FDOrErr) {
+ bool IsNFS = !sys::fs::is_local(CacheDirectoryPath);
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
MemoryBuffer::getOpenFile(*FDOrErr, EntryPath,
/*FileSize=*/-1,
More information about the llvm-commits
mailing list