Skip to content

common/options: bluefs_buffered_io=true by default - #38044

Merged
neha-ojha merged 1 commit into
ceph:masterfrom
dvanders:dvanders_buffered
Mar 25, 2021
Merged

neha-ojha merged 1 commit into
ceph:masterfrom
dvanders:dvanders_buffered

Conversation

@dvanders

@dvanders dvanders commented Nov 12, 2020 •

Copy link
Copy Markdown
Contributor

Enable bluefs_buffered_io again because it makes a huge user-visible
improvement in metadata intensive scenarios, such as but not limited to
PG deletion.

In our environment, deleting PGs from 4 hybrid OSDs (sharing one SATA SSD block.db) saturates
the block.db at 350MB/s reads and causes slow reqs and flapping on the OSDs.
Those OSDs have 3GB osd_target_memory.

Enabling bluefs_buffered_io drops the SSD IO down to <1MBps and the OSDs
are performant again. (The underlying PG deletion inefficiency is being
solved separately, but the page cache is so much more effective than
the bluestore cache in this scenario).

Lastly, remove the comment about swap. We should separately advise
operators to disable swap on OSD machines, as it is much better in
our experience to OOM and restart than to chug along swapping.

Signed-off-by: Dan van der Ster [email protected]
Related-to: https://tracker.ceph.com/issues/45765
Related-to: https://tracker.ceph.com/issues/47044

@dvanders

Copy link
Copy Markdown
Contributor Author

(I re-pushed with the swap comment fully removed).

Enable bluefs_buffered_io again because it makes a huge user-visible
improvement in metadata intensive scenarios, such as but not limited to
PG deletion.

In our environment, deleting PGs from 4 hybrid OSDs (sharing one SATA SSD block.db) saturates
the block.db at 350MB/s reads and causes slow reqs and flapping on the OSDs.
Those OSDs have 3GB osd_target_memory.
Enabling bluefs_buffered_io drops the SSD IO down to <1MBps and the OSDs
are performant again. (The underlying PG deletion inefficiency is being
solved separately, but the page cache is so much more effective than
the bluestore cache in this scenario).

Lastly, remove the comment about swap. We should separately advise
operators to disable swap on OSD machines, as it is much better in
our experience to OOM and restart than to chug along swapping.

Signed-off-by: Dan van der Ster <[email protected]>
Related-to: https://tracker.ceph.com/issues/45765
Related-to: https://tracker.ceph.com/issues/47044
@ifed01

ifed01 commented Nov 16, 2020

Copy link
Copy Markdown
Contributor

