Skip to content

Commit

Permalink
Disable COW for SSD checkpoint and evictlog files
Browse files Browse the repository at this point in the history
Summary:
On btrfs overwriting file's blocks causes file system to allocate more
and more new blocks, eventually taking the whole disk space, while the
file is being only fraction of it.
'copy on write' is already disabled for SSD cache file to prevent the
issue. It is also needed for checkpoint files and evictlog files.

Reviewed By: xiaoxmeng

Differential Revision: D56777422

fbshipit-source-id: d8e4e7a742acad9f9ce7e87a1ffa61f04a6423fa
  • Loading branch information
zacw7 authored and facebook-github-bot committed May 1, 2024
1 parent 6b0cb0f commit 0902f1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion velox/common/caching/SsdFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ SsdFile::SsdFile(
folly::Executor* executor)
: fileName_(filename),
maxRegions_(maxRegions),
disableFileCow_(disableFileCow),
shardId_(shardId),
checkpointIntervalBytes_(checkpointIntervalBytes),
executor_(executor) {
Expand All @@ -155,7 +156,7 @@ SsdFile::SsdFile(
filename,
folly::errnoStr(errno));

if (disableFileCow) {
if (disableFileCow_) {
disableCow(fd_);
}

Expand Down Expand Up @@ -790,6 +791,11 @@ void SsdFile::checkpoint(bool force) {
const auto checkpointFd = checkRc(
::open(checkpointPath.c_str(), O_WRONLY),
"Open of checkpoint file for sync");
// TODO: add this as file open option after we migrate to use velox
// filesystem for ssd file access.
if (disableFileCow_) {
disableCow(checkpointFd);
}
VELOX_CHECK_GE(checkpointFd, 0);
checkRc(::fsync(checkpointFd), "Sync of checkpoint file");
::close(checkpointFd);
Expand Down Expand Up @@ -822,6 +828,9 @@ void SsdFile::initializeCheckpoint() {
}
const auto logPath = fileName_ + kLogExtension;
evictLogFd_ = ::open(logPath.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (disableFileCow_) {
disableCow(evictLogFd_);
}
if (evictLogFd_ < 0) {
++stats_.openLogErrors;
// Failure to open the log at startup is a process terminating error.
Expand Down
3 changes: 3 additions & 0 deletions velox/common/caching/SsdFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ class SsdFile {
// Maximum size of the backing file in kRegionSize units.
const int32_t maxRegions_;

// True if copy on write should be disabled.
const bool disableFileCow_;

// Serializes access to all private data members.
mutable std::shared_mutex mutex_;

Expand Down

0 comments on commit 0902f1d

Please sign in to comment.