Skip to content

crimson: split ObjectDataBlock when overwriting - #45519

Merged
athanatos merged 6 commits into
ceph:mainfrom
zhscn:wip-split-extent
Jul 11, 2022
Merged

athanatos merged 6 commits into
ceph:mainfrom
zhscn:wip-split-extent

Conversation

@zhscn

@zhscn zhscn commented Mar 18, 2022 •

Copy link
Copy Markdown
Member

This PR introduces a straightforward strategy to reduce write amplification.
The design and changes can be found in the commit message and comments.

Benchmark

The benchmark of splitting extents contains two major aspects:

  1. write to new object. In such cases, no extra read and write occurs, it can get the overhead of maintaining the data structure and the procedure of splitting.
  2. overwrite, the length of original extent is 4KiB and greater. When the length is greater than 4KiB, splitting can reduce the read and write amplification so that performance could be better.

for 1. create a new rbd image and test with fio;
for 2. create a rbd image and sequential write, then random write to the full image.

start command:

MGR=1 MON=1 OSD=1 MDS=0 RGW=0 ../src/vstart.sh -n -x --without-dashboard --seastore --crimson --redirect-output --seastore-devs /dev/nvme1n1

1. random write to empty image

fio config
[global]
ioengine=rbd
clientname=admin
pool=test_pool
rbdname=test_img
direct=1
sync=1
time_based=1
runtime=600
randseed=1259
[randwrite-4k]
rw=randwrite
bs=4K
numjobs=1
iodepth=768
random_distribution=zoned:90/10:10/90

Result:

IOPS BW
master 2637 10.3MiB/s
split 3037 11.9MiB/s

2. random write to full image

2.1. the length of extent in image is 4KiB

sequential write with fio
[global]
ioengine=rbd
clientname=admin
pool=test_pool
rbdname=test_img
direct=1
sync=1
randseed=1259
[write-4k]
rw=write
bs=4K
numjobs=1
iodepth=768
random_distribution=zoned:90/10:10/90
IOPS BW
master 20.8k 81.3MiB/s
split 20.3k 79.2MiB/s

After the image is full, start random writes

random write with fio
[global]
ioengine=rbd
clientname=admin
pool=test_pool
rbdname=test_img
direct=1
sync=1
time_based=1
runtime=600
randseed=1259
[randwrite-4k]
rw=randwrite
bs=4K
numjobs=1
iodepth=768
random_distribution=zoned:90/10:10/90
IOPS BW
master 141 567KiB/s
split 2307 9231KiB/s

2.2. the length of extent in image is 64KiB

sequential write with fio
[global]
ioengine=rbd
clientname=admin
pool=test_pool
rbdname=test_img
direct=1
sync=1
randseed=1259
[write-4k]
rw=write
bs=64K
numjobs=1
iodepth=768
random_distribution=zoned:90/10:10/90
IOPS BW
master 8530 533MiB/s
split 7484 468MiB/s

After the image is full, start random writes

random write with fio
[global]
ioengine=rbd
clientname=admin
pool=test_pool
rbdname=test_img
direct=1
sync=1
time_based=1
runtime=600
randseed=1259
[randwrite-4k]
rw=randwrite
bs=4K
numjobs=1
iodepth=768
random_distribution=zoned:90/10:10/90
IOPS BW
master 77 311KiB/s
split 2671 10.4MiB/s

3. summary

The results are annoying. The performance of random writes to a full image is much
worse than expected that the difference of 2.1 test could be insignificant. There may be other factors present.

But the results of splitting are as expected:
writing to empty image has best performance;
writing to 64KiB extent is second;
writing to 4KiB extent is last.

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

@athanatos

Copy link
Copy Markdown
Contributor

I should get to this later this week.

@zhscn
zhscn force-pushed the wip-split-extent branch from f422ded to 8431f3f Compare March 31, 2022 05:59
@zhscn

zhscn commented Mar 31, 2022

Copy link
Copy Markdown
Member Author

jenkins test make check

@zhscn
zhscn force-pushed the wip-split-extent branch from 8431f3f to 76fcf33 Compare March 31, 2022 06:22
@athanatos

Copy link
Copy Markdown
Contributor

This PR introduces split in a way that cuts across existing abstraction barriers and increases complexity greatly. Have you considered any other ways to do this that fit better within existing abstractions?

@athanatos

Copy link
Copy Markdown
Contributor

Is the problem here that the extent_info_t within the records can't be modified after write? The backref change should fix that, would that remove the need for the extent retirement complexity and split_context_t?

@zhscn

zhscn commented Apr 6, 2022 •

Copy link
Copy Markdown
Member Author

Have you considered any other ways to do this that fit better within existing abstractions?

Yes and no. 1) For yes, I did design another solution that introduces a new "write context" layer in which we first do splits without the help of Cache/LBAManager and only calls Cache/LBAManager's methods when leaving the ObjectDataHandler, this design can avoid making changes to "Cache::get_extent()", "TransactionManager::dec_ref()" and "Cache::retire_extent_addr()". 2) For no, current abstraction can not handle with the cases that one transaction contains multiple split operation on one extent, which makes the changes of existing abstractions unavoidable. Details are explained later.

Is the problem here that the extent_info_t within the records can't be modified after write? The backref change should fix that, would that remove the need for the extent retirement complexity and split_context_t?

Not exactly, backrefs only affects rewrite process which is not leading to changes in components other than SegmentCleaner.

Current design

Here are some design trade-offs needs to be considered:

Actually splitting process affects 3 aspects:

  1. ObjectDataHandler, the construction phase of a transaction. Currently all split operations occur at this period.

First problem: whether the remaining pieces of an ObjectDataBlock should exist in the form of CachedExtent after splitting and before completing transaction.

                                  |
               Transaction begin  |
               ObjectDataHandler  |
                                  |
                                  |                |******| incoming data (not a CachedExtent)
                                  |
                                  |   |-------------------| original extent (ObjectDataBlock with paddr1, real and not relative)
                                  |
                   split extent   |
         remove original extent   |
alloc extent for incoming  data   |                |******| ObjectDataBlock with paddr2, relative, in write_set
                                  |
                                  |   |------------|       original-left piece of the extent
                                  |                        (is this a CachedExtent? What's its paddr, paddr1 or a new relative paddr3?)
                                  |
                                  |
                                  v

For the original-left piece, 1) if it is a CachedExtent with the same physical address of original ObjectDataBlock paddr1, then Cache::get_extent can not work correctly since its extent is indexed only by paddr_t, so we need a new structure to hold the original-left piece; 2) if it is a CachedExtent with a new relative paddr3, then there must be a data structure in Transaction to maintain the mapping from new relative paddr3 to original real paddr1.

Second problem: how to handle operations on "split extents"?

                                  |
               Transaction begin  |
               ObjectDataHandler  |
                                  |
                                  |               |******| incoming data (not a CachedExtent)
                                  |
                                  |  |-------------------| original extent (ObjectDataBlock with paddr1, real and not relative)
                                  |
                   split extent   |
         remove original extent   |
alloc extent for incoming  data   |               |******| ObjectDataBlock with paddr2, relative, in write_set
                                  |
                                  |  |------------|       original-left piece of the extent
                                  |
                                  |
                                  |
               next operation     |
                                  |      +---------------  result of previous split(we call it "split extent")
                                  |      |
                                  |      |           +---  incoming data of prev op
                                  |      v           v     ObjectDataBlock with relative paddr
                                  |  |------------|******|
                                  |
                                  |   |****|               new incoming data, offset and
                                  |                        length are not block size aligned
                                  v

With current mechanism, every step of handling transaction operation works as follows:

  • get pin from LBA by laddr_t
  • get extent from Cache by paddr_t.

If the pin returned from LBA is the "split pin" of previous operation, then all operations on this pin needs to be converted into operations on the original extent.

For example, remove a "split extent": Transaction::dec_ref involves Cache::retire_extent_addr, but a "split extent" is the part of original extent which has been retired at previous operation. So removing a "split extent" should not call Cache::retire_extent_addr and only remove entry from LBA tree.

There must exist a mechanism to distinguish whether a range of (laddr_t,length) corresponds to a "split extent" of previous operation.

Given these two problems, a "split_context_t" is necessary to maintain the information about the split extents.

What's more, this PR doesn't treat "split extent" as a real CachedExtent, so allocating split extents is only allocating a new entry on LBA tree, not allocating CachedExtent from Cache.

  1. extent retirement.

Follow the part 1, since a split operation involves removing old extents and inserting new extents, old extents are always in Transaction::retired_set. In case of partially overwrite, old extents should not be completely retired, as the remaining pieces of them are still live. So when retiring an ObjectDataBlock, we also needs a structure to find out retired ranges correctly, which is also the purpose of split_context_t.

  1. rewrite extent.

Currently checking a extent(ObjectDataBlock) are alive calls LBAManager::get_pins. The more efficient way will be calling backref tree in the future.

Write Context

Of course this design causes several break changes: 1) Cache::get_extent can return retired ObjectDataBlock; 2) complex parameters of Transaction::dec_ref and Cache::retire_extent_addr; 3) complex retire policy 4) and some others.

The root cause is that for each transaction step, we do the following sequence:

  1. load touched extents
  2. do splits
  3. alloc "split extents" and "new extents"

And successive transaction steps needs to deal with the result of the previous transaction step.

With the "write context" approach, we attach each transaction with a write_context_t, and cache all steps' results in it, so the workflow changes to the following:

  1. load all extents that are touched by all transaction ops
  2. do steps on top of the write_context_t, some of which mean involve extents splitting
  3. do all retires/allocations

Hopefully, with the "write context" approach, the first two break changes above, that's "Cache::get_extent can return retired ObjectDataBlock" and "complex parameters of Transaction::dec_ref and Cache::retire_extent_addr", can be avoided. And the third issue of "complex retiring policy" can be simplified.

@github-actions

Copy link
Copy Markdown

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

@athanatos

athanatos commented Apr 20, 2022 •

Copy link
Copy Markdown
Contributor

First problem: whether the remaining pieces of an ObjectDataBlock should exist in the form of CachedExtent after splitting and before completing transaction.

                                  |
               Transaction begin  |
               ObjectDataHandler  |
                                  |
                                  |                |******| incoming data (not a CachedExtent)
                                  |
                                  |   |-------------------| original extent (ObjectDataBlock with paddr1, real and not relative)
                                  |
                   split extent   |
         remove original extent   |
alloc extent for incoming  data   |                |******| ObjectDataBlock with paddr2, relative, in write_set
                                  |
                                  |   |------------|       original-left piece of the extent
                                  |                        (is this a CachedExtent? What's its paddr, paddr1 or a new relative paddr3?)
                                  |
                                  |
                                  v

For the original-left piece, 1) if it is a CachedExtent with the same physical address of original ObjectDataBlock paddr1, then Cache::get_extent can not work correctly since its extent is indexed only by paddr_t, so we need a new structure to hold the original-left piece

Why can't the original-left piece become a CachedExtent? It seems to me like we could mutate the lba and backref mappings to make this original-left piece a real CachedExtent indexed by its paddr by "retiring" the original extent and creating a new, smaller extent in its place. The main obstacle to this before is that we can't mutate the extent_info_t originally written with the extent, but the backref manager should eliminate that as a problem.

@athanatos

Copy link
Copy Markdown
Contributor

Of course this design causes several break changes: 1) Cache::get_extent can return retired ObjectDataBlock; 2) complex parameters of Transaction::dec_ref and Cache::retire_extent_addr; 3) complex retire policy 4) and some others.

The root cause is that for each transaction step, we do the following sequence:

1. load touched extents

2. do splits

3. alloc "split extents" and "new extents"

And successive transaction steps needs to deal with the result of the previous transaction step.

With the "write context" approach, we attach each transaction with a write_context_t, and cache all steps' results in it, so the workflow changes to the following:

1. load all extents that are touched by all transaction ops

2. do steps on top of the write_context_t, some of which mean involve extents splitting

3. do all retires/allocations

Hopefully, with the "write context" approach, the first two break changes above, that's "Cache::get_extent can return retired ObjectDataBlock" and "complex parameters of Transaction::dec_ref and Cache::retire_extent_addr", can be avoided. And the third issue of "complex retiring policy" can be simplified.

This is why I'm skeptical of this approach. We already have a mechanism for tracking extents as they are mutated through a transaction. I'd really prefer to generalize the existing mechanism rather than to introduce a new one, and I'm not yet convinced that this write context approach is simpler.

@zhscn

zhscn commented Apr 29, 2022

Copy link
Copy Markdown
Member Author

@athanatos I reimplement split extent under your suggestion.

Here are some changes:

  1. split extent becomes a state in ObjectDataBlock. All split extents are added into Transaction::split_set;
  2. Add Transaction::get_retired_object_data_block. I think it's necessary to keep a mapping from split extent to original extent, which is helpful to avoid reading disk or copy data multiple times in certain cases. When allocting a split extent, the original extent has been retired, which causes Transaction must return a retired ObjectDataBlock. I don't find a better way to build the mapping, do you have any suggestions?
  3. Cache::get_extent: first check whether the target paddr is located in Transaction::split_set, if non-empty or original extent is not a retired place holder, then (copy data and) return split extent directly. Otherwise read disk and call Transcation::replace_placeholder to replace all RetiredPlaceHolder.

@athanatos

Copy link
Copy Markdown
Contributor

This still treats split extents as special, and it's still not obvious to me that that's actually necessary. Why wouldn't Cache::get_extent find the newly split extent in the write_set as always?

@athanatos

athanatos commented Apr 29, 2022 •

Copy link
Copy Markdown
Contributor

To expand on this a bit, the interaction I'd like to see is something like:

Original extent: paddr: p ~ 16k laddr: l ~ 16k

4k write at l + 4k

TransactionManager::dec_ref(t, original_extent);
left_extent = TransactionManager::map_existing_extent(t, l, 4k, p);
middle_extent = TransactionManager::alloc_extent(t, l + 4k, 4k);
// fill in data for middle_extent from write
right_extent = TransactionManager::map_existing_extent(t, l + 8k, 8k, p + 8k);

left_extent, middle_extent, and right_extent would be in the write_set as with any other extent, so no special support should be needed in get_extent. The lba mappings should be in the lba tree, so lba lookups should behave correctly. The only portion that previously was impossible was that the garbage collector needed the record extent_info_t information to find the lba for original_extent. #45390 should handle that by letting map_existing_extent simply update the backref tree accordingly.

I'd really like to avoid anything below TransactionManager needing to know about the existence of ObjectDataBlocks or splits specifically. Instead, I'd like to add a general ability for a Transaction to be able to mutate lba mappings such that the existing lba tree, backref tree, and write_set behave correctly without needing auxiliary structures specific to ObjectDataBlock's or splits.

@zhscn

zhscn commented Apr 30, 2022 •

Copy link
Copy Markdown
Member Author

Why wouldn't Cache::get_extent find the newly split extent in the write_set as always?

Because left_extent has the same paddr with original extent. Cache::get_extent first looks up Transaction::retired_set by the paddr of left_extent (same as paddr of original extent), the retired result is not what we want. Retiring a split extent could not move it into Transaction::retired_set for the same reasion. Getting right_extent works as expected.

One possible solution without split_set is adding a new length parameters:

Transaction::get_extent(paddr_t addr, extent_len_t length, CachedExtentRef *out)

If the length of extent in retired_set is not same as length parameter, then looks up write_set.

Or check Transaction::write_set first, and return get_extent_ret::SPLIT according to ObjectDataBlock::is_split.


Except for "split_set", does current strategy of reading a split extent, keep a "data_ref" field in ObjectDataBlock and replace RetiredPlaceHolder, work as expected?

@athanatos

athanatos commented May 1, 2022 •

Copy link
Copy Markdown
Contributor

Why wouldn't Cache::get_extent find the newly split extent in the write_set as always?

Because left_extent has the same paddr with original extent. Cache::get_extent first looks up Transaction::retired_set by the paddr of left_extent (same as paddr of original extent), the retired result is not what we want. Retiring a split extent could not move it into Transaction::retired_set for the same reasion. Getting right_extent works as expected.

get_extent should probably check Transaction::write_set first. I suspect there will be multiple things like this we'll need to fix in order to correctly support remapping a physical extent and that's where I'd like the design effort to be focused.

One possible solution without split_set is adding a new length parameters:

Transaction::get_extent(paddr_t addr, extent_len_t length, CachedExtentRef *out)

If the length of extent in retired_set is not same as length parameter, then looks up write_set.

I'm not convinced this is actually necessary -- if the extent is in the write set that should probably just suffice.

Or check Transaction::write_set first, and return get_extent_ret::SPLIT according to ObjectDataBlock::is_split.

Like I said, I really don't want Cache to have behavior specific to ObjectDataBlock.

Except for "split_set", does current strategy of reading a split extent, keep a "data_ref" field in ObjectDataBlock and replace RetiredPlaceHolder, work as expected?

data_ref doesn't seem necessary either.

@zhscn
zhscn force-pushed the wip-split-extent branch 2 times, most recently from 1d00e5a to 340cc4c Compare May 10, 2022 08:29
@github-actions

Copy link
Copy Markdown

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

@zhscn
zhscn force-pushed the wip-split-extent branch from 66db552 to 4da6b86 Compare July 6, 2022 07:57
@zhscn

zhscn commented Jul 6, 2022

Copy link
Copy Markdown
Member Author

jenkins test api

@zhscn

zhscn commented Jul 6, 2022

Copy link
Copy Markdown
Member Author

jenkins test make check arm64

@cyx1231st

Copy link
Copy Markdown
Member

@athanatos Sure! will take a look this week.

@zhscn
zhscn force-pushed the wip-split-extent branch 3 times, most recently from 57d2be9 to 2ff59e0 Compare July 7, 2022 03:41

@cyx1231st cyx1231st left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My initial questions, still looking.

Comment thread src/crimson/os/seastore/transaction.h Resolved
Comment thread src/crimson/os/seastore/cache.cc Outdated

@cyx1231st cyx1231st Jul 7, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mutating an ObjectDataBlock is not support yet, see the class definition. And the split feature is not used by other types of extents, right?

If that's true, what case can invoke this part of logic?

@zhscn zhscn Jul 7, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

other LogicalCachedExtent, like SeastoreNodeExtent or OMapNode, which may also need to be splitted if they are enlarged to more than deivce block size (4KB, in most cases) in the future.

#45519 (comment)

In early implementation, I restrict only ObjectDataBlock can be splitted, but it seems not necessary so it becomes a generalized interface.

@cyx1231st cyx1231st Jul 7, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So the split-mutate logic will never be invoked in the current running SeaStore.
I guess there is also no tests to validate this scenario, combined with conflicts and replay.

Do we need worry about the non-existent use case and to implement tests for them? Things might be more complicated if the extent needs to mutate then split then mutate in the same transaction.

What do you think? @athanatos

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess there is also no tests to validate this scenario, combined with conflicts and replay.

f9f1e60 contains replay test.

If there are several transactions try to split the same extent, all these transaction need to retire the target extent first. When one transaction enter prepare phase, it will invalid other transactions.

I can add a new concurrent split test.

Things might be more complicated if the extent needs to mutate then split then mutate in the same transaction.

for ObjectDataBlock, here is a multiple split test:
https://github.com/ceph/ceph/blob/2ff59e0fa941894bc0baf83296a39888218a610b/src/test/crimson/seastore/test_object_data_handler.cc#L384-L416

split then mutate:
f9f1e60 has tested.

mutated then split:
I forget to consider this case, current code can not handle it. map_existing_extent invoke ExtentPlacementManager::read to fill the extent, if the original extent is a mutated extent, it will lose the delta. If we need to support this case, more development is needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I forgot that ObjectDataBlock doesn't allow deltas at the moment. The use case would be a rados-level transaction that mutates the same logical byte range on an object resulting in a seastore transaction with two writes to the same byte range within an existing allocated extent. I actually think this is worth preserving even if ObjectDataHandler doesn't support it yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we need to support this case, more development is needed.

Seems no need to implement it in this PR right now. But the complete mutate-with-split feature is in the middle state. We might still need asserts as a reminder.

The use case would be a rados-level transaction that mutates the same logical byte range on an object resulting in a seastore transaction with two writes to the same byte range within an existing allocated extent.

Do you mean that in the future ObjectDataBlock is expected to support mutations and deltas? If so, probably we can fully enable the mutate-with-split feature in that PR.

@athanatos athanatos Jul 8, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, ok. With the ability to split extents, it may never make sense to journal deltas to ObjectDataBlock's, and RBM extents would probably do write-back rather than a split anyway. I'm ok with deferring this support for later

* Add an assert to duplicate_for_write.
* Add a constexpr supports_map_existing() method to CachedExtent and ObjectDataBlock -- static_assert it in duplicate_for_write and map_existing_extent.
* Add a comment to the EXISTING_CLEAN state explaining that an extent type may use map_existing_extent or duplicate_for_write depending on T::supports_map_existing(), but not both.

Actually, I think we should keep it, see below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think ObjectDataBlock will probably need to support deltas fairly soon. For RBM extents, it will be more efficient to journal-ahead a delta and do a write-back. We probably even want to support deltas for very small writes on ZNS devices. We could enforce a restriction that a particular extent may not be mapped and mutated in the same transaction, but that strikes me as too subtle. I'm inclined to go ahead and introduce this support now given that it's got a test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These use cases make sense to me. And the assert looks trivial.

For "very small writes", do you specifically mean the block-unaligned small writes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah

@zhscn
zhscn force-pushed the wip-split-extent branch from 2ff59e0 to 4acdd36 Compare July 8, 2022 05:25
@zhscn

zhscn commented Jul 8, 2022

Copy link
Copy Markdown
Member Author

jenkins test api

@cyx1231st cyx1231st Jul 8, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When SegmentCleaner invokes get_extents_if_live, the target extent may have been split into multiple pieces by other transaction.

It sounds like a loophole in our transaction conflict mechanism if it is really happening, Ideally these transactions should conflict each other instead @athanatos .

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

IIUC, without splitting pr, it's also possible to make a loophole that there may be some transactions release extents located in reclaim range. With splitting pr, it's impossible to split the same original extent forever and it's a small probability event, so it doesn't make things worse.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, I didn't mean that this PR is related to the potential loophole.

Instead, I am trying to evaluate whether we should going forward to change get_extent_if_live to get_extents_if_live, or fix that hole instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, IIRC the original purpose of get_extent_if_live is that the SegmentCleaner didn't get at these extents by reading the lba tree, it got them by scanning the segment headers. Thus, it still needed to confirm whether the extent in question was still live. Now, however, we get them via the backref extent. That really should be transactionally up-to-date and would indeed cause a conflict otherwise. I think we can actually eliminate this entirely. @xxhdx1985126 ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, IIRC the original purpose of get_extent_if_live is that the SegmentCleaner didn't get at these extents by reading the lba tree, it got them by scanning the segment headers. Thus, it still needed to confirm whether the extent in question was still live. Now, however, we get them via the backref extent. That really should be transactionally up-to-date and would indeed cause a conflict otherwise. I think we can actually eliminate this entirely. @xxhdx1985126 ?

Yes, I think so:-)

However, IIUC, GC always need to read extents out, add them to Cache and then rewrite those extents, and "adding them to Cache" is mandatory for the sake of correctness which is the same reason why, when we prevent GC from touching the LRU, we still have to add extents that are to be GC'd into Cache. Am I right? If so, I think, as long as we have to add extents to Cache, there will be a possibility for GC transactions to conflict with other transactions on those extents, no matter whether we check the liveness of extents or not. Is this right?

With regard to how we should modify the space reclamation procedure, I think, since we have to read extents and rewrite them when reclaiming disk space, we may still have to go through pretty much what TransactionManager::get_extent_if_live() is doing now, which is, first try to get extents directly from Cache, and then, if it fails, go through the lba tree to get laddr->paddr mappings and read the extents from disk. The reason why we still have to go through the lba tree is that we have to maintain the invariant that all parent nodes in the lba tree must have already been loaded into Cache before child ones are loaded. Am I right? If so, I think the focus is whether we should maintain that invariant. If we do, I think maybe we should drop TransactionManager::get_extent_if_live() and call TransactionManager::read_extent() instead. But it will be a totally different situation, if we don't. Am I right? @athanatos What do you think?:-)

@athanatos athanatos Jul 9, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, so we'd need something like read_extent_maybe_cached(..., laddr_t laddr, paddr_t paddr) which checks the cache for paddr and invokes read_extent with laddr if not present.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, so we'd need something like read_extent_maybe_cached(..., laddr_t laddr, paddr_t paddr) which checks the cache for paddr and invokes read_extent with laddr if not present.

Yeah, I'll submit a PR for this:-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the crux of this problem is that we will need to get alive extents from Cache's backref buffer and read them out in the same continuation (meaning atomically among other current transactions). Otherwise, if any transactions can be committed in-between, the paddr~len to read out might be already splitted.

IIUC the lba tree is not quite related to this issue as we will always need to access it in order to rewrite the extent.

@xxhdx1985126 @athanatos Do you think so?

@xxhdx1985126 xxhdx1985126 Jul 11, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IIUC the lba tree is not quite related to this issue as we will always need to access it in order to rewrite the extent.

Yes, I mentioned the lba tree just to discuss how we should change the get_extent_if_live part of the space reclamation procedure, not for resolving the conflict issue. Since live extents may be at very low level of the lba tree and we have to make sure parent nodes are loaded before child nodes, we have to go through the lba tree any way.

What I meant in #45519 (comment) are as follows:

  1. the checking of liveness of extents in space reclamation is not necessary, indeed;
  2. dropping that checking may not help to solve the conflict issue, as we still have to read extents out and add them to Cache even without the liveness checking;
  3. we should drop the liveness checking even if it doesn't help to solve the conflict issue, and we have to involve a process pretty similar to what TransactionManager::get_extent_if_live() is doing now but not for the purpose of extent liveness checking

BTW, since the conflict rate is very low now, and, as @zhscn mentioned above, the space reclamation transactions won't be locked in an infinite loop of conflict(because extents are at least "block size" and can't be split forever, and the number of extents within the range of space reclamation are limited), maybe we should put aside this issue for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I'm fine to leave it in a future PR. And this logic can simplified. I'd be happy to do this.

Comment thread src/crimson/os/seastore/cache.cc Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it necessary to actually read it out?

@zhscn zhscn Jul 8, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

consider this case:

https://github.com/ceph/ceph/blob/4acdd368d7e3464c066070aba746e7de173bda3f/src/test/crimson/seastore/test_object_data_handler.cc#L389-L392

first split retires the original extent, its offset and length are block size aligned, so the original extent may exist as a RetiredPlaceHolder.

if the split extent is remapped but not fill the data, the secondary non-aligend overwrite exactly needs to read the split result, Cache::get_extent will return an empty extent.

To support this case, invoke epm.read is the most convenient way.

A lazy read approach is possible, but it needs to maintain the mapping between original extent and all split extents, which seems a little tricky and magic.

This mapping is also relate to mutate-then-split cases(it needs to find the mutated extent) and verification of #45519 (comment) , since the most simple way to find these mappings is to look up Transaction::retire_set

@athanatos athanatos Jul 8, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@cyx1231st In principle, we could do a lazy read. I argued, however, for doing this for now in order to simplify the PR. We can introduce lazy reads later.

@cyx1231st cyx1231st Jul 11, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not only about lazy reads. The original data may be already present in the Cache, so no need to read from the disk in that case.

I also agree that it can be in a future PR. The solution might be to pass in the original to-split pin to do splits, that also need refactors in the ObjectDataHandler as it always do removal and insertions in separate rounds in the current implementation.

@zhscn what do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The original data may be already present in the Cache

The details of lazy reads are still incomplete in my mind, but I think lazy reads should handle this case.

The solution might be to pass in the original to-split pin to do splits, that also need refactors in the ObjectDataHandler as it always do removal and insertions in separate rounds.

It seems reasonable and similar to "write_context_t" that do removals and insertions only once:

With the "write context" approach, we attach each transaction/ObjectDataHandler with a write_context_t, and cache all steps' results in it, so the workflow changes to the following:

  1. load all extents that are touched by all transaction ops
  2. do steps on top of the write_context_t, some of which mean involve extents splitting
  3. do all retires/allocations

There maybe another way to do lazy read like I have mentioned above is maintaining a structure to record all split operation and the mappings between "split extents" and "(mutated) original extents".

But I'm not convinced it finally works and the implementation looks ugly, since there are several corner cases make things complex.

@cyx1231st cyx1231st Jul 11, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For lazy read, I think the solution may not need to be that complicated.

After implementing passing in the original to-split pin. Probably to introduce an ExistCleanPlaceholder if we found that the data of the to-split pin is not present in Cache (i.e. to-split will be retired as a retired-placeholder) or is also an ExistCleanPlaceholder, the ExistCleanPlaceholder will be ignored by Cache if it is still not read out when commit.

ExistCleanPlaceholder will be replaced by a normal EXIST_CLEAN extent if user needs to read it out, so it should never leak to users as well.

Probably we don't need the ExistCleanPlaceholder as well, just to allow an EXIST_CLEAN extent to have an empty ceph::bufferptr if it is not needed yet.

Does it make sense?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This solution is better and simpler than mine, I'll try to implement it later.

@aisakaki aisakaki Jan 10, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hey @zhscn, are you still working on the lazy read? I am now trying to implement this~

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hey @zhscn, are you still working on the lazy read? I am now trying to implement this~

No problem, the lazy read branch last updated a long time ago; I'm not working on it.

zhscn added 6 commits July 11, 2022 09:59
TransactionManager::get_extents_if_live should return a list of
extents that are located in range paddr~len. When SegmentCleaner
invokes get_extents_if_live, the target extent may have been split into
multiple pieces by other transaction, so only search the paddr as key
will lose other pieces need to be rewritten.

Signed-off-by: Zhang Song <[email protected]>
@zhscn
zhscn force-pushed the wip-split-extent branch from 4acdd36 to 114502a Compare July 11, 2022 02:30

@cyx1231st cyx1231st left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@zhscn

zhscn commented Jul 11, 2022

Copy link
Copy Markdown
Member Author

jenkins test windows


if (pin_seg_addr_id != seg_addr_id ||
pin_paddr < seg_addr ||
pin_paddr.add_offset(pin_len) > seg_addr.add_offset(len)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See https://tracker.ceph.com/issues/66924 and ec2c483,

The issue proves that the extent has been moved to the same segment during reclaiming this segment, which looks strange because this segment should already be closed upon reclaiming, which means the segment is impossible to be modified upon reclaiming.

What do you think @xxhdx1985126 @zhscn ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@cyx1231st Which branch are you testing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See https://tracker.ceph.com/issues/66924 and ec2c483,

The issue proves that the extent has been moved to the same segment during reclaiming this segment, which looks strange because this segment should already be closed upon reclaiming, which means the segment is impossible to be modified upon reclaiming.

What do you think @xxhdx1985126 @zhscn ?

Does the test environment use multiple devices?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Latest main + testing PRs ( wip-yingxin-testing ).

I think the official rados-crimson suite won't use multiple devices for an OSD.

@zhscn zhscn Jul 12, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seems there are two IO transactions:

  1. write data at offset 0 with length 1MB;
  2. write data at offset 4K with length 4K, which caused lba mapping split;
    Both two transactions write data to the same segment:
    drawio
    The assertion will fail in this case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry forget to update the test log, added in the tracker.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zhscn I think so, seems the segment Seg[Dev(0),5] is just closed (04:56:50,177) before it is reclaming (04:56:50,183), so it's possible that a concurrent transaction is moving/splitting the extent into the same segment in lba, even though the segment containing the extent is closed.

Should be a simple fix, then.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The problem could be worse than expected. The root cause of this issue is that GC transactions can't retrieve all backref entries. At T1, GC transaction fetch all backref entries located at to be reclaimed region, and after the fetch completes at T2, an IO transaction invokes Cache::complete_commit which updates the cached backref entries.

Enabling multiple devices in crimson will make this process more complicated.

@cyx1231st cyx1231st Jul 15, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, it is a separate issue. I think a simple solution is to add another runtime-only state (e.g. segment_state_t::Committed) to the segments to indicate that all the transactions attempting to write a segment has been committed. And allow a segment to be considered for reclaim only after that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

5 participants