Skip to content

os/bluestore: Blazingly fast new BlueFS WAL disk format 🚀 #56927

Closed
pereman2 wants to merge 4 commits intoceph:mainfrom
pereman2:wal-fsync
Closed

os/bluestore: Blazingly fast new BlueFS WAL disk format 🚀 #56927
pereman2 wants to merge 4 commits intoceph:mainfrom
pereman2:wal-fsync

Conversation

@pereman2
Copy link
Contributor

@pereman2 pereman2 commented Apr 16, 2024

problem

BlueFS write are expensive due to every BlueFS::fsync invoking disk->flush twice, one for the file data and another one for BlueFS log metadata. We can avoid this duality by joining merging metadata and data in the same envelope. This PR delievers on that front.

New format

Previous a bluefs log transaction would hold a file_update_inc that includes the increase of file size, that way we now what is the length of data the file hold in its own extents. Therefore, every write would perform a fnode->size += delta and consequently mark it as dirty.

This new format is basically a envelope that holds both data and delta metadata plus some error detection stuff:

  • Flush length (u64) -> the length of the data in the envelope
  • Payload (flush length) -> data of the WAL write asked for (size is flush length)
  • Marker (u64) -> id of the file used for error detection (this in talks to change to crc or something else)

With this new format, for every fsync we do, create this envelope and flush it without marking the file as dirty, therefore not generating the log disk flush. This inferred huge benefits in performance that will be looking at next.

EOF tricks

A "huge" problem is: how do we know we cannot read more data from the file. Either we reach end of allocated extents or... in this case we append some 0s to the evenlope so that next flush_length is overwritten and therefore we can check if next flush is not yet flushed to disk. This basically works like a null terminated string.

Preliminary results:

I ran multiple fio jobs including different workloads: randrw, random writes, random reads, etc...

image

image

By counting number of flushes with a simple counter vs a vector of flush extents we saw a significat performance degradation that might be worth to use the vector only in replay and forget about storing flush extents during the run:
image

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@pereman2 pereman2 requested review from aclamk and ifed01 April 16, 2024 16:34
@pereman2 pereman2 changed the title os/bluestore: new BlueFS WAL disk format os/bluestore: Blazingly fast new BlueFS WAL disk format 🚀 Apr 17, 2024
vselector->get_hint_by_dir(dirname);
vselector->add_usage(file->vselector_hint, file->fnode);

if (boost::algorithm::ends_with(filename, ".log")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ends_with() is now part of c++ (since c++20, which we are using)

bufferlist t;
t.substr_of(buf.bl, flush_offset - buf.bl_off, sizeof(File::WALFlush::WALLength));
dout(30) << "length dump\n";
t.hexdump(*_dout);
Copy link
Contributor

Choose a reason for hiding this comment

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

are we OK with log lines like this one, without the preamble?

}
}

