Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/bluestore/BlueFS: only flush device which writed by file when do f… #14118

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/os/bluestore/BlueFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1380,10 +1380,13 @@ int BlueFS::_flush_and_sync_log(std::unique_lock<std::mutex>& l,
// drop lock while we wait for io
list<FS::aio_t> completed_ios;
_claim_completed_aios(log_writer, &completed_ios);

set<unsigned int> unsync_bdev = log_writer->unsync_bdev;
log_writer->unsync_bdev.clear();
l.unlock();
wait_for_aio(log_writer);
completed_ios.clear();
flush_bdev();
flush_bdev(unsync_bdev);
l.lock();

log_flushing = false;
Expand Down Expand Up @@ -1600,6 +1603,7 @@ int BlueFS::_flush_range(FileWriter *h, uint64_t offset, uint64_t length)
}
}
bdev[p->bdev]->aio_write(p->offset + x_off, t, h->iocv[p->bdev], buffered);
h->unsync_bdev.insert(p->bdev);
bloff += x_len;
length -= x_len;
++p;
Expand Down Expand Up @@ -1721,10 +1725,14 @@ int BlueFS::_fsync(FileWriter *h, std::unique_lock<std::mutex>& l)

list<FS::aio_t> completed_ios;
_claim_completed_aios(h, &completed_ios);

set<unsigned int> unsync_bdev = h->unsync_bdev;
h->unsync_bdev.clear();
lock.unlock();

wait_for_aio(h);
completed_ios.clear();
flush_bdev();
flush_bdev(unsync_bdev);
lock.lock();

if (old_dirty_seq) {
Expand All @@ -1748,6 +1756,16 @@ void BlueFS::flush_bdev()
}
}

void BlueFS::flush_bdev(set<unsigned int> &unsync_bdev)
{
// NOTE: this is safe to call without a lock.
dout(20) << __func__ << dendl;
for (auto p : unsync_bdev) {
assert(p < MAX_BDEV && bdev[p] != NULL);
bdev[p]->flush();
}
}

int BlueFS::_allocate(uint8_t id, uint64_t len,
mempool::bluefs::vector<bluefs_extent_t> *ev)
{
Expand Down
3 changes: 2 additions & 1 deletion src/os/bluestore/BlueFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class BlueFS {

std::mutex lock;
std::array<IOContext*,MAX_BDEV> iocv; ///< for each bdev

set<unsigned int> unsync_bdev; ///< write but unsync bdev recently
FileWriter(FileRef f)
: file(f),
pos(0),
Expand Down Expand Up @@ -288,6 +288,7 @@ class BlueFS {
//void _aio_finish(void *priv);

void flush_bdev(); // this is safe to call without a lock
void flush_bdev(set<unsigned int> &unsync_bdev); // only flush bdev in this set

int _preallocate(FileRef f, uint64_t off, uint64_t len);
int _truncate(FileWriter *h, uint64_t off);
Expand Down