Repository navigation
crimson/osd/object_context_loader: Fix obc cache existence usage - #57725
Conversation
with_head_obc() uses get_cached_obc() to get_or_create obc instances. If the obc exists in cache, get_or_load_obc is called with `existed`=true. The assumption above is wrong. Cache existence (`existed`) only guarantees that the obc instance was created (and inserted) in the obc_registery. However, it does **not** assure that the obc was actually loaded. As obc-loading is now concurrent, it's possible for the first user to only create the obc in cache (without loading yet) and the second concurrent user to assume it was already loaded. With this patch, we verify that the obc was loaded in get_or_load_obc. * make loading-obc concurrent PR: ceph#55488 Fixes: https://tracker.ceph.com/issues/64206 Fixes: https://tracker.ceph.com/issues/66214 Signed-off-by: Matan Breizman <[email protected]>
Signed-off-by: Matan Breizman <[email protected]>
2e3c8d3 to
ccc0001
Compare
| auto loaded = | ||
| load_obc_iertr::make_ready_future<ObjectContextRef>(obc); | ||
| if (existed) { | ||
| if (existed && obc->is_loaded()) { |
There was a problem hiding this comment.
I think this is the correct direction to return only until the obc is loaded.
As obc-loading is now concurrent, it's possible for the first user to only create the obc in cache (without loading yet) and the second concurrent user to assume it was already loaded.
But I think the first user must create and also start to load the obc at the same time. So the second (maybe-concurrent) user should assume it is already loading or already loaded.
(If I'm wrong above, can you help point to the violating logic?)
If I'm correct above, I think the accurate pseudo logic might be:
if (existed && obc->is_loaded()) {
return load_obc_iertr::make_ready_future<ObjectContextRef>(obc);
} else if (existed) {
// not the first user, the obc must be already loading,
// return the loading future, instead of loading the obc again.
} else { // !existed: the first user
return obc->template with_promoted_lock<State, IOInterruptCondition>(
[obc, this] { return load_obc(obc); }
);
}However, the current version should be fine to address the assert failure.
There was a problem hiding this comment.
But I think the first user must create and also start to load the obc at the same time. So the second (maybe-concurrent) user should assume it is already loading or already loaded.
This is correct. Broadly speaking, the pseudo logic should work, though I'm now sure it's worth the additional logic. This will require maintaining the loading future from the "first-user" for the "second" one to use later, instead of loading again.
The main reason for avoiding implementing the pseudo logic is that this scenario is rare. This was quite frequent in testing was because the obc_lru_size is set to 10 (to reduce cache hits).
@cyx1231st, I suggest merging as is to resolve the bug. Later on, we could rework this bit if needed. What do you think?
There was a problem hiding this comment.
This is correct. Broadly speaking, the pseudo logic should work, though I'm now sure it's worth the additional logic. This will require maintaining the loading future from the "first-user" for the "second" one to use later, instead of loading again.
@Matan-B #57687 is for this purpose, it avoid loading the obc again by making sure the exist check and the load happens synchronously, maybe we should consider it?
There was a problem hiding this comment.
@Matan-B #57687 is for this purpose, it avoid loading the obc again by making sure the
existcheck and the load happens synchronously, maybe we should consider it?
@xxhdx1985126 , To consider the benefit of avoiding the extra load we need to understand how frequent this scenario is. IIUC, a normal workload (not thrash test), with a decent size of obc_lru_size (default of 512) - should not be impacted by this.
For this reason, I'm leaning towards readability and maintainability here.
There was a problem hiding this comment.
Note: I'm scheduling a test run since this assert causes too many jobs to fail and merging is blocked, please let me know if you don't agree with my previous comments.
There was a problem hiding this comment.
@Matan-B @cyx1231st I think this pr may fail. According to the following code, we can't promote the lock to EXCL when there are multiple readers/writers. Am I missing something?
void tri_mutex::promote_from_read()
{
assert(readers == 1);
--readers;
exclusively_used = true;
}
void tri_mutex::promote_from_write()
{
assert(writers == 1);
--writers;
exclusively_used = true;
}
There was a problem hiding this comment.
@cyx1231st, I suggest merging as is to resolve the bug. Later on, we could rework this bit if needed. What do you think?
I'm fine to address the specific assert failure with a simple fix, and then find a proper way to avoid loading the same obc.
And I think it is also related to https://tracker.ceph.com/issues/65451, because allowing the non-first user(s) to load the same obc (in the promoted/exclusive lock) concurrently should violate the assertion `readers/writers == 1' upon promotion. (@xxhdx1985126 also points it out above)
This will require maintaining the loading future from the "first-user" for the "second" one to use later, instead of loading again. The main reason for avoiding implementing the pseudo logic is that this scenario is rare. ..
A per-obc seastar::shared_mutex<> may be helpful to make the concurrent users (except the first user) to wait outside the promoted/exclusive lock until the obc is loaded, and also preserve the waiting order. Otherwise, we might need to rethink tri-mutex and the lock promotion. Anyway, the exclusive constraint to load the same obc makes more sense to me.
There was a problem hiding this comment.
@Matan-B @cyx1231st I think this pr may fail. According to the following code, we can't promote the lock to EXCL when there are multiple readers/writers. Am I missing something?
void tri_mutex::promote_from_read() { assert(readers == 1); --readers; exclusively_used = true; } void tri_mutex::promote_from_write() { assert(writers == 1); --writers; exclusively_used = true; }
Ah, that's correct.
A per-obc seastar::shared_mutex<> may be helpful to make the concurrent users (except the first user) to wait outside the promoted/exclusive lock until the obc is loaded, and also preserve the waiting order.
I like this approach, will update the PR. If this will result in unelegant code we could reconsider #57687.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
@cyx1231st Maybe SeaStore's Cache::get_extent()-like methods can also follow this approach?
There was a problem hiding this comment.
@xxhdx1985126 Sorry I'm not following. Which mutex/lock are you refering to in the Cache::get_extent() related path?
There was a problem hiding this comment.
@xxhdx1985126 Sorry I'm not following. Which mutex/lock are you refering to in the
Cache::get_extent()related path?
Sorry, I didn't make myself clear. With regard to SeaStore::Cache, we have a similar issue and we need to make sure that the check for whether an extent is in Cache and the load of the missing extent are synchronous. Maybe we can take an approach like this pr, adding a mutex/lock for each extent and locking it when trying to load the extent from disk. What do you think?
There was a problem hiding this comment.
If there is no specific blocking problem that the current way cannot cover (or it result in unacceptabe complexity). Probably it's better to keep the existing way.
The mutex added in this case is because otherwise the code will break.
36d6e05 to
622db94
Compare
|
Approved commits left intact, I'll squash after CR. |
c3de6dd to
6a1f5e4
Compare
6a1f5e4 to
1b11fb4
Compare
@cyx1231st, included. Thanks! |
|
It seems that 55e7e13109c7085486efbea21b02324a3bb90352 couldn't ensure the atomic call.
Sanitized crash: CC: @cyx1231st Update: It looks that the call |
|
Quote my previous comment.
After a second thought, I think "preserve the waiting order" might not be a necessary requirement here, the design of phases (if implemented correctly) should already sufficient to recover the original order upon entering the next exclusive phase: ceph/src/crimson/osd/osd_operations/client_request.cc Lines 347 to 357 in d18b722 (i.e. upon entering the next exclusive "process" phase)
I agree with you,
I think the assumption is incorrect, see the promoted lock interface: ceph/src/crimson/common/tri_mutex.h Lines 28 to 39 in d18b722 I don't think these promoted locks support waiting yet, their |
b801e75 to
cf00dc7
Compare
I have switched to the atmoic version when using the per-obc mutex. I will note that on local tests I was not able to trigger the per-obc mutex to actually make any user wait (with the new change). It looks to me that the call to promote was atomic and therefore the second user was waiting outside of |
|
@athanatos @cyx1231st, results look great! I want to merge this asap in order to unblock other awaiting PRs, PTAL. |
Signed-off-by: Matan Breizman <[email protected]>
Signed-off-by: Matan Breizman <[email protected]>
to be used only for testing Signed-off-by: Matan Breizman <[email protected]>
Signed-off-by: Matan Breizman <[email protected]>
Signed-off-by: Yingxin Cheng <[email protected]> Signed-off-by: Matan Breizman <[email protected]>
Otherwise, promotion cannot be atomic with the 1st locker. Identified by: Matan Breizman <[email protected]> Signed-off-by: Yingxin Cheng <[email protected]>
make use of try_lock in order to support atomicity when called in ObjectContext::_with_lock() Co-authored-by: Yingxin Cheng <[email protected]> Signed-off-by: Matan Breizman <[email protected]>
cf00dc7 to
1675ce8
Compare
|
changeset: squashed a reverted commit (same diff) |
|
jenkins test api |
|
am I correct that a "tri_mutex" is not a mutex but rather a future-enabled reader-writer lock? |
Yes, though not a traditional reader-writer lock, attaching the header comment: |
|
@mattbenjamin Kinda, it's multi-writer, multi-reader, single-exclusive. It's there to model the OSD's rules for dealing with concurrent operations on a single object. |
with_head_obc() uses get_cached_obc() to get_or_create obc instances.
If the obc exists in cache, get_or_load_obc is called with
existed=true.The assumption above is wrong.
Cache existence (
existed) only guarantees that the obc instance was created (and inserted) in the obc_registery. However, it does not assure that the obc was actually loaded.As obc-loading is now concurrent, it's possible for the first user to only create the obc in cache (without loading yet) and the second concurrent user to assume it was already loaded.
With this patch, we verify that the obc was loaded for get_or_load_obc usage.
Fixes: https://tracker.ceph.com/issues/64206
Fixes: https://tracker.ceph.com/issues/66214
Since we now await for loading to finish (in-case in progress), we can
also assert is_loaded().
Fixes: https://tracker.ceph.com/issues/65451
Fixes: https://tracker.ceph.com/issues/66308
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