Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions util/fibers/uring_file_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,46 @@ TEST_F(UringFileTest, FSync) {
});
}

TEST_F(UringFileTest, FAllocate) {
string path = base::GetTestTempPath("1.log");
proactor_->Await([this, path] {
auto res = OpenLinux(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
ASSERT_TRUE(res);
LinuxFile* wf = (*res).get();

struct statx stat;
auto ec = StatX(path.c_str(), &stat, wf->fd());
ASSERT_FALSE(ec);
// File size remained zero even if we allocated block size
ASSERT_EQ(stat.stx_size, 0);
const off_t fsize = 128 * 1024 * 1024; // 128 MB

{
util::fb2::FiberCall fc(proactor_.get());
fc->PrepFallocate(wf->fd(), FALLOC_FL_KEEP_SIZE, 0, fsize);
FiberCall::IoResult io_res = fc.Get();
ASSERT_EQ(io_res, 0);
}

ec = StatX(path.c_str(), &stat, wf->fd());
ASSERT_FALSE(ec);
ASSERT_EQ(stat.stx_size, 0);
ASSERT_NE(stat.stx_blocks, 0);

const int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
util::fb2::FiberCall fc(proactor_.get());
fc->PrepFallocate(wf->fd(), mode, 0, fsize);
FiberCall::IoResult io_res = fc.Get();
ASSERT_EQ(io_res, 0);

ec = StatX(path.c_str(), &stat, wf->fd());
ASSERT_FALSE(ec);
ASSERT_EQ(stat.stx_size, 0);
ASSERT_EQ(stat.stx_blocks, 0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fires but I don't understand why 🤔

const int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;

Means that we will punch a hole on all the blocks so at least we should see a reduction yet it does not change at all 🤔

Based on my understanding, PUCH_HOLE is not hint meaning that we should see a reduction in block size

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know but I would first use fallocate + stat shell commands and play with them. no need to write code to explore their behavior


ASSERT_FALSE(wf->Close());
});
}

} // namespace fb2
} // namespace util
Loading