Given multiple back-and-forth iterations on this parameter (previous one is at #34224) IMO it makes sense to have a more formal process behind this modification. E.g. this should include complete scenario's description, lab H/W and resulting numbers in a way this is reproducible by somebody else.
Rationales from the previous PR to be dealt somehow as well. @markhpc - can we have detailed benchmarking scenarios/numbers from your side as well?

@ifed01

ifed01 commented Nov 16, 2020

Copy link
Copy Markdown
Contributor

@dvanders - additionally I'm curious wouldn't #37314 be a good enough replacement for this PR. At least for removal scenarios....

@dvanders

Copy link
Copy Markdown
Contributor Author

Given multiple back-and-forth iterations on this parameter (previous one is at #34224) IMO it makes sense to have a more formal process behind this modification. E.g. this should include complete scenario's description, lab H/W and resulting numbers in a way this is reproducible by somebody else.

Right, I agree, and I can work on a reproducer: the basic idea is to add a PG with ~200000 small objects to a hybrid OSD (hdd + sata ssd), then delete that PG. The ssd's IO should saturate when buffered_io=false, and will be ~nil in with buffered_io=true.

TBH, I'm trying to provoke this discussion because by experience the impact of the option was shown to be dramatic in two independent clusters we run (both while migrating to new hw): one S3 cluster, one CephFS cluster. For each of those clusters, when bluefs_buffered_io was false (v14.2.11), the result was that the draining OSDs became totally unstable while deleting PGs and the clusters nearly went down.

Even if you don't want to enable it by default anymore, IMHO the impact of the option can be so large that we should at least regularly check/qa test with bluefs_buffered_io = true so that we can be confident that there are no bugs when it is enabled. (Maybe we should add a bluefs_buffered_io = random setting for testing?)

@dvanders - additionally I'm curious wouldn't #37314 be a good enough replacement for this PR. At least for removal scenarios....

I very much look forward to that PR being merged, thank you :) But I just find it unlikely that this is the only place that the page cache is speeding up OSD operations. We normally have spare memory on a server -- why not use it?

@ifed01

ifed01 commented Nov 16, 2020

Copy link
Copy Markdown
Contributor

Given multiple back-and-forth iterations on this parameter (previous one is at #34224) IMO it makes sense to have a more formal process behind this modification. E.g. this should include complete scenario's description, lab H/W and resulting numbers in a way this is reproducible by somebody else.

Right, I agree, and I can work on a reproducer: the basic idea is to add a PG with ~200000 small objects to a hybrid OSD (hdd + sata ssd), then delete that PG. The ssd's IO should saturate when buffered_io=false, and will be ~nil in with buffered_io=true.

TBH, I'm trying to provoke this discussion because by experience the impact of the option was shown to be dramatic in two independent clusters we run (both while migrating to new hw): one S3 cluster, one CephFS cluster. For each of those clusters, when bluefs_buffered_io was false (v14.2.11), the result was that the draining OSDs became totally unstable while deleting PGs and the clusters nearly went down.

Even if you don't want to enable it by default anymore, IMHO the impact of the option can be so large that we should at least regularly check/qa test with bluefs_buffered_io = true so that we can be confident that there are no bugs when it is enabled. (Maybe we should add a bluefs_buffered_io = random setting for testing?)

@dvanders - additionally I'm curious wouldn't #37314 be a good enough replacement for this PR. At least for removal scenarios....

I very much look forward to that PR being merged, thank you :) But I just find it unlikely that this is the only place that the page cache is speeding up OSD operations. We normally have spare memory on a server -- why not use it?

@dvanders - I totally understand your points but the issue is that currently the community is in a position to make a decision while having multiple confronting facts about this option - see Mark's description in #34224. Hence I don't see a way other than have a sort of trial where both sides to present their arguments. The more arguments the better ;) IMO weekly performance meeting is the best place for that...

Just a side note about massive removals - definitely buffered_io can impact this - but IMO this specific use case can/should be treated differently, in as way #37314 does. The major rationale - I've seen multiple complains about miserable PG removal experience long before bluefs_buffered_io adjustement....

@dvanders

Copy link
Copy Markdown
Contributor Author

Given multiple back-and-forth iterations on this parameter (previous one is at #34224) IMO it makes sense to have a more formal process behind this modification. E.g. this should include complete scenario's description, lab H/W and resulting numbers in a way this is reproducible by somebody else.

Right, I agree, and I can work on a reproducer: the basic idea is to add a PG with ~200000 small objects to a hybrid OSD (hdd + sata ssd), then delete that PG. The ssd's IO should saturate when buffered_io=false, and will be ~nil in with buffered_io=true.
TBH, I'm trying to provoke this discussion because by experience the impact of the option was shown to be dramatic in two independent clusters we run (both while migrating to new hw): one S3 cluster, one CephFS cluster. For each of those clusters, when bluefs_buffered_io was false (v14.2.11), the result was that the draining OSDs became totally unstable while deleting PGs and the clusters nearly went down.
Even if you don't want to enable it by default anymore, IMHO the impact of the option can be so large that we should at least regularly check/qa test with bluefs_buffered_io = true so that we can be confident that there are no bugs when it is enabled. (Maybe we should add a bluefs_buffered_io = random setting for testing?)

@dvanders - additionally I'm curious wouldn't #37314 be a good enough replacement for this PR. At least for removal scenarios....

I very much look forward to that PR being merged, thank you :) But I just find it unlikely that this is the only place that the page cache is speeding up OSD operations. We normally have spare memory on a server -- why not use it?

