Repository navigation
Conversation
| @@ -11776,11 +11841,131 @@ int BlueStore::read( | |||
| if (offset == length && offset == 0) | |||
| length = o->onode.size; | |||
|
|
|||
| r = _do_read(c, o, offset, length, bl, op_flags); | |||
| r = _do_read(c, o, offset, length, bl, op_flags, 0, | |||
| might_need_reformatting ? &span_stat : nullptr); | |||
There was a problem hiding this comment.
If we can potentially defrag on any read, it could be interesting once the extents are read off disk to make a decision about whether or not an object is fragmented enough to warrant defragmentation on-the-fly.
There was a problem hiding this comment.
@markhpc I am excited to see it. Opens interesting paths.
|
I'm not sure "data_layout_reformatting" is very clear to the users what it is doing. Maybe instead use "optimize_during_scrub" with options "defrag", "recompress", "all", ... The second option is flexible if we want to allow additional optimizations or modes in the future. |
| @@ -6156,7 +6157,8 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) | |||
| {"dedup_chunk_algorithm", DEDUP_CHUNK_ALGORITHM}, | |||
| {"dedup_cdc_chunk_size", DEDUP_CDC_CHUNK_SIZE}, | |||
| {"bulk", BULK}, | |||
| {"read_ratio", READ_RATIO} | |||
| {"read_ratio", READ_RATIO}, | |||
| {"data_layout_reformatting", DATA_LAYOUT_REFORMATTING}, | |||
There was a problem hiding this comment.
This is missing corresponding "data_reformatting" get and set entries in MonCommands.h (easy to miss!)
Very much dislike "optimize_during_scrub". I'd favor the boolean flag approach with something like "scrub_defragmentation", and "scrub_recompression". The number of pool options we have and the way we display them in the command help has become pretty unwieldy though. This doesn't do anything to help it. Having said that, I agree that this is best configurable at the pool level, especially if we want to allow lazy compression of objects on scrub. |
|
I did a very minimal initial test where I created 4 128GB RBD images, pre-filled them with 4MB writes, then did 5 minutes of 4K random writes to them in a pool with 512 PGs. This is on NVMe, so it's pretty quick. I then looked at a certain PG 2.1ff:
and ran deep-scrub on it 3 times:
And the fragmentation score and reformat counters at this point is: Next set the pool data_reformatting to defragment and rerun deep-scrub on 2.1ff:
Next set the pool data_reformatting to both and rerun deep-scrub on 2.1ff:
Next set the pool compression_mode to passive and rerun deep-scrub on 2.1ff. Results are similar to above.
Running another deep scrub on that PG results in an attempt to recompress the objects again: A couple of thoughts:
Morning update: I tried deep-scrubbing another PG this morning with data_reformatting set to both and watched onode_extents:
It looks like the number of extents actually went up? |
|
Here's a debug_bluestore = 10 log while deep-scrubbing one of the other PGs (2.1fb). |
Are you referring to onode_extens perf counter here? IMO that's a wrong metric as it's an amount of logical (not physical) extents in the cache(!) |
Looks good to me, the majority of reads has log output like: |
I could see no initial compression, e.g. sc (aka storage compressed) = 0 2024-05-23T12:58:04.864+0000 7fed59ea4700 10 bluestore(/tmp/cbt/mnt/osd-device-2-data) read recompress info, 0x80000 vs. 0x80000 the above line shows no saving due to recompression - recompressed data needs the same 512K of space. So I presume your input data flow isn't compressible. Or something wrong with compression settings... |
Yikes! That's confusing. I don't know if I knew that at one point, but clearly I didn't remember it. :) We should rename it. I'll try to take a look with the histogram. |
There was no initial compression. I wrote the data out uncompressed with data_reformatting off, then set it to "defragment", then "both". Next I set the compression mode to passive, then aggressive, then force. Each time, I ran a deep scrub on different PGs to see what would happen. |
This is a great point. I think the intuitive user expectation is that this feature could be used to compress old objects written uncompressed before this feature was available. Also earlier we spoke about a feature like:
|
462da8c to
56f74a1
Compare
| @@ -11776,11 +11841,134 @@ int BlueStore::read( | |||
| if (offset == length && offset == 0) | |||
| length = o->onode.size; | |||
|
|
|||
| r = _do_read(c, o, offset, length, bl, op_flags); | |||
| r = _do_read(c, o, offset, length, bl, op_flags, 0, | |||
There was a problem hiding this comment.
The implementation is very strongly tied to existing BlueStore execution paths.
This is a problem, because it gives very little room to actually work on optimization algorithms.
There was a problem hiding this comment.
That's true but we really want to save some cycles by not doing independent standalone optimization.
There was a problem hiding this comment.
I do not believe in optimizing cycles in function that optimizes metadata shape.
In almost all cases it is more profitable to pay for optimization and get the rewards elsewhere.
| IOContext* ioc) | ||
| { | ||
| IOContext* ioc, | ||
| span_stat_t* res_span_stat) |
There was a problem hiding this comment.
_prepare_read_ioc is modified to provide scanning for optimization.
We should have a separate function that will scan object and decide action.
For example it might happen that in object we have 3 chunks for total of 4MB,
and in attempt to defragment it we allocated 3 chunks.
There was a problem hiding this comment.
_prepare_read_iocis modified to provide scanning for optimization. We should have a separate function that will scan object and decide action.
That's again an attempt to design things for an independent optimization process. Which still sounds questionable to me.
For example it might happen that in object we have 3 chunks for total of 4MB, and in attempt to defragment it we allocated 3 chunks.
Not sure I understand this example. When speaking of defragmentation only - it would happen if amount of new fragments is less than original one for a specific data span (512K when triggered from deep scrub).
If recompression is enabled as well -reformatting unconditionally occurs when new required space for a data span is less than the original one. Fragmentation is taken into consideration when recompression is not beneficial only. This recompression+defragmentation prioritization might look a bit inflexible - one might want prefer defragmentation over recompression but for now it looks like an overkill to me.
There was a problem hiding this comment.
The big reason I think we want to piggyback on deep-scrub is because we're already reading the content of the object to do the scrub, so it's the perfect time to make decisions about de-fragmentation and compression as the most expensive part of this can easily be reading the fragmented extents. I don't think we should scan objects as a separate loop unless we have a very good reason. It's much better in my mind to opportunistically defrag/compress when we've already done the expensive fragmented read.
There was a problem hiding this comment.
@markhpc
I (now) agree that performing optimization to object as an extra step during deep-scrub is good.
"I don't think we should scan objects as a separate loop unless we have a very good reason."
The code here is scanning the object - it's just piggybacking _read_cache to do it.
There is no change to behaviour of _read_cache.
The filling of span_stat_t could be done in separate loop at a cost of a loop.
Similarly, we now load shared blobs in _prepare_read_ioc - useless for reading process.
That would made optimization sense, if significant part of processing was reused - but its only the loop.
@gardran My opinion is that whenever we make a new feature we should make it as detached from existing code as possible to minimize accidental bug injection. Within reason of course...
There was a problem hiding this comment.
@gardran My opinion is that whenever we make a new feature we should make it as detached from existing code as possible to minimize accidental bug injection. Within reason of course...
Generally I agree with this point when we're talking about a severe intervention into the execution path: changing run flow, having new algorithms, etc...
Instead I just perform stats collection (by using simple arithmetic ops) here. So apart from a trivial null/invalid pointer dereferencing this shouldn't introduce any issues to existing functionality. Moreover if refactoring is disabled this function collects stats into a dummy local var which is an absolutely trivial operation.
So IMO that sort of changes (in this specific function) is quite safe and doesn't worth the separation - basic code review/testing should reveal any potential issues if any.
There was a problem hiding this comment.
I was slightly worried about performance drop from that unused span_stat_t in non-scrub case, but performance cost is low. It is about 1% more resources, different metrics are consistent here.
origin/main:
{
"sample_count": 22863635,
"context_switches": {
"non_zero_count": 18006771,
"zero_count": 4856864,
"total": 19591775,
"avg": 0.85689677078907178
},
"cpu_cycles": {
"total": 1086421762527,
"avg": 47517.455668225986
},
"cache_misses": {
"total": 26163467742,
"avg": 1144.3266891725659
},
"branch_misses": {
"total": 3647919172,
"avg": 159.55114626348785
},
"instructions": {
"total": 164399693895,
"avg": 7190.4442970245109
}
}
this PR:
{
"sample_count": 23010714,
"context_switches": {
"non_zero_count": 18123197,
"zero_count": 4887517,
"total": 19730884,
"avg": 0.85746509213056143
},
"cpu_cycles": {
"total": 1105964001154,
"avg": 48063.002354207696
},
"cache_misses": {
"total": 27135710009,
"avg": 1179.2641466492521
},
"branch_misses": {
"total": 3783880829,
"avg": 164.43995736073205
},
"instructions": {
"total": 166885546959,
"avg": 7252.5149353905317
}
}
| #undef dout_prefix | ||
| #define dout_prefix *_dout << "OnodeReformatDefragment " | ||
|
|
||
| bool OnodeReformatDefragmentAction::call(OnodeReformatContext* ctx, |
There was a problem hiding this comment.
How does DEFRAGMENT engine work when RECOMPRESS engine is not enabled?
Please lead me through the logic.
There was a problem hiding this comment.
Data is staged for overwriting with a goal to lower the number of fragments on disk. If the goal is achieved - the actual overwrite takes place. No recompression is applied along the path.
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
@aclamk - your last comments have been resolved/answered. Please take another look. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
@gardran The benefit is that we do not have to modify The performance, measured during deep-scrub:
The performance, measured during random read-write testing:
We have +0.7% more CPU on scrub, but -0.2% CPU on client IO reads. I am looking forward to discussion about benefits / problems of the solution I proposed here. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
The 0.2% drop on client load is rather cause by unconditinal passing span_stat_t parameter into _do_read. Originally this wasn't the case and it had been happening for scrubbing reads only. Anyway I encorporated your changes into the PR, please keep reviewing. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
1 similar comment
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
design. Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankivich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
Signed-off-by: Garry Drankovich <[email protected]>
than embed it. Signed-off-by: Garry Drankovich <[email protected]>
Collect `span_stat_t` related code from _read_cache, _prepare_read_ioc into single _reformat_scan function. Signed-off-by: Adam Kupczyk <[email protected]>
…read Signed-off-by: Adam Kupczyk <[email protected]>
Suggested by Adam to minimize exisiting code intervention Signed-off-by: Garry Drankoivich <[email protected]>
Thus making general framework unaware of specific data layout preconditions to apply reformatting engines. Signed-off-by: Garry Drankovich <[email protected]>
dvanders
left a comment
There was a problem hiding this comment.
Thanks @gardran for sticking with this. I still want this feature, and Fast EC makes it more important. aclamk's _reformat_scan split looks good. Before merge I see some blockers:
- An unknown
deep_scrub_reformattoken indexesnew_engines[-1](bothfrom the description triggers it). The mon needs to validate the value. - EC scrub reads past EOF. The reformat write uses the requested length instead of
bl.length(), so it runs off the end of the bufferlist and growsonode.size. - When
_do_writefails, the txc is dropped but the punched extent map stays in cache. - Compressor errors in the recompress engine are treated as success.
- Defrag allocates holes, which costs space on thin RBD and sparse EC shards.
- Now that a read with CEPH_OSD_OP_FLAG_SCRUB can cause writes, please strip that flag from client ops in the OSD. librados drops it, but a raw client could set it.
I'd also like a rate limit or OSD-side off switch, no exclusive c->lock unless we actually write, pool docs, and tests for EC-style reads, ENOSPC and fsck afterwards.
@aclamk could you re-review the current head, especially the _do_write_big / _do_alloc_write changes and the lazy-mode semantics?
| engine = new OnodeReformatDefragmentEngine(args); | ||
| } | ||
| ceph_assert(e < MAX_REFORMAT_ENGINES); | ||
| new_engines[e].reset(engine); |
There was a problem hiding this comment.
Any token other than recompress/defragment leaves e=-1. The assert passes and we index new_engines[-1]. ceph osd pool set X deep_scrub_reformat both (what the PR description says) would hit this on every OSD in the pool. Please reject unknown tokens here, and validate in OSDMonitor like compression_mode.
| cct->_conf->bluestore_log_op_age); | ||
| } | ||
| if (r >= 0) { | ||
| _maybe_do_reformat_onode(reformat_ctx, c, o, offset, length, bl, op_flags); |
There was a problem hiding this comment.
EC scrub reads 4M even near EOF. The reformat write uses the requested length, not bl.length(). That throws end_of_buffer in _do_write_data and would also grow the object. Please clamp to bl.length() and add a test that reads past EOF at a non-zero offset. Also, reformat_ctx is built before the 0~0 → onode.size fixup above, so it sees the unfixed length.
| ceph_assert(o->exists); | ||
| int r = _do_write(txc, txc->ch, o, offset, length, bl, wctx); | ||
|
|
||
| if (r < 0) { |
There was a problem hiding this comment.
If _do_write fails we drop the txc but keep the modified extent map in cache. Normal writes abort here. Either preallocate everything before touching the onode, or invalidate/reload the onode on failure.
|
|
||
| res_len = from_bl.length(); | ||
| if (l > min_alloc_size && | ||
| wctx.compressor->compress(from_bl, wi.compressed_bl, wi.compressor_message) == 0) { |
There was a problem hiding this comment.
If compress() fails in the engine, _do_alloc_write still treats compressed_bl as valid (r=0). Please carry the error through or clear compressed_bl.
| #undef dout_prefix | ||
| #define dout_prefix *_dout << "OnodeReformatDefragment " | ||
|
|
||
| bool OnodeReformatDefragmentEngine::execute(OnodeReformatContext& ctx, |
There was a problem hiding this comment.
Defrag turns holes into allocated zeros (the small-gap test shows it). That is a space regression for thin RBD and sparse EC shards. Skip holes, or require stored==length. Also please add a minimum gain, e.g. average fragment size below X.
| OnodeReformatContext reformat_ctx(read_ctx, c->reformat_engines); | ||
| if (o && o->exists && reformat_ctx.is_enabled()) { | ||
| slock.unlock(); | ||
| ulock.lock(); |
There was a problem hiding this comment.
This takes c->lock exclusive whenever an engine is enabled, so every aligned scrub read, even when nothing gets rewritten, and holds it across the compress, allocation and _txc_exec. Could we only take it exclusive once we've decided to write? Please also add an OSD-side cap (bytes/s or a fraction of scrub reads) and a global off switch.
|
Built it and ran some tests on Linux (store_test, v1 and v2 write paths):
Happy to share the test cases if useful. |
@gardran the test cases are here, on top of your current head: https://github.com/dvanders/ceph/commits/wip-57631-repro-tests (one commit, test/objectstore only). The past-EOF and hole-fill ones fail at 9bfd726 and should pass once those are fixed. Run with --plugin-dir pointing at your build's lib/, or the compressor plugins won't load. Feel free to pick them into the PR. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
This PR adds an ability for BlueStore to perform object content recompression and defragmentation when handling read requests during deep-scrubbing.
After reading object's chunk BlueStore assesses if it can improve space saving by recompressing an object and/or it can optimize physical layout of the object.
Per-pool option 'data_layout_reformatting' has been introduced to control the behavior. It support the following options:
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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e