[Commits] 9f7e77b: MDEV-10296 - Multi-instance table cache

Sergey Vojtovich svoj at mariadb.org
Wed Sep 7 11:48:31 EEST 2016


revision-id: 9f7e77b5414b5b2ef9b5f50f131966821fefb9c7 (mariadb-10.1.8-229-g9f7e77b)
parent(s): 58634f6e50b40b28533a03a1afcb68f139937351
committer: Sergey Vojtovich
timestamp: 2016-09-07 12:47:43 +0400
message:

MDEV-10296 - Multi-instance table cache

- simplified access to per-share free tables list
- explain paddings

---
 sql/table_cache.cc | 29 +++++++++--------------------
 sql/table_cache.h  | 13 ++++++++++++-
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/sql/table_cache.cc b/sql/table_cache.cc
index f1eb006..d635d1b 100644
--- a/sql/table_cache.cc
+++ b/sql/table_cache.cc
@@ -114,14 +114,6 @@ static int fix_thd_pins(THD *thd)
   part of table definition cache.
 */
 
-struct Share_free_tables
-{
-  typedef I_P_List <TABLE, TABLE_share> List;
-  List list;
-  char pad[CPU_LEVEL1_DCACHE_LINESIZE];
-};
-
-
 struct Table_cache_instance
 {
   /**
@@ -135,6 +127,7 @@ struct Table_cache_instance
             I_P_List_null_counter, I_P_List_fast_push_back<TABLE> >
     free_tables;
   ulong records;
+  /** Avoid false sharing between instances */
   char pad[CPU_LEVEL1_DCACHE_LINESIZE];
 
   Table_cache_instance(): records(0)
@@ -155,12 +148,6 @@ struct Table_cache_instance
 static Table_cache_instance *tc;
 
 
-static inline Share_free_tables *SHARE_FREE_TABLES(TDC_element *element)
-{
-  return (Share_free_tables*) (element + 1);
-}
-
-
 static void intern_close_table(TABLE *table)
 {
   delete table->triggers;
@@ -226,7 +213,7 @@ static void tc_remove_all_unused_tables(TDC_element *element,
   for (ulong i= 0; i < tc_instances; i++)
   {
     mysql_mutex_lock(&tc[i].LOCK_table_cache);
-    while ((table= SHARE_FREE_TABLES(element)[i].list.pop_front()))
+    while ((table= element->free_tables[i].list.pop_front()))
     {
       tc[i].records--;
       tc[i].free_tables.remove(table);
@@ -315,7 +302,7 @@ void tc_add_table(THD *thd, TABLE *table)
   mysql_mutex_lock(&tc[i].LOCK_table_cache);
   if (tc[i].records == tc_size && (LRU_table= tc[i].free_tables.pop_front()))
   {
-    SHARE_FREE_TABLES(LRU_table->s->tdc)[i].list.remove(LRU_table);
+    LRU_table->s->tdc->free_tables[i].list.remove(LRU_table);
     /* Needed if MDL deadlock detector chimes in before tc_remove_table() */
     LRU_table->in_use= thd;
   }
@@ -344,7 +331,7 @@ static TABLE *tc_acquire_table(THD *thd, TDC_element *element)
   TABLE *table;
 
   mysql_mutex_lock(&tc[i].LOCK_table_cache);
-  table= SHARE_FREE_TABLES(element)[i].list.pop_front();
+  table= element->free_tables[i].list.pop_front();
   if (table)
   {
     DBUG_ASSERT(!table->in_use);
@@ -403,7 +390,7 @@ void tc_release_table(TABLE *table)
   else
   {
     table->in_use= 0;
-    SHARE_FREE_TABLES(table->s->tdc)[i].list.push_front(table);
+    table->s->tdc->free_tables[i].list.push_front(table);
     tc[i].free_tables.push_back(table);
     mysql_mutex_unlock(&tc[i].LOCK_table_cache);
   }
@@ -416,8 +403,10 @@ static void tdc_assert_clean_share(TDC_element *element)
   DBUG_ASSERT(element->ref_count == 0);
   DBUG_ASSERT(element->m_flush_tickets.is_empty());
   DBUG_ASSERT(element->all_tables.is_empty());
+#ifndef DBUG_OFF
   for (ulong i= 0; i < tc_instances; i++)
-    DBUG_ASSERT(SHARE_FREE_TABLES(element)[i].list.is_empty());
+    DBUG_ASSERT(element->free_tables[i].list.is_empty());
+#endif
   DBUG_ASSERT(element->all_tables_refs == 0);
   DBUG_ASSERT(element->next == 0);
   DBUG_ASSERT(element->prev == 0);
@@ -489,7 +478,7 @@ static void lf_alloc_constructor(uchar *arg)
   element->m_flush_tickets.empty();
   element->all_tables.empty();
   for (ulong i= 0; i < tc_instances; i++)
-    SHARE_FREE_TABLES(element)[i].list.empty();
+    element->free_tables[i].list.empty();
   element->all_tables_refs= 0;
   element->share= 0;
   element->ref_count= 0;
diff --git a/sql/table_cache.h b/sql/table_cache.h
index 4f449cb..979f3c9 100644
--- a/sql/table_cache.h
+++ b/sql/table_cache.h
@@ -18,6 +18,15 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 
+struct Share_free_tables
+{
+  typedef I_P_List <TABLE, TABLE_share> List;
+  List list;
+  /** Avoid false sharing between instances */
+  char pad[CPU_LEVEL1_DCACHE_LINESIZE];
+};
+
+
 struct TDC_element
 {
   uchar m_key[NAME_LEN + 1 + NAME_LEN + 1];
@@ -43,7 +52,9 @@ struct TDC_element
     for this share.
   */
   All_share_tables_list all_tables;
-  char pad[CPU_LEVEL1_DCACHE_LINESIZE]; // free_tables follows this immediately
+  /** Avoid false sharing between TDC_element and free_tables */
+  char pad[CPU_LEVEL1_DCACHE_LINESIZE];
+  Share_free_tables free_tables[0];
 };
 
 


More information about the commits mailing list