@dvanders - I totally understand your points but the issue is that currently the community is in a position to make a decision while having multiple confronting facts about this option - see Mark's description in #34224. Hence I don't see a way other than have a sort of trial where both sides to present their arguments. The more arguments the better ;) IMO weekly performance meeting is the best place for that...

Just a side note about massive removals - definitely buffered_io can impact this - but IMO this specific use case can/should be treated differently, in as way #37314 does. The major rationale - I've seen multiple complains about miserable PG removal experience long before bluefs_buffered_io adjustement....

Fair enough. OK, to minimize unnecessary work, I propose that I'll put this PR on hold (mark it DNM), then review again after we all get practical experience with #37314. Works for you?

@ifed01

ifed01 commented Nov 17, 2020

Copy link
Copy Markdown
Contributor

Fair enough. OK, to minimize unnecessary work, I propose that I'll put this PR on hold (mark it DNM), then review again after we all get practical experience with #37314. Works for you?

Sounds good.

@dvanders dvanders changed the title common/options: bluefs_buffered_io=true by default DNM: common/options: bluefs_buffered_io=true by default Nov 17, 2020
@tchaikov tchaikov added the DNM label Nov 17, 2020
@vumrao

vumrao commented Dec 11, 2020

Copy link
Copy Markdown
Contributor

cc @vumrao

@FredNass

FredNass commented Dec 12, 2020 •

Copy link
Copy Markdown
Contributor

Hello folks,

I just wanted to report that we made the very same experience as Dan's and decided to revert bluefs_buffered_io to true. Having it to false was extremely painful to the cluster during snap trimming. For example, with bluefs_buffered_io set to false, choosing any lower value than 20s (!) for osd_snap_trim_sleep would result in SSDs toping at 100%util on an iostat with 770MB/s READ and 4.5kiops READ, resulting in slow requests appearing in the cluster (then expected consequences for iSCSI and S3 services).
Our OSDs are Hybrid with NL SAS HDDs backed by SSDs (RocksDB). I can provide more details about our setup if needed.
The SSD load stopped immediately right after injecting the bluefs_buffered_io=true and we could set the osd_snap_trim_sleep to 0.1s. Snap trimming ended up in the very next minutes.

From our last observations, we could mitigate the swap usage issue by lowering the osd memory target from (previously) 8GB to 4GB. It looks as if the in memory cache used with/by bluefs_buffered_io was not bound by/to the osd memory target context.

It seems that the decision to change the default value was motivated by : 1. The excessive swap usage issue with a value of true 2. The small performance differences between true and false. 3. the time needed to investigate the excessive swap usage.

We now know that 2. is somehow wrong in real life, 1. can be mitigated by lowering osd memory target (I may need a few days yet to confirm that for good), 3. the excessive swap usage was not (or was it?) investigated yet.

If the excessive swap usage does not appear with lower osd memory target values then bluefs_buffered_io default value should probably go back to true, imho. And the effort should then focus on 3, that is "osd memory target not observed when bluefs_buffered_io=true" or something :-)

Same performance issue during snap trimming was observed here.

A new BZ was just created here.

Best regards,
Frédéric.

@markhpc

markhpc commented Dec 17, 2020 •

Copy link
Copy Markdown
Member

@FredNass Thanks for the report! Yeah, we can't really control the page cache with the osd_memory_target since ultimately the kernel owns it. The best we can do is madvise but that's not going to fix things imho.

