Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCS/UCP/RCACHE: Store memh completion in request #10190

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iyastreb
Copy link
Contributor

What

The aim of this PR is to prepare infra for RNDV PPLN invalidation, which will be implemented without using rcache invalidation. Currently rcache stores completion entries within its private memory pool, and the proposed change is to move that completion entry to UCP request.

Why ?

  • This allows to use invalidation completion without rcache (will be used in the subsequent PR)
  • There is no memory overhead in UCP request, because we reuse invalidate union struct
  • Less memory usage in rcache
  • Rcache does not need to bother with memory pool and acquire locks to deal with completion entries

How ?

  • Request owns the completion entry within invalidate struct
  • Safe invalidation: separate check for invalidate from invalidation itself. This is needed to deallocate request resources before request becomes invalidated (because invalidation updates the union -> may corrupt the object, and it may happen synchronously)

if (req->send.rndv.rkey != NULL) {
ucp_proto_rndv_rkey_destroy(req);
}
ucp_proto_request_zcopy_id_reset(req);
ucp_request_memh_invalidate(req, status);
Copy link
Contributor

Choose a reason for hiding this comment

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

are we able to add ucp_request_memh_invalidate() right after the check line 226, or some req field might touched after?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should put ucp_request_memh_invalidate call just before ucp_proto_request_zcopy_id_reset.
But we cannot put it before ucp_proto_rndv_rkey_destroy, because that function uses field from union rndv part of the request, which gets invalidated by invalidate struct.

@@ -395,50 +395,65 @@ static ucp_md_map_t ucp_request_get_invalidation_map(ucp_ep_h ep)
return inv_map;
}

int ucp_request_memh_invalidate(ucp_request_t *req, ucs_status_t status)
static UCS_F_ALWAYS_INLINE ucp_mem_h* ucp_request_get_memh(ucp_request_t *req)
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like no need in pointer

Suggested change
static UCS_F_ALWAYS_INLINE ucp_mem_h* ucp_request_get_memh(ucp_request_t *req)
static UCS_F_ALWAYS_INLINE ucp_mem_h ucp_request_get_memh(ucp_request_t *req)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pointer is actually used to assign NULL to memh, on line 456:

 *memh_p = NULL;

Copy link
Contributor

Choose a reason for hiding this comment

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

pointer is not needed as a return value of this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's needed, please check again
We assign NULL value to the request field, which address is stored in memh_p

Copy link
Contributor

Choose a reason for hiding this comment

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

ah.. found it but IMO this is a not good idea to set value using "getter", maybe reset the field directly by req->send.state.dt_iter.type.contig.memh = NULL at line 448?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint. That would work if we always unconditionally replace original memh field by NULL.
But it's slightly more involved here, because I use the same function in ucp_request_memh_check_invalidate, that must not change the request, so it must be pure get.
But I'll think a bit more on how to make it less confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored it in the latest PR with entire invalidation solution, used extract approach:
03123f7

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 does it mean that this PR is not relevant any more?
( just cross reference PRs #10204 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hoping to merge this small low-risk PR in the current release, but no luck.
I will confirm with tech leads on Monday whether it makes sense to split the overall solution into several pieces

Copy link
Contributor

Choose a reason for hiding this comment

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

then maybe cherry-pick 03123f7 to here?

@@ -54,10 +54,11 @@ enum {
UCP_REQUEST_FLAG_RKEY_INUSE = UCS_BIT(18),
UCP_REQUEST_FLAG_USER_HEADER_COPIED = UCS_BIT(19),
UCP_REQUEST_FLAG_USAGE_TRACKED = UCS_BIT(20),
UCP_REQUEST_FLAG_INVALIDATED = UCS_BIT(21),
Copy link
Contributor

Choose a reason for hiding this comment

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

  • pls move under UCS_ENABLE_ASSERT section
  • need better name since it's irrelevant for any request, e.g. UCP_REQUEST_FLAG_MEMH_INVALIDATED

Copy link
Contributor Author

@iyastreb iyastreb Oct 1, 2024

Choose a reason for hiding this comment

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

In this PR it's used only within ucs_assert, but in the upcoming invalidation PR I use this flag in a couple of places to check whether request had been already invalidated. But I'll check once again if I manage to get rid of those checks. So far it's not easy, because in some parts of the code after invalidation we still access rndv part.

This flag indicates invalidated request (not just memory handle), meaning the request which populated invalidate struct from the send union. As a consequence, we cannot safely access other union structures from invalidated request (e.g. we can't anymore safely access rndv part). So in fact this is the property of request itself

Copy link
Contributor

Choose a reason for hiding this comment

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

  • lets move back when and IF it's really needed
  • we dont have dedicated flags for union members, all prevoius flags named by state and/or action, IMO "invalidated request " may have to wide meaning without context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I will add code to this PR that actually uses this flag in production code path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants