-
Notifications
You must be signed in to change notification settings - Fork 543
UCT/CUDA_IPC: Keep lru invariant - region in cache <-> region in lru #11363
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
Open
nbellalou
wants to merge
2
commits into
openucx:v1.21.x
Choose a base branch
from
nbellalou:cudaIpcLru_bugFIx
base: v1.21.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−23
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,22 +302,32 @@ class test_cuda_ipc_cache_lru : public ucs::test { | |
| void release_region(uct_cuda_ipc_cache_region_t *region) { | ||
| ASSERT_GE(region->refcount, 1UL); | ||
| region->refcount--; | ||
| if (!region->in_lru) { | ||
| ucs_list_add_tail(&m_cache->lru_list, ®ion->lru_list); | ||
| region->in_lru = 1; | ||
| } | ||
| } | ||
|
|
||
| void reacquire_region(uct_cuda_ipc_cache_region_t *region) { | ||
| /* Move to LRU tail (most recently used) */ | ||
| if (region->in_lru) { | ||
| ucs_list_del(®ion->lru_list); | ||
| } | ||
| ucs_list_del(®ion->lru_list); | ||
| ucs_list_add_tail(&m_cache->lru_list, ®ion->lru_list); | ||
| region->in_lru = 1; | ||
| region->refcount++; | ||
| } | ||
|
|
||
| void destroy_region(uct_cuda_ipc_cache_region_t *region) | ||
| { | ||
| ucs_status_t status = ucs_pgtable_remove(&m_cache->pgtable, | ||
| ®ion->super); | ||
| ASSERT_EQ(UCS_OK, status); | ||
|
|
||
| ASSERT_TRUE(region->in_lru); | ||
| ucs_list_del(®ion->lru_list); | ||
| region->in_lru = 0; | ||
|
|
||
| ASSERT_GT(m_cache->num_regions, 0UL); | ||
| m_cache->num_regions--; | ||
| m_cache->total_size -= region->key.b_len; | ||
|
|
||
| ucs_free(region); | ||
| } | ||
|
|
||
| void evict_lru() { | ||
| uct_cuda_ipc_cache_region_t *region, *tmp; | ||
|
|
||
|
|
@@ -328,9 +338,6 @@ class test_cuda_ipc_cache_lru : public ucs::test { | |
| } | ||
|
|
||
| if (region->refcount > 0) { | ||
| /* In-use -- pull off LRU, will be re-added on release */ | ||
| ucs_list_del(®ion->lru_list); | ||
| region->in_lru = 0; | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -530,3 +537,28 @@ UCS_TEST_F(test_cuda_ipc_cache_lru, unlimited) { | |
| EXPECT_TRUE(pgtable_has(i)); | ||
| } | ||
| } | ||
|
|
||
| UCS_TEST_F(test_cuda_ipc_cache_lru, stale_destroy_while_in_use) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you verify the test fails before the PR?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did now |
||
| /* Check that evict_lru does not pull in-use regions off | ||
| * the LRU. This could cause a failure if region is destroyed | ||
| * while not in LRU. */ | ||
| create_cache(0 /* force eviction on every insert */, SIZE_MAX); | ||
|
|
||
| uct_cuda_ipc_cache_region_t *r1 = insert_region(0); | ||
| ASSERT_EQ(1UL, r1->refcount); | ||
| ASSERT_EQ(1, r1->in_lru); | ||
|
|
||
| evict_lru(); | ||
|
|
||
| /* Core assertion: in-use region must stay on LRU after eviction */ | ||
| EXPECT_EQ(1, r1->in_lru); | ||
| EXPECT_EQ(1UL, m_cache->num_regions); | ||
| EXPECT_TRUE(pgtable_has(0)); | ||
|
|
||
| /* Simulate the stale-buffer_id destroy path */ | ||
| destroy_region(r1); | ||
|
|
||
| EXPECT_EQ(0UL, m_cache->num_regions); | ||
| EXPECT_EQ(0UL, m_cache->total_size); | ||
| EXPECT_TRUE(ucs_list_is_empty(&m_cache->lru_list)); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it always 1 now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in_lru should always be 1 now because every region in cache should be in lru. However, I think it worth keeping the field and the assert ucs_assertv(region->in_lru) for debuggability and to detect potential future issues in CI, given the small memory cost of 1 byte (uint8_t)