Skip to content

Commit

Permalink
MDEV-17933 slow server status - dict_sys_get_size()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Jan 23, 2019
1 parent f9cc956 commit 52d1303
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 61 deletions.
38 changes: 11 additions & 27 deletions storage/innobase/dict/dict0dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
4 changes: 1 addition & 3 deletions storage/innobase/srv/srv0srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
38 changes: 11 additions & 27 deletions storage/xtradb/dict/dict0dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
6 changes: 2 additions & 4 deletions storage/xtradb/srv/srv0srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 52d1303

Please sign in to comment.