Repository navigation
crimson: split ObjectDataBlock when overwriting - #45519
Conversation
|
I should get to this later this week. |
|
jenkins test make check |
|
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? |
|
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? |
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.
Not exactly, backrefs only affects rewrite process which is not leading to changes in components other than SegmentCleaner. Current designHere are some design trade-offs needs to be considered: Actually splitting process affects 3 aspects:
First problem: whether the remaining pieces of an ObjectDataBlock should exist in the form of CachedExtent after splitting and before completing transaction. 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"? With current mechanism, every step of handling transaction operation works as follows:
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.
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.
Currently checking a extent(ObjectDataBlock) are alive calls LBAManager::get_pins. The more efficient way will be calling backref tree in the future. Write ContextOf 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:
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:
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 pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
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. |
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. |
|
@athanatos I reimplement split extent under your suggestion. Here are some changes:
|
|
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? |
|
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, 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. |
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 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? |
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.
I'm not convinced this is actually necessary -- if the extent is in the write set that should probably just suffice.
Like I said, I really don't want Cache to have behavior specific to ObjectDataBlock.
data_ref doesn't seem necessary either. |
1d00e5a to
340cc4c
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
jenkins test api |
|
jenkins test make check arm64 |
|
@athanatos Sure! will take a look this week. |
57d2be9 to
2ff59e0
Compare
cyx1231st
left a comment
There was a problem hiding this comment.
My initial questions, still looking.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
In early implementation, I restrict only ObjectDataBlock can be splitted, but it seems not necessary so it becomes a generalized interface.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
|
jenkins test api |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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?:-)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:-)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- the checking of liveness of extents in space reclamation is not necessary, indeed;
- 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;
- 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.
There was a problem hiding this comment.
Yeah, I'm fine to leave it in a future PR. And this logic can simplified. I'd be happy to do this.
There was a problem hiding this comment.
Is it necessary to actually read it out?
There was a problem hiding this comment.
consider this case:
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
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- load all extents that are touched by all transaction ops
- do steps on top of the write_context_t, some of which mean involve extents splitting
- 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
This solution is better and simpler than mine, I'll try to implement it later.
There was a problem hiding this comment.
hey @zhscn, are you still working on the lazy read? I am now trying to implement this~
There was a problem hiding this comment.
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.
…_PENDING Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]> fix obj
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]>
…ting_extent Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
|
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)) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Latest main + testing PRs ( wip-yingxin-testing ).
I think the official rados-crimson suite won't use multiple devices for an OSD.
There was a problem hiding this comment.
Sorry forget to update the test log, added in the tracker.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.

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:
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:
1. random write to empty image
fio config
Result:
2. random write to full image
2.1. the length of extent in image is 4KiB
sequential write with fio
After the image is full, start random writes
random write with fio
2.2. the length of extent in image is 64KiB
sequential write with fio
After the image is full, start random writes
random write with fio
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
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 windows