Merge pull request #7812 from FernandoS27/made-straight-from-the-nut

BufferCache: Find direction of the stream buffer increase.
This commit is contained in:
bunnei 2022-03-20 15:23:53 -07:00 committed by GitHub
commit ff2e891022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -1469,21 +1469,29 @@ typename BufferCache<P>::OverlapResult BufferCache<P>::ResolveOverlaps(VAddr cpu
overlap_ids.push_back(overlap_id); overlap_ids.push_back(overlap_id);
overlap.Pick(); overlap.Pick();
const VAddr overlap_cpu_addr = overlap.CpuAddr(); const VAddr overlap_cpu_addr = overlap.CpuAddr();
if (overlap_cpu_addr < begin) { const bool expands_left = overlap_cpu_addr < begin;
if (expands_left) {
cpu_addr = begin = overlap_cpu_addr; cpu_addr = begin = overlap_cpu_addr;
} }
end = std::max(end, overlap_cpu_addr + overlap.SizeBytes()); const VAddr overlap_end = overlap_cpu_addr + overlap.SizeBytes();
const bool expands_right = overlap_end > end;
if (overlap_end > end) {
end = overlap_end;
}
stream_score += overlap.StreamScore(); stream_score += overlap.StreamScore();
if (stream_score > STREAM_LEAP_THRESHOLD && !has_stream_leap) { if (stream_score > STREAM_LEAP_THRESHOLD && !has_stream_leap) {
// When this memory region has been joined a bunch of times, we assume it's being used // When this memory region has been joined a bunch of times, we assume it's being used
// as a stream buffer. Increase the size to skip constantly recreating buffers. // as a stream buffer. Increase the size to skip constantly recreating buffers.
has_stream_leap = true; has_stream_leap = true;
if (expands_right) {
begin -= PAGE_SIZE * 256; begin -= PAGE_SIZE * 256;
cpu_addr = begin; cpu_addr = begin;
}
if (expands_left) {
end += PAGE_SIZE * 256; end += PAGE_SIZE * 256;
} }
} }
}
return OverlapResult{ return OverlapResult{
.ids = std::move(overlap_ids), .ids = std::move(overlap_ids),
.begin = begin, .begin = begin,