int64_t BlueFS::_read_wal(
Copy link
Contributor

Choose a reason for hiding this comment

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

a style/pref comment: this is a pretty long function. Can it be broken down into logical, named, sub-functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might abstract some parts that are reused in different places but imho I prefer reading from top to bottom what this function does instead of going to defitinition in functions.

@markhpc
Copy link
Member

markhpc commented Apr 22, 2024

@pereman2 I was very excited about your PR, and did some librbd fio testing on mako over the weekend. These are relatively fast NVMe drives so I'm not sure how limited they are by fsync (which should be a no-op for the drive, but still require the syscall). I suspect we may see better numbers as other bottlenecks are eliminated. It would be very interesting however to see how this performs on consumer grade flash and HDDs.

Here are the results:

Single NVMe OSD 4K Random Write (1X)

Ceph Version IOPS Avg Latency (ms) 99.9% Latency (ms) ceph-osd CPU Usage %
v18.2.2 94030 16.49 301.73 1508
main 94445 16.58 333.71 1538
main + #56927 97048 16.02 321.56 1561

30 NVMe OSD 4K Random Write (3X)

Ceph Version IOPS Avg Latency (ms) 99.9% Latency (ms) ceph-osd CPU Usage % (mako06)
v18.2.2 476575 13.46 385.54 1051
main 465904 13.76 322.02 1068
main + #56927 469424 13.88 410.33 1098

@pereman2
Copy link
Contributor Author

Here are the results:

Oh cool! I wonder the difference between our nvmes used are.

If you are up for it, I will update the code removing some obvious inefficiencies that might have an effect on CPU, and you may run it again to see if it did fix something. Nevertheless I will attach my results again after that fix

@pereman2
Copy link
Contributor Author

pereman2 commented Apr 22, 2024

@markhpc I'm curious. How many times did you run the 4k randwrite benchmark? Did you pre fill the cluster to simulated some real data or was it ran in a real cluster?
My benchmark basically does:

iterations = 8
bssplit = "--bssplit=4k/16:8k/10:12k/9:16k/8:20k/7:24k/7:28k/6:32k/6:36k/5:40k/5:44k/4:48k/4:52k/4:56k/3:60k/3:64k/3"
for run in range(iterations):
  for t in ['randrw', 'randwrite', 'randread', 'rw']:
     # do fio test with "t"

@pereman2
Copy link
Contributor Author

@markhpc I got new results! Looks like randwrites are not getting any better somehow but randrw do get better:

randwrite 1 host 3 osds bssplit
randrw 1 host 3 osds bssplit

@markhpc
Copy link
Member

markhpc commented Apr 22, 2024

@markhpc I'm curious. How many times did you run the 4k randwrite benchmark? Did you pre fill the cluster to simulated some real data or was it ran in a real cluster? My benchmark basically does:

iterations = 8
bssplit = "--bssplit=4k/16:8k/10:12k/9:16k/8:20k/7:24k/7:28k/6:32k/6:36k/5:40k/5:44k/4:48k/4:52k/4:56k/3:60k/3:64k/3"
for run in range(iterations):
  for t in ['randrw', 'randwrite', 'randread', 'rw']:
     # do fio test with "t"

Yep, these are prefilled rbd volumes. Only ran the set of tests for one iteration this time. 4k and 4m randreads and randwrites for 5 minutes. It's pretty easy to run repeated tests though if we want.

@mheler
Copy link
Contributor

mheler commented Apr 23, 2024

@markhpc I'm curious. How many times did you run the 4k randwrite benchmark? Did you pre fill the cluster to simulated some real data or was it ran in a real cluster? My benchmark basically does:

iterations = 8
bssplit = "--bssplit=4k/16:8k/10:12k/9:16k/8:20k/7:24k/7:28k/6:32k/6:36k/5:40k/5:44k/4:48k/4:52k/4:56k/3:60k/3:64k/3"
for run in range(iterations):
  for t in ['randrw', 'randwrite', 'randread', 'rw']:
     # do fio test with "t"

Yep, these are prefilled rbd volumes. Only ran the set of tests for one iteration this time. 4k and 4m randreads and randwrites for 5 minutes. It's pretty easy to run repeated tests though if we want.

Was the NVMe drive pre-filled? That's actually going to matter more than the rbd volumes.

@pereman2
Copy link
Contributor Author

@markhpc I'm curious. How many times did you run the 4k randwrite benchmark? Did you pre fill the cluster to simulated some real data or was it ran in a real cluster? My benchmark basically does:

iterations = 8
bssplit = "--bssplit=4k/16:8k/10:12k/9:16k/8:20k/7:24k/7:28k/6:32k/6:36k/5:40k/5:44k/4:48k/4:52k/4:56k/3:60k/3:64k/3"
for run in range(iterations):
  for t in ['randrw', 'randwrite', 'randread', 'rw']:
     # do fio test with "t"

Yep, these are prefilled rbd volumes. Only ran the set of tests for one iteration this time. 4k and 4m randreads and randwrites for 5 minutes. It's pretty easy to run repeated tests though if we want.

Was the NVMe drive pre-filled? That's actually going to matter more than the rbd volumes.

Yes!

@pereman2 pereman2 marked this pull request as ready for review April 29, 2024 14:03
@pereman2 pereman2 requested a review from a team as a code owner April 29, 2024 14:03
@markhpc
Copy link
Member

markhpc commented May 1, 2024

@markhpc I'm curious. How many times did you run the 4k randwrite benchmark? Did you pre fill the cluster to simulated some real data or was it ran in a real cluster? My benchmark basically does:

iterations = 8
bssplit = "--bssplit=4k/16:8k/10:12k/9:16k/8:20k/7:24k/7:28k/6:32k/6:36k/5:40k/5:44k/4:48k/4:52k/4:56k/3:60k/3:64k/3"
for run in range(iterations):
  for t in ['randrw', 'randwrite', 'randread', 'rw']:
     # do fio test with "t"

Yep, these are prefilled rbd volumes. Only ran the set of tests for one iteration this time. 4k and 4m randreads and randwrites for 5 minutes. It's pretty easy to run repeated tests though if we want.

Was the NVMe drive pre-filled? That's actually going to matter more than the rbd volumes.

Naw, this was a quick test. I was curious what kind of syscall overhead reduction we might see here versus other previous tests where I can see some overhead for 4k random writes. We could certainly do tests at larger fill values though.

@pereman2 pereman2 force-pushed the wal-fsync branch 2 times, most recently from 72dc822 to 7e436c8 Compare May 9, 2024 15:57
enum bluefs_node_type {
LEGACY = 0,
WAL_V2 = 1,
NODE_TYPE_END = 0x100,
Copy link
Contributor

Choose a reason for hiding this comment

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

NODE_TYPE_END is 2 currently.
We can move it up if more types appear.

while(flush_offset < file->fnode.allocated) {
// read first part of wal flush
bufferlist bl;
_read(h, flush_offset, sizeof(File::WALFlush::WALLength), &bl, nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is bad.
FileReader will redirect reading to _read_wal, that is already trying to cut envelope out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I treat _read as read raw data, fnode.size includes all extra envelope data. BlueFS::read is the one that redirect to _read or _read_wal.

@pereman2 pereman2 force-pushed the wal-fsync branch 2 times, most recently from 9cbc2a3 to 51fefc7 Compare July 31, 2024 10:24
@ifed01
Copy link
Contributor

ifed01 commented Jul 31, 2024

jenkins test make check

// Ensure no dangling wal v2 files are inside transactions.
_compact_log_sync_LNF_LD();

_write_super(BDEV_DB, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

s/true/1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahg, should've been compile time error thanks for pointing it out

// Ensure no dangling wal v2 files are inside transactions.
_compact_log_sync_LNF_LD();

_write_super(BDEV_DB, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is downgrade to 1, version shouldn't be 2 then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not by brightest day

@ifed01
Copy link
Contributor

ifed01 commented Jul 31, 2024

jenkins test make

@ifed01
Copy link
Contributor

ifed01 commented Jul 31, 2024

jenkins test make check

@aclamk aclamk added the aclamk-testing-nauvoo bluestore testing label Jul 31, 2024
@aclamk
Copy link
Contributor

aclamk commented Aug 6, 2024

jenkins test make check

@github-actions
Copy link

github-actions bot commented Aug 7, 2024

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
@github-actions
Copy link

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions bot added the stale label Nov 24, 2024
@github-actions
Copy link

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions bot closed this Dec 24, 2024
@aclamk aclamk mentioned this pull request Mar 11, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants