-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Maybe fix for improper reuse #8830
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -174,17 +174,21 @@ void LRUEvictionPolicy::claimBlock(BlockPtr block, std::optional<executor::Reten | |||||||||||
| { | ||||||||||||
| mFreeQueues[cacheLevel][getPriorityIdx(block->getPriority())].erase(*mFreeBlockIterators[id]); | ||||||||||||
| mNumFreeBlocksPerLevel[cacheLevel] -= 1; | ||||||||||||
| mFreeBlockIterators[id] = std::nullopt; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| mFreeBlockIterators[id] = std::nullopt; | ||||||||||||
|
|
||||||||||||
| if (priority.has_value()) | ||||||||||||
| { | ||||||||||||
| block->setPriority(*priority); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // It is safe to call erase even if block is not found in mExpiringBlockHeap. | ||||||||||||
| mExpiringBlockHeap.erase(block); | ||||||||||||
| block->setDurationMs(durationMs); | ||||||||||||
|
|
||||||||||||
|
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. Ditto. Is this change necessary for the bug? Looks like a non-functional change to me. |
||||||||||||
| if (durationMs.has_value()) | ||||||||||||
| { | ||||||||||||
| block->setDurationMs(durationMs); | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+188
to
+191
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. Duration must be reset when no value is provided With this change a caller can no longer clear a block’s duration by passing - if (durationMs.has_value())
- {
- block->setDurationMs(durationMs);
- }
+ block->setDurationMs(durationMs);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| std::chrono::steady_clock::time_point::duration LRUEvictionPolicy::getTime() const | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1225,6 +1225,13 @@ SizeType32 WindowBlockManager::loadOrAllocateBlocks(std::vector<BlockKey> const& | |
| : std::make_tuple(false, 0, nullptr); | ||
| if (matchingBlock != nullptr) | ||
| { | ||
| // Remove matchingBlock from free queue so it does not get overwritten accidentally. | ||
| // If block is not in free queue, calling claimBlock is a noop. | ||
|
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.
|
||
| if (!matchingBlock->hasRefs()) | ||
| { | ||
| mEvictionPolicy->claimBlock(matchingBlock); | ||
| } | ||
|
|
||
| KVCacheBlock::IdType matchingBlockId = matchingBlock->getBlockId(); | ||
|
|
||
| numMatchedTokens += numMatched > 0 ? numMatched : blockItr->uniqueTokens.size(); | ||
|
|
@@ -1252,13 +1259,20 @@ SizeType32 WindowBlockManager::loadOrAllocateBlocks(std::vector<BlockKey> const& | |
| *blockItr, blockItr->uniqueTokens.size() == static_cast<size_t>(mTokensPerBlock)); | ||
| } | ||
| matchingBlock->setHash(); | ||
| if (!matchingBlock->hasRefs()) | ||
| { | ||
| // Return matchingBlock to free queue since we have copied it and won't be using matchingBlock itself | ||
| mEvictionPolicy->releaseBlock(matchingBlock); | ||
| } | ||
| TLLM_LOG_DEBUG("%s::loadOrAllocateBlocks - Copied partially filled block %d", mLogPrefix.c_str(), | ||
| matchingBlockId); | ||
| } | ||
| else | ||
| { | ||
| // Leaf block that nobody is using. Make block private and reuse | ||
| freeLeafBlock(matchingBlock); | ||
| // It is safe to call claimBlock a second time. | ||
| // This call merely sets priority and duration. | ||
| mEvictionPolicy->claimBlock( | ||
| matchingBlock, perBlockRetentions[bi].retentionPriority, perBlockRetentions[bi].durationMs); | ||
| TLLM_LOG_DEBUG("%s::loadOrAllocateBlocks - Reused partially filled block %d", mLogPrefix.c_str(), | ||
|
|
@@ -1269,6 +1283,8 @@ SizeType32 WindowBlockManager::loadOrAllocateBlocks(std::vector<BlockKey> const& | |
| else | ||
| { | ||
| // Recover block and reuse | ||
| // It is safe to call claimBlock a second time. | ||
| // This call merely sets priority and duration. | ||
| mEvictionPolicy->claimBlock( | ||
| matchingBlock, perBlockRetentions[bi].retentionPriority, perBlockRetentions[bi].durationMs); | ||
| TLLM_LOG_DEBUG("%s::loadOrAllocateBlocks - Matched full block %d", mLogPrefix.c_str(), matchingBlockId); | ||
|
|
||
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.
Is this change necessary for the bug? Looks like a non-functional change to me.