diff options
Diffstat (limited to 'storage/perfschema/pfs_buffer_container.h')
-rw-r--r-- | storage/perfschema/pfs_buffer_container.h | 162 |
1 files changed, 97 insertions, 65 deletions
diff --git a/storage/perfschema/pfs_buffer_container.h b/storage/perfschema/pfs_buffer_container.h index 326d4e0b676..ed1a933f545 100644 --- a/storage/perfschema/pfs_buffer_container.h +++ b/storage/perfschema/pfs_buffer_container.h @@ -1,13 +1,20 @@ /* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU General Public License, version 2.0, for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, @@ -70,7 +77,7 @@ class PFS_buffer_default_array public: typedef T value_type; - value_type *allocate(pfs_dirty_state *dirty_state, size_t max) + value_type *allocate(pfs_dirty_state *dirty_state) { uint index; uint monotonic; @@ -81,11 +88,11 @@ public: return NULL; monotonic= PFS_atomic::add_u32(& m_monotonic.m_u32, 1); - monotonic_max= monotonic + max; + monotonic_max= monotonic + m_max; - do + while (monotonic < monotonic_max) { - index= monotonic % max; + index= monotonic % m_max; pfs= m_ptr + index; if (pfs->m_lock.free_to_dirty(dirty_state)) @@ -94,7 +101,6 @@ public: } monotonic= PFS_atomic::add_u32(& m_monotonic.m_u32, 1); } - while (monotonic < monotonic_max); m_full= true; return NULL; @@ -106,9 +112,20 @@ public: m_full= false; } + T* get_first() + { + return m_ptr; + } + + T* get_last() + { + return m_ptr + m_max; + } + bool m_full; PFS_cacheline_uint32 m_monotonic; T * m_ptr; + size_t m_max; /** Container. */ PFS_opaque_container *m_container; }; @@ -123,16 +140,16 @@ public: : m_builtin_class(klass) {} - int alloc_array(array_type *array, size_t size) + int alloc_array(array_type *array) { array->m_ptr= NULL; array->m_full= true; array->m_monotonic.m_u32= 0; - if (size > 0) + if (array->m_max > 0) { array->m_ptr= PFS_MALLOC_ARRAY(m_builtin_class, - size, sizeof(T), T, MYF(MY_ZEROFILL)); + array->m_max, sizeof(T), T, MYF(MY_ZEROFILL)); if (array->m_ptr == NULL) return 1; array->m_full= false; @@ -140,10 +157,12 @@ public: return 0; } - void free_array(array_type *array, size_t size) + void free_array(array_type *array) { + DBUG_ASSERT(array->m_max > 0); + PFS_FREE_ARRAY(m_builtin_class, - size, sizeof(T), array->m_ptr); + array->m_max, sizeof(T), array->m_ptr); array->m_ptr= NULL; } @@ -171,6 +190,7 @@ public: { m_array.m_full= true; m_array.m_ptr= NULL; + m_array.m_max= 0; m_array.m_monotonic.m_u32= 0; m_lost= 0; m_max= 0; @@ -181,10 +201,11 @@ public: { if (max_size > 0) { - int rc= m_allocator->alloc_array(& m_array, max_size); + m_array.m_max= max_size; + int rc= m_allocator->alloc_array(& m_array); if (rc != 0) { - m_allocator->free_array(& m_array, max_size); + m_allocator->free_array(& m_array); return 1; } m_max= max_size; @@ -195,7 +216,7 @@ public: void cleanup() { - m_allocator->free_array(& m_array, m_max); + m_allocator->free_array(& m_array); } ulong get_row_count() const @@ -244,8 +265,8 @@ public: void apply(function_type fct) { - value_type *pfs= m_array.m_ptr; - value_type *pfs_last= pfs + m_max; + value_type *pfs= m_array.get_first(); + value_type *pfs_last= m_array.get_last(); while (pfs < pfs_last) { @@ -259,8 +280,8 @@ public: void apply_all(function_type fct) { - value_type *pfs= m_array.m_ptr; - value_type *pfs_last= pfs + m_max; + value_type *pfs= m_array.get_first(); + value_type *pfs_last= m_array.get_last(); while (pfs < pfs_last) { @@ -271,8 +292,8 @@ public: void apply(processor_type & proc) { - value_type *pfs= m_array.m_ptr; - value_type *pfs_last= pfs + m_max; + value_type *pfs= m_array.get_first(); + value_type *pfs_last= m_array.get_last(); while (pfs < pfs_last) { @@ -286,8 +307,8 @@ public: void apply_all(processor_type & proc) { - value_type *pfs= m_array.m_ptr; - value_type *pfs_last= pfs + m_max; + value_type *pfs= m_array.get_first(); + value_type *pfs_last= m_array.get_last(); while (pfs < pfs_last) { @@ -324,8 +345,8 @@ public: value_type *sanitize(value_type *unsafe) { intptr offset; - value_type *pfs= m_array.m_ptr; - value_type *pfs_last= pfs + m_max; + value_type *pfs= m_array.get_first(); + value_type *pfs_last= m_array.get_last(); if ((pfs <= unsafe) && (unsafe < pfs_last)) @@ -345,9 +366,9 @@ private: { DBUG_ASSERT(index <= m_max); - value_type *pfs_first= m_array.m_ptr; + value_type *pfs_first= m_array.get_first(); value_type *pfs= pfs_first + index; - value_type *pfs_last= pfs_first + m_max; + value_type *pfs_last= m_array.get_last(); while (pfs < pfs_last) { @@ -459,6 +480,7 @@ public: } DBUG_ASSERT(m_max_page_count <= PFS_PAGE_COUNT); + DBUG_ASSERT(0 < m_last_page_size); DBUG_ASSERT(m_last_page_size <= PFS_PAGE_SIZE); native_mutex_init(& m_critical_section, NULL); @@ -480,7 +502,7 @@ public: page= m_pages[i]; if (page != NULL) { - m_allocator->free_array(page, PFS_PAGE_SIZE); + m_allocator->free_array(page); delete page; m_pages[i]= NULL; } @@ -521,7 +543,6 @@ public: uint monotonic; uint monotonic_max; uint current_page_count; - uint page_logical_size; value_type *pfs; array_type *array; @@ -555,8 +576,7 @@ public: if (array != NULL) { - page_logical_size= get_page_logical_size(index); - pfs= array->allocate(dirty_state, page_logical_size); + pfs= array->allocate(dirty_state); if (pfs != NULL) { /* Keep a pointer to the parent page, for deallocate(). */ @@ -642,10 +662,11 @@ public: array= new array_type(); builtin_memory_scalable_buffer.count_alloc(sizeof (array_type)); - int rc= m_allocator->alloc_array(array, PFS_PAGE_SIZE); + array->m_max= get_page_logical_size(current_page_count); + int rc= m_allocator->alloc_array(array); if (rc != 0) { - m_allocator->free_array(array, PFS_PAGE_SIZE); + m_allocator->free_array(array); delete array; builtin_memory_scalable_buffer.count_free(sizeof (array_type)); m_lost++; @@ -672,8 +693,7 @@ public: } DBUG_ASSERT(array != NULL); - page_logical_size= get_page_logical_size(current_page_count); - pfs= array->allocate(dirty_state, page_logical_size); + pfs= array->allocate(dirty_state); if (pfs != NULL) { /* Keep a pointer to the parent page, for deallocate(). */ @@ -749,8 +769,8 @@ public: page= m_pages[i]; if (page != NULL) { - pfs= page->m_ptr; - pfs_last= pfs + PFS_PAGE_SIZE; + pfs= page->get_first(); + pfs_last= page->get_last(); while (pfs < pfs_last) { @@ -776,8 +796,8 @@ public: page= m_pages[i]; if (page != NULL) { - pfs= page->m_ptr; - pfs_last= pfs + PFS_PAGE_SIZE; + pfs= page->get_first(); + pfs_last= page->get_last(); while (pfs < pfs_last) { @@ -800,8 +820,8 @@ public: page= m_pages[i]; if (page != NULL) { - pfs= page->m_ptr; - pfs_last= pfs + PFS_PAGE_SIZE; + pfs= page->get_first(); + pfs_last= page->get_last(); while (pfs < pfs_last) { @@ -827,8 +847,8 @@ public: page= m_pages[i]; if (page != NULL) { - pfs= page->m_ptr; - pfs_last= pfs + PFS_PAGE_SIZE; + pfs= page->get_first(); + pfs_last= page->get_last(); while (pfs < pfs_last) { @@ -848,6 +868,12 @@ public: if (page != NULL) { uint index_2= index % PFS_PAGE_SIZE; + + if (index_2 >= page->m_max) + { + return NULL; + } + value_type *pfs= page->m_ptr + index_2; if (pfs->m_lock.is_populated()) @@ -876,8 +902,15 @@ public: return NULL; } - *has_more= true; uint index_2= index % PFS_PAGE_SIZE; + + if (index_2 >= page->m_max) + { + *has_more= false; + return NULL; + } + + *has_more= true; value_type *pfs= page->m_ptr + index_2; if (pfs->m_lock.is_populated()) @@ -901,8 +934,8 @@ public: page= m_pages[i]; if (page != NULL) { - pfs= page->m_ptr; - pfs_last= pfs + PFS_PAGE_SIZE; + pfs= page->get_first(); + pfs_last= page->get_last(); if ((pfs <= unsafe) && (unsafe < pfs_last)) @@ -925,6 +958,7 @@ private: { if (page_index + 1 < m_max_page_count) return PFS_PAGE_SIZE; + DBUG_ASSERT(page_index + 1 == m_max_page_count); return m_last_page_size; } @@ -939,7 +973,7 @@ private: value_type *pfs; value_type *pfs_last; - do + while (index_1 < PFS_PAGE_COUNT) { page= m_pages[index_1]; @@ -949,9 +983,9 @@ private: return NULL; } - pfs_first= page->m_ptr; + pfs_first= page->get_first(); pfs= pfs_first + index_2; - pfs_last= pfs_first + PFS_PAGE_SIZE; + pfs_last= page->get_last(); while (pfs < pfs_last) { @@ -968,7 +1002,6 @@ private: index_1++; index_2= 0; } - while (index_1 < PFS_PAGE_COUNT); index= m_max; return NULL; @@ -1277,7 +1310,7 @@ private: value_type *record= NULL; DBUG_ASSERT(partition_index < PFS_PARTITION_COUNT); - do + while (partition_index < PFS_PARTITION_COUNT) { sub_iterator_type sub_iterator= m_partitions[partition_index]->iterate(sub_index); record= sub_iterator.scan_next(found_sub_index); @@ -1291,7 +1324,6 @@ private: partition_index++; sub_index= 0; } - while (partition_index < PFS_PARTITION_COUNT); *found_partition= PFS_PARTITION_COUNT; *found_sub_index= 0; @@ -1366,7 +1398,7 @@ typedef PFS_cond_container::iterator_type PFS_cond_iterator; extern PFS_cond_container global_cond_container; #ifdef USE_SCALABLE -typedef PFS_buffer_scalable_container<PFS_file, 1024, 1024> PFS_file_container; +typedef PFS_buffer_scalable_container<PFS_file, 4 * 1024, 4 * 1024> PFS_file_container; #else typedef PFS_buffer_container<PFS_file> PFS_file_container; #endif @@ -1414,7 +1446,7 @@ typedef PFS_table_container::iterator_type PFS_table_iterator; extern PFS_table_container global_table_container; #ifdef USE_SCALABLE -typedef PFS_buffer_scalable_container<PFS_table_share, 1024, 1024> PFS_table_share_container; +typedef PFS_buffer_scalable_container<PFS_table_share, 4 * 1024, 4 * 1024> PFS_table_share_container; #else typedef PFS_buffer_container<PFS_table_share> PFS_table_share_container; #endif @@ -1422,7 +1454,7 @@ typedef PFS_table_share_container::iterator_type PFS_table_share_iterator; extern PFS_table_share_container global_table_share_container; #ifdef USE_SCALABLE -typedef PFS_buffer_scalable_container<PFS_table_share_index, 1024, 1024> PFS_table_share_index_container; +typedef PFS_buffer_scalable_container<PFS_table_share_index, 8 * 1024, 8 * 1024> PFS_table_share_index_container; #else typedef PFS_buffer_container<PFS_table_share_index> PFS_table_share_index_container; #endif @@ -1430,7 +1462,7 @@ typedef PFS_table_share_index_container::iterator_type PFS_table_share_index_ite extern PFS_table_share_index_container global_table_share_index_container; #ifdef USE_SCALABLE -typedef PFS_buffer_scalable_container<PFS_table_share_lock, 1024, 1024> PFS_table_share_lock_container; +typedef PFS_buffer_scalable_container<PFS_table_share_lock, 4 * 1024, 4 * 1024> PFS_table_share_lock_container; #else typedef PFS_buffer_container<PFS_table_share_lock> PFS_table_share_lock_container; #endif @@ -1466,8 +1498,8 @@ public: class PFS_account_allocator { public: - int alloc_array(PFS_account_array *array, size_t size); - void free_array(PFS_account_array *array, size_t size); + int alloc_array(PFS_account_array *array); + void free_array(PFS_account_array *array); }; #ifdef USE_SCALABLE @@ -1497,8 +1529,8 @@ public: class PFS_host_allocator { public: - int alloc_array(PFS_host_array *array, size_t size); - void free_array(PFS_host_array *array, size_t size); + int alloc_array(PFS_host_array *array); + void free_array(PFS_host_array *array); }; #ifdef USE_SCALABLE @@ -1540,8 +1572,8 @@ public: class PFS_thread_allocator { public: - int alloc_array(PFS_thread_array *array, size_t size); - void free_array(PFS_thread_array *array, size_t size); + int alloc_array(PFS_thread_array *array); + void free_array(PFS_thread_array *array); }; #ifdef USE_SCALABLE @@ -1571,8 +1603,8 @@ public: class PFS_user_allocator { public: - int alloc_array(PFS_user_array *array, size_t size); - void free_array(PFS_user_array *array, size_t size); + int alloc_array(PFS_user_array *array); + void free_array(PFS_user_array *array); }; #ifdef USE_SCALABLE |