Skip to content

crimson/os/seastore: add back-reference - #45390

Merged
athanatos merged 23 commits into
ceph:masterfrom
xxhdx1985126:wip-backref2
May 11, 2022
Merged

athanatos merged 23 commits into
ceph:masterfrom
xxhdx1985126:wip-backref2

Conversation

@xxhdx1985126

@xxhdx1985126 xxhdx1985126 commented Mar 15, 2022 •

Copy link
Copy Markdown
Member

Back-reference generally works as follows:

  1. For every transaction, all paddr alloc/release information is first recorded as alloc_delta_t in the record for the purpose of replaying and cached in Cache::backref_buffer/backref_bufs_to_flush;
  2. Later when triming journal, cached alloc/release backref entries are inserted into backref tree in batches.
  3. During system startup, backref tree and backref cache(both are constructed by replaying the journal) are scanned instead of lba tree;
  4. paddrs of backref extents in the backref tree are recorded in Cache::backref_extents, a pure-in-memory index which is also constructed by scanning backref tree.

Several notes:

  1. The complete back reference view is comprised of backrefs in the backref tree and the Cache;
  2. Since backref entries insertions/deletions are not idempotent for now, journal triming must move forward in the unit of journal seqs and journal_tail are recorded in segment tails and each journal group header; this makes sure that no alloc/release information can be replayed more than once;
  3. Before an extent's backref is inserted into the backref tree, it can be removed/rewritten, so when reclaiming segments, all backrefs up to that of the retiring of the last rewritten extent must all be inserted; otherwise, the following scenario may occur: an extent E's previous segment is reclaimed and reopened for write, an backref extent B is placed in the exact position where extent E is previously placed, which means the B's paddr would be the same as E in the backref tree if the retiring of E has not yet taken place in the backref tree.
  4. Retirements caused by segments reclaiming immediately take effects in the backref tree, no alloc_delta_t is recorded

Signed-off-by: Xuehan Xu [email protected]

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

@xxhdx1985126
xxhdx1985126 requested a review from a team as a code owner March 15, 2022 13:48
@xxhdx1985126
xxhdx1985126 marked this pull request as draft March 15, 2022 13:48
@xxhdx1985126

Copy link
Copy Markdown
Member Author

I'm still debugging this pr

@xxhdx1985126

Copy link
Copy Markdown
Member Author

the first 3 commits come from pr #44912

@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

@xxhdx1985126
xxhdx1985126 force-pushed the wip-backref2 branch 2 times, most recently from 6bc0124 to 57f95fe Compare March 30, 2022 04:29
@xxhdx1985126
xxhdx1985126 marked this pull request as ready for review March 30, 2022 04:30
@xxhdx1985126
xxhdx1985126 marked this pull request as draft March 30, 2022 04:30
@xxhdx1985126
xxhdx1985126 marked this pull request as ready for review March 30, 2022 09:11
@xxhdx1985126

Copy link
Copy Markdown
Member Author

jenkins test make check

1 similar comment
@xxhdx1985126

Copy link
Copy Markdown
Member Author

jenkins test make check

@xxhdx1985126
xxhdx1985126 marked this pull request as draft March 31, 2022 09:01
@xxhdx1985126
xxhdx1985126 marked this pull request as ready for review April 4, 2022 10:06
@xxhdx1985126 xxhdx1985126 changed the title [WIP]crimson/os/seastore: add back-reference crimson/os/seastore: add back-reference Apr 4, 2022
@github-actions

github-actions Bot commented Apr 4, 2022

Copy link
Copy Markdown

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

@xxhdx1985126

xxhdx1985126 commented Apr 5, 2022 •

Copy link
Copy Markdown
Member Author

rbd client stress test

image
we can see visible perf improvement, not too much though

early perf analysis

Before backref
image
After backref
image
The cpu time spent polling has been reduced, but we can still see about 18% of cpu time invoking kernel polls

This may be due to the fact that, when available disk space is less than available_ratio_hard_limit,
all transactions has to wait for the rewrite transaction to complete. Need more proofs.

On the other hand, we can also observe the phenomenon that cleaner's space reclaiming is much faster
when the available disk space is less than available_ratio_hard_limit:

avail_disk_space < available_ratio_hard_limit avail_disk_space > available_ratio_hard_limit
avg reclaim time(second) per segment 0.520661s 2.14902s
avg repeated transaction runs per transaction (indicating number of conflicts per transaction) 1 7.69697

This may be due to conflicts between space reclaim transaction and client io transactions.

…ger/backref_manager's complete_transaction

Signed-off-by: Xuehan Xu <[email protected]>
…loc infos in segment header/tail

Signed-off-by: Xuehan Xu <[email protected]>
…sk without initializing

For the purpose of higher space reclaim perf, we load backref extents by
parallelly invoking Cache::get_extent_by_type, which means loaded backref
extents won't be initialized

Signed-off-by: Xuehan Xu <[email protected]>
This should reduce the conflicts between gc transactions and io transactions

Signed-off-by: Xuehan Xu <[email protected]>
@xxhdx1985126

xxhdx1985126 commented May 7, 2022 •

Copy link
Copy Markdown
Member Author

See A-before1 and B-after2. The conflicts from different types of extents are just got propotional larger, meaning they might be unrelated to why conflicts become intensified.

Yes, I just wanted to confirm that your test's result is consistent with mine.

I think I can explain why we see more invalid writes and conflicts between gc transactions and io transactions: extents rewriting now operates the backref tree, which will create backref extents which doesn't exist before this pr and will be counted as invalid writes if the transaction gets invalidated, so we see more invalid writes. Since extents rewriting needs to operates the backref tree, the time it takes to complete gc transactions becomes longer, the longer it takes, the more possible gc transactions get invalidated.

This pr is partly aiming at improving performance of space reclamation by avoiding the need to scan disks for reclaiming the corresponding disk space, the effect is shown in https://gist.github.com/xxhdx1985126/8e038946ad53bb3c021cbfaf5e7fa022.

As to the conflicts and invalid writes issue, I think we can avoid it completely by eliminating the possibility of conflicts between gc transactions and io transactions, which is exactly what I'm working on right now.

@cyx1231st

Copy link
Copy Markdown
Member

From my understanding from #46158 (comment), I agree with @xxhdx1985126 's point that the existing reclaiming logic is not efficient, and the backref tree is helpful in this case:

  • During reclaim, the extents in the target segment are mostly not alive, but the existing reclaim logic still needs to check every extent with TransactionManager::get_extent_if_live();
  • The reclaiming process is too slow so that the number of closed segments keep increased until the write is stopped, even though there is nearly nothing to reclaim in the target segments;

@athanatos

Copy link
Copy Markdown
Contributor

@cyx1231st I'm ok with merging this once you're happy with it.

@athanatos
athanatos self-requested a review May 11, 2022 04:53
@cyx1231st

Copy link
Copy Markdown
Member

Generally look good to me, except the concern from thread #45390 (comment).

I think we can avoid it completely by eliminating the possibility of conflicts between gc transactions and io transactions, which is exactly what I'm working on right now.

@xxhdx1985126 I'm curious about how to eliminate these conflicts, would you mind elaborating more about it?

@athanatos
athanatos merged commit 12d0955 into ceph:master May 11, 2022
@xxhdx1985126

xxhdx1985126 commented May 18, 2022 •

Copy link
Copy Markdown
Member Author

@xxhdx1985126 I'm curious about how to eliminate these conflicts, would you mind elaborating more about it?

@cyx1231st Sorry that I missed your comment the other day.

About elimiting the conflicts, what I really meant was that, I planned to modify the current transaction conflicts handling mechanism, so that, instead of rolling back other transactions, we make conflicting transactions agree on the final outcome, and the repeat overhead can be avoided. But, this turns out to be complicated, I'm trying to see if it's worth it, right now. Or maybe there are other solutions, like what sam suggested in: https://gist.github.com/xxhdx1985126/1c49d0de2a8590aed5d62e611cbc63cd

I'm really sorry for replying so late.

@cyx1231st

Copy link
Copy Markdown
Member

@xxhdx1985126 no worry at all.

so that, instead of rolling back other transactions, we make conflicting transactions agree on the final outcome, and the repeat overhead can be avoided. But, this turns out to be complicated

Yeah, I agree that this is complicated. For example, how to coordinate multiple conflicting transactions that are trying to split the same set of tree nodes but in different ways.

@athanatos

Copy link
Copy Markdown
Contributor

A quick sketch of what this might look like for onode or lba tree nodes is:

  • each extent tracks version number for each entry
  • each transaction for each extent tracks which entries it read and at what version
  • a transaction at commit time for each extent with a conflict
    • checks the specific keys it actually read and conflicts if the version changed
    • otherwise it replays its deltas on the new version of the extent and conflicts if it violates a btree invariant (too large/too small) -- conflict detection would ensure that such a replay is otherwise well formed

The above would impose a lot of overhead and is actually more similar to what we already do than it appears. A straightforward way to reduce the overhead would be to version groups of keys rather than individual keys with larger groups corresponding to smaller memory/runtime overhead. There's a continuum of conflict detection vs memory tradeoffs: individual key vs groups of keys within an extent vs single whole extent group (what we do now).

We can test the whether the above is worth bothering with by artificially restricting the size of lba/onode btree nodes as that would have the same effect of reducing the key conflict group size.

@xxhdx1985126

Copy link
Copy Markdown
Member Author

We can test the whether the above is worth bothering with by artificially restricting the size of lba/onode btree nodes as that would have the same effect of reducing the key conflict group size.

Yeah, I'm working on that.

@cyx1231st

Copy link
Copy Markdown
Member

If the major issue is only between MUTATE and CLEANER_RECLAIM transactions, another possible way might be to decrease reclaim_bytes_per_cycle and allow CLEANER_RECLAIM transactions to run in parallel.

This might be simpler than adding version number to the keys, as the key layout of ONODE tree is already very complicated.

@xxhdx1985126

xxhdx1985126 commented May 19, 2022 •

Copy link
Copy Markdown
Member Author

If the major issue is only between MUTATE and CLEANER_RECLAIM transactions, another possible way might be to decrease reclaim_bytes_per_cycle and allow CLEANER_RECLAIM transactions to run in parallel.

I think those parallel cleaner_reclaim transactions can conflict with each other on the lba/backref tree, am I right? The backref tree is indexed by paddr, so those transactions can have a relative high probability of colliding on the same backref extent. Altough, for the backref part, maybe we can separate the backref tree updates from cleaner_reclaim transactions into dedicated transactions, which is what I'm trying to see the feasibility of now(related to the drawback I mentioned here), there's still conflicts on the lba tree, with which we have to deal, right?

This might be simpler than adding version number to the keys, as the key layout of ONODE tree is already very complicated.

Actually, for the logical extents, I had another idea:

Since rewriting logical extents doesn't cause any change to the logical extents itself at all. So I think maybe we optimize gc perf by making the space reclamation and journal trimming transaction do the extent content copy after they enter the "prepare" phase. With this approach, client io transactions can only contradict the gc transactions on logical extents in the following two scenarios:

  1. client io transactions remove some logical extents that are to be rewritten;
  2. client io transactions mutate some logical extents and invalidate the old version of those logical extents;
    For scenario 1, I think we can simply let gc transactions skip rewriting those removed extents; for scenario 2, I think we can easily add some facility to LogicalCachedExetnt to allow gc transactions to find the most recent version of the logical extents to be rewritten, and rewrite that new version's content.

(BTW, this may be actually more complicated than it seems, as sam suggested)

But on the other hand, according to the test result here, cleaner_trim transactions conflicts with io transactions mostly on lba nodes and seldom on logical extents, maybe we can skip the onode tree modification for dealing with the issue of space reclamation transactions' conflicts for now. Am I right?

I think your pr #46310 has reduced conflicts on onode extents of trim transactions very well, and we can wait until the space reclamation conflicts are solved to see whether we need to work further on the onode tree. What do you think?

@cyx1231st

Copy link
Copy Markdown
Member

Yeah, agree with you that onode conflict seems not a major issue right now.

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.

3 participants