mariadb/mysys
Monty e600f9aebb MDEV-35750 Change MEM_ROOT allocation sizes to reduse calls to malloc() and avoid memory fragmentation
This commit updates default memory allocations size used with MEM_ROOT
objects to minimize the number of calls to malloc().

Changes:
- Updated MEM_ROOT block sizes in sql_const.h
- Updated MALLOC_OVERHEAD to also take into account the extra memory
  allocated by my_malloc()
- Updated init_alloc_root() to only take MALLOC_OVERHEAD into account as
  buffer size, not MALLOC_OVERHEAD + sizeof(USED_MEM).
- Reset mem_root->first_block_usage if and only if first block was used.
- Increase MEM_ROOT buffers sized used by my_load_defaults, plugin_init,
  Create_tmp_table, allocate_table_share, TABLE and TABLE_SHARE.
  This decreases number of malloc calls during queries.
- Use a small buffer for THD->main_mem_root in THD::THD. This avoids
  multiple malloc() call for new connections.

I tried the above changes on a complex select query with 12 tables.
The following shows the number of extra allocations that where used
to increase the size of the MEM_ROOT buffers.

Original code:
- Connection to MariaDB:   9 allocations
- First query run:       146 allocations
- Second query run:       24 allocations

Max memory allocated for thd when using with heap table:  61,262,408
Max memory allocated for thd when using Aria tmp table:      419,464

After changes:
Connection to MariaDB:     0 allocations
- First run:              25 allocations
- Second run:              7 allocations

Max memory allocated for thd when using with heap table:  61,347,424
Max memory allocated for thd when using Aria table:          529,168

The new code uses slightly more memory, but avoids memory fragmentation
and is slightly faster thanks to much fewer calls to malloc().

Reviewed-by: Sergei Golubchik <serg@mariadb.org>
2025-01-05 16:40:11 +02:00
..
crc32 MDEV-34825 FreeBSD fails to build under clang natively 2024-09-05 12:14:06 +10:00
array.c Merge branch '10.5' into '10.6' 2024-12-13 01:45:35 +01:00
base64.c
ChangeLog
charset-def.c
charset.c Merge 10.5 into 10.6 2024-11-29 12:37:46 +02:00
CMakeLists.txt Merge branch '10.5' into 10.6 2024-10-29 14:20:03 +01:00
crc32ieee.cc MDEV-33817 preparation: Restructuring and unit tests 2024-05-03 13:06:13 +03:00
errors.c
file_logger.c
get_password.c
guess_malloc_library.c
hash.c MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
lf_alloc-pin.c Fix a stack overflow in pinbox allocator 2024-07-05 13:26:37 +10:00
lf_dynarray.c
lf_hash.cc
list.c
ma_dyncol.c Merge 10.5 into 10.6 2024-05-30 14:27:07 +03:00
mf_arr_appstr.c
mf_cache.c
mf_dirname.c
mf_fn_ext.c
mf_format.c
mf_getdate.c
mf_iocache.c
mf_iocache2.c
mf_keycache.c Merge 10.5 into 10.6 2024-11-29 12:37:46 +02:00
mf_keycaches.c
mf_loadpath.c
mf_pack.c
mf_path.c
mf_qsort.c MDEV-34348: Consolidate cmp function declarations 2024-11-23 08:14:22 -07:00
mf_qsort2.c
mf_radix.c
mf_same.c
mf_sort.c
mf_soundex.c
mf_tempdir.c
mf_tempfile.c
mf_unixpath.c
mf_wcomp.c
mulalloc.c
my_access.c
my_addr_resolve.c
my_alarm.c
my_alloc.c MDEV-35750 Change MEM_ROOT allocation sizes to reduse calls to malloc() and avoid memory fragmentation 2025-01-05 16:40:11 +02:00
my_atomic_writes.c
my_basename.c
my_bit.c
my_bitmap.c
my_chmod.c
my_chsize.c
my_compare.c
my_compress.c
my_conio.c
my_copy.c
my_cpu.c
my_create.c Change my_umask{,_dir} to mode_t and remove os_innodb_umask 2024-12-11 17:21:01 +11:00
my_default.c MDEV-35750 Change MEM_ROOT allocation sizes to reduse calls to malloc() and avoid memory fragmentation 2025-01-05 16:40:11 +02:00
my_delete.c
my_div.c
my_dlerror.c
my_error.c
my_file.c
my_fopen.c
my_fstream.c
my_getexe.c MDEV-34340 mariadb-backup immediately dumps core on NetBSD 2024-10-16 11:46:19 +11:00
my_gethwaddr.c
my_getncpus.c
my_getopt.c MDEV-34491 Setting log_slow_admin="" at startup should be converted to log_slow_admin=ALL 2024-07-02 11:26:13 +03:00
my_getpagesize.c
my_getsystime.c
my_getwd.c
my_init.c Change my_umask{,_dir} to mode_t and remove os_innodb_umask 2024-12-11 17:21:01 +11:00
my_largepage.c
my_lib.c MDEV-34348: Consolidate cmp function declarations 2024-11-23 08:14:22 -07:00
my_libwrap.c
my_likely.c MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
my_lock.c
my_lockmem.c
my_malloc.c
my_memmem.c
my_mess.c
my_minidump.cc
my_mkdir.c
my_mmap.c
my_new.cc
my_once.c
my_open.c Merge 10.5 into 10.6 2024-12-11 14:46:43 +02:00
my_port.c
my_pread.c
my_pthread.c
my_quick.c
my_rdtsc.c Refactor GitLab cppcheck and update SAST ignorelists 2024-07-08 10:51:48 +01:00
my_read.c
my_redel.c
my_rename.c
my_rnd.c
my_safehash.c MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
my_safehash.h
my_seek.c
my_setuser.c
my_sleep.c
my_stack.c Fixup bddbef3573 2024-10-31 10:01:01 +01:00
my_static.c Merge 10.5 into 10.6 2024-12-11 14:46:43 +02:00
my_static.h
my_symlink.c Remove HAVE_BROKEN_REALPATH 2024-10-16 11:46:19 +11:00
my_symlink2.c Change my_umask{,_dir} to mode_t and remove os_innodb_umask 2024-12-11 17:21:01 +11:00
my_sync.c
my_thr_init.c MDEV-34077 scripts/mariadb-install-db: Error in my_thread_global_end(): 1 threads didn't exit 2024-05-05 21:37:08 +02:00
my_uuid.c
my_win_popen.cc
my_wincond.c
my_winerr.c
my_winfile.c
my_winthread.c
my_wintoken.c
my_write.c
mysys_priv.h
psi_noop.c
ptr_cmp.c MDEV-34348: Consolidate cmp function declarations 2024-11-23 08:14:22 -07:00
queues.c MDEV-34348: Consolidate cmp function declarations 2024-11-23 08:14:22 -07:00
safemalloc.c
stacktrace.c
string.c
test_charset.c
test_dir.c
test_thr_mutex.c
test_xml.c
testhash.c
thr_alarm.c Merge 10.5 into 10.6 2024-12-11 14:46:43 +02:00
thr_lock.c
thr_mutex.c Merge 10.5 into 10.6 2024-06-10 15:22:15 +03:00
thr_rwlock.c MDEV-34530 dead code in the thr_rwlock.c 2024-07-17 21:25:40 +02:00
thr_timer.c MDEV-35574 remove obsolete pthread_exit calls 2024-12-10 12:12:20 +11:00
tree.c
typelib.c
waiting_threads.c MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
wqueue.c