mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Use fallocate to prevent excessive allocation of sst files and logs
Summary: On some filesystems, pre-allocation can be a considerable amount of space. xfs in our production environment pre-allocates by 1GB, for instance. By using fallocate to inform the kernel of our expected file sizes, we eliminate this wasteage (that isn't recovered until the file is closed which, in the case of LOG files, can be a considerable amount of time). Test Plan: created an xfs loopback filesystem, mounted with allocsize=4M, and ran db_stress. LOG file without this change was 4M, and with it it was 128k then grew to normal size. Reviewers: dhruba Reviewed By: dhruba CC: adsharma, leveldb Differential Revision: https://reviews.facebook.net/D7953
This commit is contained in:
@@ -524,6 +524,35 @@ TEST(DBTest, ReadWrite) {
|
||||
} while (ChangeOptions());
|
||||
}
|
||||
|
||||
TEST(DBTest, Preallocation) {
|
||||
const std::string src = dbname_ + "/alloc_test";
|
||||
unique_ptr<WritableFile> srcfile;
|
||||
ASSERT_OK(env_->NewWritableFile(src, &srcfile));
|
||||
srcfile->SetPreallocationBlockSize(1024 * 1024);
|
||||
|
||||
// No writes should mean no preallocation
|
||||
size_t block_size, last_allocated_block;
|
||||
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
|
||||
ASSERT_EQ(last_allocated_block, 0UL);
|
||||
|
||||
// Small write should preallocate one block
|
||||
srcfile->Append("test");
|
||||
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
|
||||
ASSERT_EQ(last_allocated_block, 1UL);
|
||||
|
||||
// Write an entire preallocation block, make sure we increased by two.
|
||||
std::string buf(block_size, ' ');
|
||||
srcfile->Append(buf);
|
||||
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
|
||||
ASSERT_EQ(last_allocated_block, 2UL);
|
||||
|
||||
// Write five more blocks at once, ensure we're where we need to be.
|
||||
buf = std::string(block_size * 5, ' ');
|
||||
srcfile->Append(buf);
|
||||
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
|
||||
ASSERT_EQ(last_allocated_block, 7UL);
|
||||
}
|
||||
|
||||
TEST(DBTest, PutDeleteGet) {
|
||||
do {
|
||||
ASSERT_OK(db_->Put(WriteOptions(), "foo", "v1"));
|
||||
|
||||
Reference in New Issue
Block a user