Debian Codegraph @

storage/innobase/ut/ut0new.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2014, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file ut/ut0new.cc
29 Instrumented memory allocator.
30
31 Created May 26, 2014 Vasil Dimov
32 *******************************************************/
33
34 #include "univ.i"
35
36 #include "my_compiler.h"
37 #include "ut0new.h"
38
39 /** System-default huge (large) page setting. */
40 const size_t large_page_default_size = ut::detail::large_page_size();
41
42 /** Maximum number of retries to allocate memory. */
43 const size_t alloc_max_retries = 60;
44
45 /** Keys for registering allocations with performance schema.
46 Keep this list alphabetically sorted. */
47 PSI_memory_key mem_key_ahi;
48 PSI_memory_key mem_key_archive;
49 PSI_memory_key mem_key_buf_buf_pool;
50 PSI_memory_key mem_key_buf_stat_per_index_t;
51 /** Memory key for clone */
52 PSI_memory_key mem_key_clone;
53 PSI_memory_key mem_key_dict_stats_bg_recalc_pool_t;
54 PSI_memory_key mem_key_dict_stats_index_map_t;
55 PSI_memory_key mem_key_dict_stats_n_diff_on_level;
56 PSI_memory_key mem_key_fil_space_t;
57 PSI_memory_key mem_key_lock_sys;
58 PSI_memory_key mem_key_other;
59 PSI_memory_key mem_key_partitioning;
60 PSI_memory_key mem_key_row_log_buf;
61 PSI_memory_key mem_key_ddl;
62 PSI_memory_key mem_key_std;
63 PSI_memory_key mem_key_trx_sys_t_rw_trx_ids;
64 PSI_memory_key mem_key_undo_spaces;
65 PSI_memory_key mem_key_ut_lock_free_hash_t;
66 /* Please obey alphabetical order in the definitions above. */
67
68 #ifdef UNIV_PFS_MEMORY
69
70 /** Auxiliary array of performance schema 'PSI_memory_info'.
71 Each allocation appears in
72 performance_schema.memory_summary_global_by_event_name (and alike) in the form
73 of e.g. 'memory/innodb/NAME' where the last component NAME is picked from
74 the list below:
75 1. If key is specified, then the respective name is used
76 2. Without a specified key, allocations from inside std::* containers use
77 mem_key_std
78 3. Without a specified key, allocations from outside std::* pick up the key
79 based on the file name, and if file name is not found in the predefined list
80 (in ut_new_boot()) then mem_key_other is used.
81 Keep this list alphabetically sorted. */
82 // TODO: check if keys other than buf_buf_pool should be also global
83 // (should use PSI_FLAG_ONLY_GLOBAL_STAT)
84 static PSI_memory_info pfs_info[] = {
85 {&mem_key_ahi, "adaptive hash index", 0, 0, PSI_DOCUMENT_ME},
86 {&mem_key_archive, "log and page archiver", 0, 0, PSI_DOCUMENT_ME},
87 {&mem_key_buf_buf_pool, "buf_buf_pool", PSI_FLAG_ONLY_GLOBAL_STAT, 0,
88 PSI_DOCUMENT_ME},
89 {&mem_key_buf_stat_per_index_t, "buf_stat_per_index_t", 0, 0,
90 PSI_DOCUMENT_ME},
91 {&mem_key_clone, "clone", 0, 0, PSI_DOCUMENT_ME},
92 {&mem_key_dict_stats_bg_recalc_pool_t, "dict_stats_bg_recalc_pool_t", 0, 0,
93 PSI_DOCUMENT_ME},
94 {&mem_key_dict_stats_index_map_t, "dict_stats_index_map_t", 0, 0,
95 PSI_DOCUMENT_ME},
96 {&mem_key_dict_stats_n_diff_on_level, "dict_stats_n_diff_on_level", 0, 0,
97 PSI_DOCUMENT_ME},
98 {&mem_key_fil_space_t, "fil_space_t", 0, 0, PSI_DOCUMENT_ME},
99 {&mem_key_lock_sys, "lock_sys", 0, 0, PSI_DOCUMENT_ME},
100 {&mem_key_other, "other", 0, 0, PSI_DOCUMENT_ME},
101 {&mem_key_partitioning, "partitioning", 0, 0, PSI_DOCUMENT_ME},
102 {&mem_key_row_log_buf, "row_log_buf", 0, 0, PSI_DOCUMENT_ME},
103 {&mem_key_ddl, "ddl", 0, 0, PSI_DOCUMENT_ME},
104 {&mem_key_std, "std", 0, 0, PSI_DOCUMENT_ME},
105 {&mem_key_trx_sys_t_rw_trx_ids, "trx_sys_t::rw_trx_ids", 0, 0,
106 PSI_DOCUMENT_ME},
107 {&mem_key_undo_spaces, "undo::Tablespaces", 0, 0, PSI_DOCUMENT_ME},
108 {&mem_key_ut_lock_free_hash_t, "ut_lock_free_hash_t", 0, 0,
109 PSI_DOCUMENT_ME},
110 /* Please obey alphabetical order in the definitions above. */
111 };
112
113 PSI_memory_key auto_event_keys[n_auto];
114 PSI_memory_info pfs_info_auto[n_auto];
115
116 #endif /* UNIV_PFS_MEMORY */
117
118 /** Setup the internal objects needed for ut::new_withkey() to operate.
119 This must be called before the first call to ut::new_withkey(). */
120 void ut_new_boot() {
121 #ifdef UNIV_PFS_MEMORY
122 for (size_t i = 0; i < n_auto; i++) {
123 /* e.g. "btr0btr" */
124 pfs_info_auto[i].m_name = auto_event_names[i];
125
126 /* a pointer to the pfs key */
127 pfs_info_auto[i].m_key = &auto_event_keys[i];
128
129 pfs_info_auto[i].m_flags = 0;
130 pfs_info_auto[i].m_volatility = PSI_VOLATILITY_UNKNOWN;
131 pfs_info_auto[i].m_documentation = PSI_DOCUMENT_ME;
132 }
133
134 PSI_MEMORY_CALL(register_memory)("innodb", pfs_info, UT_ARR_SIZE(pfs_info));
135 PSI_MEMORY_CALL(register_memory)("innodb", pfs_info_auto, n_auto);
136 #endif /* UNIV_PFS_MEMORY */
137 }
138
139 void ut_new_boot_safe() {
140 static bool ut_new_boot_called = false;
141
142 if (!ut_new_boot_called) {
143 ut_new_boot();
144 ut_new_boot_called = true;
145 }
146 }