Repository navigation
common/options: bluefs_buffered_io=true by default - #38044
Conversation
1b0dc26 to
af4c1d1
Compare
|
(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
af4c1d1 to
5ec8e8e
Compare
|
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?)
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? |
Sounds good. |
|
cc @vumrao |
|
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). 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, |
|
@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. |
Is there something we can do to ensure
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). |
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.
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 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 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.
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. 😃 |
|
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. |
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 couldn't find any fix, I blindly tried |
|
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). 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? |
|
FWIW, there's a chance that the onode double cache fix may also help in this situation: 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. |
|
@dvanders |
Sure no problem @aclamk. Do you want rocksdb_cache_index_and_filter_blocks_with_high_priority = true or false for this test? |
|
@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. |
|
@dvanders |
|
@aclamk here's a log with debug_osd=10 and debug_bluefs=10. ceph-post-file: ef551ba6-c0d7-4c6c-8284-887469388cb8 |
|
@dvanders I feel like there is too much prefetching going on. I expect it to be rocksdb bug. The actual problem is, that with bluefs_buffered_io==false we use unbuffered io. Rocksdb queries file access by: I am currently cooking a fix for that. |
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. |
|
@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)
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: 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 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: 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. |
|
@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: That's always called with "use_cache" set to true, so always should be calling in to MaybeReadBlockAndLoadToCache in RetreiveBlock here: This in turn will go through and try to retrieve that block from cache here: 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: 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: or just read the block via RandomAccessFileReader (which in turn ends up going back to bluefs via our FS abstraction that sits behind RandomAccessFileReader): 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: but for direct IO, it's actually happening in the FilePrefetchBuffer code when BlockFetcher's TryGetFromPrefetchBuffer calls the prefetch buffer's TryReadFromCache function: 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!): 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: 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. |
|
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. |


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