Skip to content

Commit c66ea5f

Browse files
benlangmuircachemeifyoucan
authored andcommitted
[cas] Automatically use smaller CAS files on macOS tmpfs
macOS tmpfs does not support sparse file tails, leading to out-of-space issues when using our default large maximum mapped file sizes in the CAS. When using tmpfs switch to 1 GB index/cache and 2 GB data pool. rdar://113036612
1 parent 5c0d283 commit c66ea5f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

llvm/lib/CAS/OnDiskGraphDB.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
#include "llvm/Support/Process.h"
6161
#include <optional>
6262

63+
#if __has_include(<sys/mount.h>)
64+
#include <sys/mount.h> // statfs
65+
#endif
66+
6367
#define DEBUG_TYPE "on-disk-cas"
6468

6569
using namespace llvm;
@@ -1346,6 +1350,22 @@ size_t OnDiskGraphDB::getStorageSize() const {
13461350
return Index.size() + DataPool.size() + getStandaloneStorageSize();
13471351
}
13481352

1353+
static bool useSmallMappedFiles(const Twine &P) {
1354+
// macOS tmpfs does not support sparse tails.
1355+
#if defined(__APPLE__) && __has_include(<sys/mount.h>)
1356+
SmallString<128> PathStorage;
1357+
StringRef Path = P.toNullTerminatedStringRef(PathStorage);
1358+
struct statfs StatFS;
1359+
if (statfs(Path.data(), &StatFS) != 0)
1360+
return false;
1361+
1362+
if (strcmp(StatFS.f_fstypename, "tmpfs") == 0)
1363+
return true;
1364+
#endif
1365+
1366+
return false;
1367+
}
1368+
13491369
Expected<std::unique_ptr<OnDiskGraphDB>> OnDiskGraphDB::open(
13501370
StringRef AbsPath, StringRef HashName, unsigned HashByteSize,
13511371
std::unique_ptr<OnDiskGraphDB> UpstreamDB, FaultInPolicy Policy) {
@@ -1359,6 +1379,11 @@ Expected<std::unique_ptr<OnDiskGraphDB>> OnDiskGraphDB::open(
13591379
uint64_t MaxIndexSize = 8 * GB;
13601380
uint64_t MaxDataPoolSize = 16 * GB;
13611381

1382+
if (useSmallMappedFiles(AbsPath)) {
1383+
MaxIndexSize = 1 * GB;
1384+
MaxDataPoolSize = 2 * GB;
1385+
}
1386+
13621387
auto CustomSize = getOverriddenMaxMappingSize();
13631388
if (!CustomSize)
13641389
return CustomSize.takeError();

0 commit comments

Comments
 (0)