Commit 52d13036 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-17933 slow server status - dict_sys_get_size()

dict_sys_get_size(): Replace the time-consuming loop with
a crude estimate that can be computed without holding any mutex.

Even before dict_sys->size was removed in MDEV-13325,
not all memory allocations by the InnoDB data dictionary cache
were being accounted for. One example is foreign key constraints.
Another example is virtual column metadata, starting with 10.2.
parent f9cc9560
......@@ -2,7 +2,7 @@
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2018, MariaDB Corporation.
Copyright (c) 2013, 2019, MariaDB Corporation.
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
......@@ -7250,30 +7250,14 @@ UNIV_INTERN
ulint
dict_sys_get_size()
{
ulint size = 0;
ut_ad(dict_sys);
mutex_enter(&dict_sys->mutex);
for(ulint i = 0; i < hash_get_n_cells(dict_sys->table_hash); i++) {
dict_table_t* table;
for (table = static_cast<dict_table_t*>(HASH_GET_FIRST(dict_sys->table_hash,i));
table != NULL;
table = static_cast<dict_table_t*>(HASH_GET_NEXT(name_hash, table))) {
dict_index_t* index;
size += mem_heap_get_size(table->heap) + strlen(table->name) +1;
for(index = dict_table_get_first_index(table);
index != NULL;
index = dict_table_get_next_index(index)) {
size += mem_heap_get_size(index->heap);
}
}
}
mutex_exit(&dict_sys->mutex);
return (size);
/* No mutex; this is a very crude approximation anyway */
ulint size = UT_LIST_GET_LEN(dict_sys->table_LRU)
+ UT_LIST_GET_LEN(dict_sys->table_non_LRU);
size *= sizeof(dict_table_t)
+ sizeof(dict_index_t) * 2
+ (sizeof(dict_col_t) + sizeof(dict_field_t)) * 10
+ sizeof(dict_field_t) * 5 /* total number of key fields */
+ 200; /* arbitrary, covering names and overhead */
return size;
}
......@@ -3,7 +3,7 @@
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, 2009 Google Inc.
Copyright (c) 2009, Percona Inc.
Copyright (c) 2013, 2017, MariaDB Corporation.
Copyright (c) 2013, 2019, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
......@@ -1341,8 +1341,6 @@ srv_printf_innodb_monitor(
"; in additional pool allocated " ULINTPF "\n",
ut_total_allocated_memory,
mem_pool_get_reserved(mem_comm_pool));
fprintf(file, "Dictionary memory allocated " ULINTPF "\n",
dict_sys_get_size());
buf_print_io(file);
......
......@@ -2,7 +2,7 @@
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2018, MariaDB Corporation.
Copyright (c) 2013, 2019, MariaDB Corporation.
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
......@@ -7252,30 +7252,14 @@ UNIV_INTERN
ulint
dict_sys_get_size()
{
ulint size = 0;
ut_ad(dict_sys);
mutex_enter(&dict_sys->mutex);
for(ulint i = 0; i < hash_get_n_cells(dict_sys->table_hash); i++) {
dict_table_t* table;
for (table = static_cast<dict_table_t*>(HASH_GET_FIRST(dict_sys->table_hash,i));
table != NULL;
table = static_cast<dict_table_t*>(HASH_GET_NEXT(name_hash, table))) {
dict_index_t* index;
size += mem_heap_get_size(table->heap) + strlen(table->name) +1;
for(index = dict_table_get_first_index(table);
index != NULL;
index = dict_table_get_next_index(index)) {
size += mem_heap_get_size(index->heap);
}
}
}
mutex_exit(&dict_sys->mutex);
return (size);
/* No mutex; this is a very crude approximation anyway */
ulint size = UT_LIST_GET_LEN(dict_sys->table_LRU)
+ UT_LIST_GET_LEN(dict_sys->table_non_LRU);
size *= sizeof(dict_table_t)
+ sizeof(dict_index_t) * 2
+ (sizeof(dict_col_t) + sizeof(dict_field_t)) * 10
+ sizeof(dict_field_t) * 5 /* total number of key fields */
+ 200; /* arbitrary, covering names and overhead */
return size;
}
......@@ -3,7 +3,7 @@
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, 2009 Google Inc.
Copyright (c) 2009, Percona Inc.
Copyright (c) 2013, 2017, MariaDB Corporation.
Copyright (c) 2013, 2019, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
......@@ -1642,9 +1642,7 @@ srv_printf_innodb_monitor(
? (recv_sys->addr_hash->n_cells * sizeof(hash_cell_t)) : 0),
recv_sys_subtotal);
fprintf(file, "Dictionary memory allocated " ULINTPF "\n",
dict_sys ? dict_sys_get_size() : 0);
fprintf(file, "Dictionary memory allocated " ULINTPF "\n", dict_size);
buf_print_io(file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment