Skip to content

Commit c6713f6

Browse files
Darshan M Nsvoj
authored andcommitted
Bug#23631471 BUF_BLOCK_ALIGN() MAKES INCORRECT ASSUMPTIONS ABOUT CHUNK SIZE
Issue: ====== Currently the approach we take to find the chunk corresponding to a given pointer uses srv_buf_pool_chunk_unit based on the assumption that srv_buf_pool_chunk_unit is the total size of all pages in a buffer pool chunk. We first step back by srv_buf_pool_chunk_unit bytes and use std::map::upper_bound() to find the first chunk in the map whose key >= the resulting pointer. However, the real size of a chunk (and thus, the total size of its pages) may differ from the value configured with innodb_buffer_pool_chunk_size due to rounding up to the OS page size. So, in some cases the above logic gives us the wrong chunk. Fix: ==== We find out the chunk corresponding to the give pointer without using srv_buf_pool_chunk_unit. This is done by using std::map::upper_bound() to find the next chunk in the map which appears right after the pointer and decrementing the iterator, which would give us the chunk the pointer belongs to. Contribution by Alexey Kopytov. RB: 13347 Reviewed-by: Debarun Banerjee <debarun.banerjee@oracle.com>
1 parent ce10116 commit c6713f6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

storage/innobase/buf/buf0buf.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3940,14 +3940,17 @@ buf_block_from_ahi(const byte* ptr)
39403940
ut_ad(buf_chunk_map_ref == buf_chunk_map_reg);
39413941
ut_ad(!buf_pool_resizing);
39423942

3943-
const byte* bound = reinterpret_cast<uintptr_t>(ptr)
3944-
> srv_buf_pool_chunk_unit
3945-
? ptr - srv_buf_pool_chunk_unit : 0;
3946-
it = chunk_map->upper_bound(bound);
3943+
buf_chunk_t* chunk;
3944+
it = chunk_map->upper_bound(ptr);
3945+
3946+
ut_a(it != chunk_map->begin());
39473947

3948-
ut_a(it != chunk_map->end());
3948+
if (it == chunk_map->end()) {
3949+
chunk = chunk_map->rbegin()->second;
3950+
} else {
3951+
chunk = (--it)->second;
3952+
}
39493953

3950-
buf_chunk_t* chunk = it->second;
39513954
ulint offs = ptr - chunk->blocks->frame;
39523955

39533956
offs >>= UNIV_PAGE_SIZE_SHIFT;

0 commit comments

Comments
 (0)