I think folks that are being hit by this should probably switch the value back (especially if they haven't hit the issue with RGW), but I'm loath to make it the default again unless we absolutely have to since the alternative is just as bad (clusters more or less falling over due to excessive swapping). I'm not convinced just lowering the osd_memory_target can necessarily fix this, though giving the kernel more free memory to work with would certainly make it less likely to happen imho.

I'm hoping that if we can instead segment the rocksdb cache in such a way that we prioritize keeping SST files related to snapshots in memory, we can still avoid using pagecache but make sure that we're not thrashing the block cache during snap trimming. This would probably need to happen after we get the onode double cache fix in (Adam has an updated branch he's working on). The downside here is that we still would be doing this on a per-OSD basis so lose out on the big page cache pool, then we have much more direct control over what gets cached.

Another alternative here is that we turn on bluefs_buffered_io only for HDDs, but I'm hoping we don't have to go that route as the HDD/NVMe split options tend to be confusing for users.

@dvanders

dvanders commented Dec 17, 2020 •

Copy link
Copy Markdown
Contributor Author

@markhpc

I think folks that are being hit by this should probably switch the value back

Is there something we can do to ensure true keeps getting test coverage; maybe a bluefs_buffered_io = random flag?

clusters more or less falling over due to excessive swapping

Is it generally recommended to have swap available on osd servers? (On our side, we have 0 swap, so that mem leaks or whatever fail hard, quickly).

@FredNass

FredNass commented Dec 17, 2020 •

Copy link
Copy Markdown
Contributor

@markhpc

Yeah, we can't really control the page cache with the osd_memory_target since ultimately the kernel owns it. The best we can do is advise but that's not going to fix things imho.

The logic behind memory allocation is way beyond my knowledge but couldn't we have the OSDs limit the memory used for the bluefs cache?

What would help is to have bluefs in memory cache bounded by a value that we could set, or a percentage of osd_memory_target. But maybe bluefs in memory cache cannot be bounded by design.

I think folks that are being hit by this should probably switch the value back (especially if they haven't hit the issue with RGW), but I'm loath to make it the default again unless we absolutely have to since the alternative is just as bad (clusters more or less falling over due to excessive swapping). I'm not convinced just lowering the osd_memory_target can necessarily fix this, though giving the kernel more free memory to work with would certainly make it less likely to happen imho.

Would setting a high vm.min_free_kbytes help avoiding excessive swap usage or would it make worse and happen earlier?

FWIW, since lowering osd_memory_target from 8GB to 4GB, even with bluefs_buffered_io=true, excessive swap usage did not happen anymore. This is on a 16 OSDs node:

$ free -h
total used free shared buff/cache available
Mem: 187G 69G 9,2G 4,1G 108G 100G
Swap: 8,0G 167M 7,8G

swap usage:

$ for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | grep ceph-osd | sort -k 2 -n -r
ceph-osd 24344 kB
ceph-osd 21900 kB
ceph-osd 21548 kB
ceph-osd 21500 kB
ceph-osd 7592 kB
ceph-osd 6644 kB
ceph-osd 5328 kB
ceph-osd 5000 kB
ceph-osd 4892 kB
ceph-osd 4492 kB
ceph-osd 3696 kB
ceph-osd 3108 kB
ceph-osd 2492 kB
ceph-osd 2364 kB
ceph-osd 2240 kB
ceph-osd 764 kB

The above output shows a big difference in the way OSDs use swap, which is kinda weird. In the end, we may well observe excessive swap usage again in weeks or months. I dunno.

I'm hoping that if we can instead segment the rocksdb cache in such a way that we prioritize keeping SST files related to snapshots in memory, we can still avoid using pagecache but make sure that we're not thrashing the block cache during snap trimming.

This would probably help, but shouldn't bluefs caching be limited in how much memory it can use to begin with (if possible)? Sorry if this is a naïve question. 😃

@alram

alram commented Feb 8, 2021

Copy link
Copy Markdown
Member

Chiming in here. We've noticed the same issue with PG deletion and snap trimming. Reproducing snap trimming is fairly trivial:
1 - Create 10x 100GB RBD
2 - run rbd bench on all 10 and snapshot every 60 secs; I ran RBD bench 3 times which created roughly 10TB of snapshot data
3. - delete all snapshots

bluefs_buffered_io = false (nevermind the avg time, cluster was idle)
bluefs_not_buffered

bluefs_buffered_io = true
bluefs_buffered

Since I've seen in the ML, I've tested osd_memory_target at 10GiB and disabled bluefs_buffered_io but that didn't help.
Happy to help with any other test needed.

@dvanders

dvanders commented Feb 8, 2021 •

Copy link
Copy Markdown
Contributor Author

It's a pity but I don't think any production cluster has yet confirmed that #37314 fixes the underlying inefficient PG removal implementation.

I didn't follow the snap trim issue closely: is there a similar fix for that somewhere? If not, we might need this change anyway.

@alram

alram commented Feb 9, 2021 •

Copy link
Copy Markdown
Member

It's a pity but I don't think any production cluster has yet confirmed that #37314 fixes the underlying inefficient PG removal implementation.

I don't believe so either. This is probably something I'm going to have try in my test env in a few weeks

I didn't follow the snap trim issue closely: is there a similar fix for that somewhere? If not, we might need this change anyway.

I couldn't find any fix, I blindly tried ceph/daemon-base:latest-nautilus-devel last Friday but saw the same behavior

@FredNass

FredNass commented Feb 10, 2021 •

Copy link
Copy Markdown
Contributor

With bluefs_buffered_io set to false, I believe snap trimming and PGs deleting speed mainly depends on the underlying SSD/NVMe hardware speed. Is that right? If so, any software improvements like changing osd_delete_sleep_* default values and others would probably help, but not in the same proportions as if these operations were executed in RAM (bluefs_buffered_io=true).
Am I right?

So unless bluefs_buffered_io was set to false for another reason than excessive RAM/swap usage, it'd be a pity to not use the bluefs cache again and properly investigate and fix the real issue which is the RAM/swap consumption. Don't you think?

@markhpc

markhpc commented Feb 11, 2021

Copy link
Copy Markdown
Member

FWIW, there's a chance that the onode double cache fix may also help in this situation:

#37391

The idea here is that we're reducing the occurrence of double caching onode data in both the bluestore onode cache and rocksdb block cache, which should allow for more onodes to be cached overall. Assuming that you are chosing a reasonable osd_memory_target based on total node memory, this should hopefully result not only in better memory utilization for caches but hopefully also stop onode reads from totally thrashing the rest of the rocksdb block cache.

@aclamk

aclamk commented Feb 25, 2021

Copy link
Copy Markdown
Contributor

@dvanders
Would it be possible to grab OSD log with debug_bluefs = 10/10 set, when high bluefs read traffic is suspected?
This might not directly help, but maybe we should consider some better caching on bluefs level.
I would personally be very interested in taking a look into this.

@dvanders

Copy link
Copy Markdown
Contributor Author

@dvanders
Would it be possible to grab OSD log with debug_bluefs = 10/10 set, when high bluefs read traffic is suspected?
This might not directly help, but maybe we should consider some better caching on bluefs level.
I would personally be very interested in taking a look into this.

Sure no problem @aclamk. Do you want rocksdb_cache_index_and_filter_blocks_with_high_priority = true or false for this test?

@baergj

baergj commented Feb 25, 2021

Copy link
Copy Markdown

@markhpc Thanks for the extended explanation! It was https://github.com/facebook/rocksdb/wiki/Tuning-RocksDB-on-Spinning-Disks that I was thinking of, and I see that I also misremembered - it's rocksdb_cache_index_and_filter_blocks (not the high priority one) in that guide.

@aclamk

aclamk commented Feb 25, 2021

Copy link
Copy Markdown
Contributor

@dvanders
I think in future we will go for rocksdb_cache_index_and_filter_blocks_with_high_priority = false, so please set it that way, if possible.

@dvanders

Copy link
Copy Markdown
Contributor Author

@aclamk here's a log with debug_osd=10 and debug_bluefs=10. ceph-post-file: ef551ba6-c0d7-4c6c-8284-887469388cb8
in the osd log the interesting ops start with _delete_some.

@aclamk

aclamk commented Feb 26, 2021

Copy link
Copy Markdown
Contributor

@dvanders
I have checked log you provided and extracted very wierd prefetch performance for ino 16305.
You can observe it here: https://gist.github.com/aclamk/09ab70d290e8c6b77dbb35e588259bc6

I feel like there is too much prefetching going on. I expect it to be rocksdb bug.
It does not affect systems that have buffering enabled, since those prefetches are comparable to just syscall.
For unbuffered files, rocksdb does not prefetch.

The actual problem is, that with bluefs_buffered_io==false we use unbuffered io.

Rocksdb queries file access by:
class RandomAccessFile { ... virtual bool use_direct_io() const { return false; }
Which I guess did not exist when we implemented filesystem-related env for rocksdb.

I am currently cooking a fix for that.
The impact of change is difficult to predict, as different prefetch logic in rocksdb will kick-in.

@FredNass

FredNass commented Mar 2, 2021 •

Copy link
Copy Markdown
Contributor

Hrm, from those sar snippets, there was a lot of write traffic happening in the bluefs_buffered_io=false case. Was that a pretty good representation of what was going on for that 4 hour duration? Looks like the disk is saturated with lots of IOs in the queue and higher average await time.

Well, with bluefs_buffered_io=false the higher numbers are READS per second(4th column rd_sec/s), not WRITES. For example at 15:20, /dev/sdn SSD has a load of over 850k read iops which looks insane to me. This does not happen with bluefs_buffered_io=true.

This ties in with Dan's observations that shows a lot more reads per sec observed when bluefs_buffered_io=false.

@markhpc

markhpc commented Mar 2, 2021 •

Copy link
Copy Markdown
Member

@FredNass yeah, a huge increase in read traffic is consistent with what we've seen in the past. Looking at @aclamk's gist, bluefs is seeing regular repeated prefetch of the exact same ranges over and over again every 3-4 seconds. Going back to the osd log from CERN, here's some random observations:

All of the recorded prefetches span only 5 distinct inodes (with ino 16305 being the major offender as Adam discovered)

ino 16301 ino 16305 ino 16312 ino 16317 ino 16322 Total
prefetches (8K-256K) 512 8442 329 149 198 9630
file size MB 64.77 64.65 64.63 64.63 20.36
prefetch "group" MB ~2.7-3.7 ~51.5-62.7
(often 62.7!)
~4.7-8.2 ~0.5-1.5 0.3-0.7
prefetch total MB 98.74 2077.24 48.99 2.66 16.24 2244.86

The duration from the first to last prefetch was about 105 seconds, so figure we were doing ~20MB/s of prefetch reads with the majority being form ino 16305. Groups of prefetch calls happen every 3-4 seconds starting out at the same offset but doesn't always end at the same place. This very much feels like range scan. Further evidence supports this theory, since each prefetch grouping starts out at 8K and then double in size to 256K as prefetch continues. IE this is almost certainly rocksdb iterator range scan code documented here:

meta/rocksdb#3884

Figure that for ino 16305 we appear to be searching the entire SST file for something every 3-4 seconds (from disk!) and never finding it. So now the question is why range search for these specific SST files appears to never may not be coming from the block cache (but maybe sometimes it is and we don't see it?). I did notice that the OSD log shows zero compactions over the duration, so this wasn't related to behavior I've observed in the past where the block cache seems to get flushed after compaction happens.

Looking more closely at meta/rocksdb#3884, it looks like we'd follow this code path when MaybeLoadDataBlockToCache leaves block.value null, which ultimately is determined by GetEntryFromCache which does the actual block cache lookup:

https://github.com/sagar0/rocksdb/blob/29843bbc13c81b103d4f38a7ad41d3b900476bbe/table/block_based_table_reader.cc#L137-L174

We have our own version of the rocksdb LRU block cache based on the upstream one from a couple of years ago that can tie into our priority cache system. I did a quick scan of the history for the upstream LRU cache and didn't see anything obviously related to the new dynamic iterator readahead code, but next steps probably involve trying to figure out why these aren't being serviced from the block cache.

@markhpc

markhpc commented Mar 3, 2021 •

Copy link
Copy Markdown
Member

@aclamk and I spent several hours today going through the rocksdb code to understand how iterators end up calling prefetch and read all the way down into bluefs code. As it turns out basically everything ultimately goes through the NewDataBlockIterator before working it's way to lower level code. The code has changed a fair amount of the last couple of years so depending on the version of ceph being used it might look and work differently. Here's what rocksdb looks like in pacific:

First, early on in NewDataBlockIterator we see that rocksdb tries to retrieve the block being worked on:

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_based/block_based_table_reader.cc#L1968-L1970

That's always called with "use_cache" set to true, so always should be calling in to MaybeReadBlockAndLoadToCache in RetreiveBlock here:

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_based/block_based_table_reader.cc#L2547-L2550

This in turn will go through and try to retrieve that block from cache here:

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_based/block_based_table_reader.cc#L2166-L2175

Ok, so far so good. If we can't find the block in cache, we instead then conditionally enter into a block of code if IO is allowed and if ro.fill_cache is true where we fetch the block from disk:

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_based/block_based_table_reader.cc#L2197

If you start digging into the BlockFetcher code you'll see that we end up with some random conditionals about reading from persistent cache, but ultimately in our case we should either end up try to read the block from the PrefetchBuffer:

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_fetcher.cc#L207-L211

or just read the block via RandomAccessFileReader (which in turn ends up going back to bluefs via our FS abstraction that sits behind RandomAccessFileReader):

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_fetcher.cc#L218-L219

Notably, if you are wondering where the prefetch buffer is filled, it can actually happen in two different places. If we're not using buffered IO, it can happen right in the BlockBasedTableIterator code before the NewDataBlockIterator is created:

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_based/block_based_table_reader.cc#L3014-L3060

but for direct IO, it's actually happening in the FilePrefetchBuffer code when BlockFetcher's TryGetFromPrefetchBuffer calls the prefetch buffer's TryReadFromCache function:

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/file/file_prefetch_buffer.cc#L126

Ok! Now that we have the block either from the prefetch buffer, or from bluefs (remember we're still in the conditional block where we didn't already get it from cache), we put that block in the block cache (assuming s.ok() is true!):

https://github.com/ceph/rocksdb/blob/ceph-pacific-v6.8.1-1/table/block_based/block_based_table_reader.cc#L2208-L2211

After that, there is some tracing code that may or may not be helpful for debugging what's going on here.

@aclamk might have different thoughts on this, but I'm still of two minds. Either something in this process is breaking where PutDataBlockToCache is not actually populating the block cache on line 2211, or this code is in fact all working properly but the block cache is churning so quickly that after a couple of seconds we lose the record and have to refetch the block from disk. This is the general concern I have with having onodes in the same block cache as omap data (and now is split into separate block caches in Pacific!). Rapid onode reads from disk may churn the block cache so fast that we lose the blocks for things like collection iteration.

Making all of this even more irritating is that the rocksdb code looks somewhat different in Nautilus:

https://github.com/ceph/rocksdb/blob/ceph-nautilus/table/block_based_table_reader.cc#L1661-L1759

Here, we can see that MayeLoadDataBlockToCache is being called directly in NewDataBlockIterator, and it's got logic to directly try to insert the block_value into the cache itself.

I think we're going to need to dig even deeper into this. @aclamk may have more thoughts and requests from folks as well. Thanks to everyone who's helping out on this. I think we're going to be in a much better place when we come through on the other side.

@neha-ojha

Copy link
Copy Markdown
Member

Discussed this with @aclamk @markhpc @jdurgin today and we think it makes sense to enable bluefs_buffered_io based on the all the data. We will backport it for the first cut of Pacific.

@markhpc is working on further performance improvements in #40351, which will be backported after they have baked enough.

@neha-ojha neha-ojha changed the title DNM: common/options: bluefs_buffered_io=true by default common/options: bluefs_buffered_io=true by default Mar 23, 2021
@neha-ojha
neha-ojha requested a review from jdurgin March 23, 2021 22:56
@neha-ojha neha-ojha removed the DNM label Mar 23, 2021
@neha-ojha

Copy link
Copy Markdown
Member

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.