SlideShare a Scribd company logo
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Feed me more: MySQL Memory analysed
FOSDEM MySQL Devroom 2013
Raghavendra Prabhu
raghavendra.prabhu@percona.com
Percona
3rd Feb, 2013
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Outline
Introduction
MySQL - Buffers and storage engines
OS/Tools/Instrumentation
Solutions
Cases / Examples
Future
Conclusion
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Overview
During capacity planning, a frequent question which pops up is “How
much memory should I allocate for MySQL and for the system in
general?”.
Memory is quite underestimated much like everything else but more so
than others.
Umpteen thumb rules about this on the Internet, often overruns the
memory and/or frequently OOMs.
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Bufferbloat
Buffers
read_buffer, read_rnd_buffer, join_buffer_size, sort_buffer_size
cache->length=length+blobs*sizeof(char*);
cache->blobs=blobs;
*blob_ptr=0;
size=max(thd->variables.join_buff_size, cache->length);
MySQL variables - max_connections, table_cache and
open_files_limit
wanted_files=10+max_connections+table_cache_size*2;
max_open_files=max(max(wanted_files, max_connections*5),open_files_limit)
tmp_table_size and max_heap_size on tmpfs
tmpdir and tmpfs
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
InnoDB
Buffer pool
Bounded
Not initialized at startup unless done so (Twitter, XtraDB)
O_DIRECT, ALL_O_DIRECT
Adaptive Hash Index
Role, Bounded, LRU/Reclaim and disable/enable
Multiple partitions - implications on locking
Hash tables & Internals: mem_heap_create_in_btr_search,
MEM_HEAP_BTR_SEARCH, MEM_HEAP_BUFFER,
MEM_HEAP_DYNAMIC
Data dictionary
Unbounded
XtraDB variable - innodb_dict_size_limit
Other ways
Change buffer
XtraDB variable to limit this / Why to limit
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
OS
Sysctls
vm.swappiness, vm.vfs_cache_pressure, vm.drop_caches
vm.overcommit_memory, vm.zone_reclaim_mode
NUMA
NUMA policies: DEFAULT, BIND, INTERLEAVE, PREFERRED
Numastat: numa_hit, numa_miss, numa_foreign, interleave_hit,
local_node, other_node; lp:1083488
numad and AutoNUMA
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Instrumentation/Tools
Instrumentation
getrusage - RUSAGE_THREAD, RUSAGE_SELF,
RUSAGE_CHILDREN
Malloc
tcmalloc - also supports profiling
jemalloc and e/glibc malloc
additional_mem_size and malloc, use_sys_malloc
Perf
perf-top, perf-list
perf-record, perf-report
perf-timechart
Tools
smem, atop, page-types - PSS, stall/pag, memory-map
Valgrind - massif, memcheck, callgrind - UNIV_DEBUG_VALGRIND
LLVM/Clang - ASAN, MSAN - CTI v/s DBI
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Code
Hinting
Not with O_DIRECT handles, Users: Galera, Xtrabackup, MySQL
Madvise and Fadvise
MADV_DONTDUMP
MADV_WILLNEED, MADV_DONTNEED, MADV_SEQUENTIAL
Caveats
Fincore
sudo linux-fincore /data/mysql/galera.cache
filename
––––
/data/mysql/galera.cache
–-
total cached size: 15,944,663,040
Don’t mix O_DIRECT and others
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
OOM and Cgroups
OOM adjustments
vm.panic_on_oom, oom_kill_allocating_task, oom_score_adj
Memory Cgroups
Multiple instances and/or shared
Per instance settings like swappiness
Overhead?
OOM: Proactive and Reactive measures
Proactive: Turn down the load
Reactive: Kill! or move
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Virtualization
Memory ballooning
You balloon the memory whenever required
Qemu monitor: info balloon
balloon virtio
KSM with KVM/Xen
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Misc
Hugepages huge pages
Supported in mysql
Boot-time allocation better
Fragmentation and performance
Transparent Huge pages
No need for setup
Possible bugs? - compaction_alloc and compact_zone
Disable the defrag
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Cases
NUMA and swap
mem_cgroup_del_lru_list and watermark
19.08% [kernel] [k] mem_cgroup_del_lru_list
14.52% [kernel] [k] intel_idle
7.98% [kernel] [k] __isolate_lru_page
6.14% [kernel] [k] shrink_inactive_list
3.83% [kernel] [k] mem_cgroup_add_lru_list
3.60% mysqld [.] 0x4c584e
3.14% [kernel] [k] page_waitqueue
3.09% [kernel] [k] isolate_pages_global
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Examples
smem stack
smem -m -t -k -P aurora
Map PIDs AVGPSS PSS
[stack:34760] 1 1.8M 1.8M
[stack:34668] 1 2.0M 2.0M
[stack:34694] 1 2.2M 2.2M
[heap] 1 6.4M 6.4M
[stack:34746] 1 9.2M 9.2M
[stack:35015] 1 19.5M 19.5M
/usr/lib/aurora/libxul.so 1 24.4M 24.4M
<anonymous> 2 337.8M 675.7M
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Examples (contd.)
Valgrind
./mysql-test-run.pl –valgrind
–valgrind-option="–suppressions=$PWD/valgrind.supp"
–valgrind-option=’–show-reachable=yes’
–valgrind-option=’–gen-suppressions=all’
–vardir=$HOME/mysql t/fake.test
=13145== 16,384 bytes in 1 blocks are still reachable in loss record 738 o
=13145== at 0x4C2C1DE: realloc (in /usr/lib/valgrind/vgpreload_memcheck-a
=13145== by 0x5D78B60: CRYPTO_realloc (in /usr/lib/libcrypto.so.1.0.0)
=13145== by 0x5E20E31: lh_insert (in /usr/lib/libcrypto.so.1.0.0)
=13145== by 0x5E23E0D: int_err_set_item (in /usr/lib/libcrypto.so.1.0.0)
=13145== by 0x5E24458: ERR_load_strings (in /usr/lib/libcrypto.so.1.0.0)
=13145== by 0x5AF99BD: ERR_load_SSL_strings (in /usr/lib/libssl.so.1.0.0)
=13145== by 0xA3C315: new_VioSSLFd (viosslfactories.c:159)
=13145== by 0xA3C91E: new_VioSSLAcceptorFd (viosslfactories.c:288)
=13145== by 0x51D509: mysqld_main(int, char**) (mysqld.cc:3735)
=13145== by 0x513974: main (main.cc:25)
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Examples (contd.)
Perf-report
# 7.15% mysqld mysqld [.] 0x11b0fe
- 0x959389
- 91.87% yaSSL::SSL::makeMasterSecret()
- 79.56% yaSSL::CertManager::sendVerify() const
page_cur_parse_insert_rec.clone.0
row_search_for_mysql
row_search_for_mysql
- row_search_for_mysql
- 61.21% row_vers_impl_x_locked_off_kernel
Create_func_from_unixtime::create_native(THD*, st_mysq
Create_func_is_used_lock::create(THD*, Item*)
Item_func_set_user_var::fix_length_and_dec()
Item_func::fix_fields(THD*, Item**)
handler::delete_table(char const*)
Item_copy_string::val_int()
Item_field::val_bool_result()
Item_cache_datetime::val_str(String*)
Item_type_holder::make_field_by_type(TABLE*)
Item_param::set_param_type_and_swap_value(Item_param*)
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
MySQL 5.6
Multi thread purge
Data dictionary LRU
Malloc
Grouping allocations
Stack instead of heap
Removing allocations
Page size - XtraDB 5.5 and MySQL 5.6
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Bugs/Features
Bugs reported / in-review
Per thread variables: http://dev.mysql.com/worklog/task/?id=681
Fadvise relay logs:
https://bugs.launchpad.net/percona-server/+bug/1073170
LRU and AHI:
https://bugs.launchpad.net/percona-server/+bug/1083536
Data Dictionary and Buffer pool:
https://bugs.launchpad.net/percona-server/+bug/1083514
MADV_DONTDUMP:
https://bugs.launchpad.net/percona-server/+bug/1092645
SSL leak: https://bugs.launchpad.net/percona-server/+bug/1049076
Leak on a filtered slave:
https://bugs.launchpad.net/percona-server/+bug/1042946
Features planned/interest
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Appendix I
Insert call-chain
btr_search_build_page_hash_index
btr_search_update_hash_on_insert
btr_search_update_hash_ref
ha_insert_for_fold
mem_heap_alloc(hash_get_heap(table, fold), sizeof(ha_node_t))
mem_heap_add_block
mem_heap_create_block
buf_block_alloc
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Appendix II
Hash table
struct hash_table_struct {
ulint n_cells;
hash_cell_t* array;
ulint n_mutexes;
mutex_t* mutexes;
mem_heap_t** heaps;
mem_heap_t* heap;
};
Raghavendra Prabhu Percona
MySQL Memory analysed
Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion
Appendix III
Heap structure
struct mem_block_info_struct {
ulint magic_n;
char file_name[8];
ulint line;
UT_LIST_BASE_NODE_T(mem_block_t) base;
UT_LIST_NODE_T(mem_block_t) list;
ulint len;
ulint total_size;
ulint type;
ulint free;
ulint start;
void* free_block;
void* buf_block;
};
Raghavendra Prabhu Percona
MySQL Memory analysed

More Related Content

PDF
Feed me more: MySQL Memory analysed
PDF
[2A2]Vectorized_processing_in_a_Nutshell
PDF
MySQL Replication: Demo Réplica en Español
PDF
MySQL Enterprise Backup: PITR Partial Online Recovery
PPTX
Dell poweredge t610+3+3+3tb+prachoom school server
PDF
Meb Backup & Recovery Performance
PPTX
Trouble shooting apachecloudstack
PPT
0628阙宏宇
Feed me more: MySQL Memory analysed
[2A2]Vectorized_processing_in_a_Nutshell
MySQL Replication: Demo Réplica en Español
MySQL Enterprise Backup: PITR Partial Online Recovery
Dell poweredge t610+3+3+3tb+prachoom school server
Meb Backup & Recovery Performance
Trouble shooting apachecloudstack
0628阙宏宇

What's hot (8)

PDF
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
PDF
Anirudh Koul. 30 Golden Rules of Deep Learning Performance
PDF
CUDA by Example : Streams : Notes
PDF
Entenda de onde vem toda a potência do Intel® Xeon Phi™
PDF
UKOUG 2011: Practical MySQL Tuning
PPTX
Advanced SQL Memory Management (GeekReady 2012)
PDF
Distributed Multi-GPU Computing with Dask, CuPy and RAPIDS
PDF
Basic MySQL Troubleshooting for Oracle DBAs
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
Anirudh Koul. 30 Golden Rules of Deep Learning Performance
CUDA by Example : Streams : Notes
Entenda de onde vem toda a potência do Intel® Xeon Phi™
UKOUG 2011: Practical MySQL Tuning
Advanced SQL Memory Management (GeekReady 2012)
Distributed Multi-GPU Computing with Dask, CuPy and RAPIDS
Basic MySQL Troubleshooting for Oracle DBAs
Ad

Viewers also liked (8)

PPTX
J & J Final Presentation 9-49pm.pptx
PPTX
Johnson and Johnson Case Competition RU Team J
PPTX
Johnson & Johnson Marketing efforts analysis
PPTX
Factors affecting Johnson and johnson
PDF
Johnson & Johnson: Elevating employee advocacy: A case study, presented by De...
PDF
Timberland: Social media case study, presented by Frank Hwang
PPT
Johnson & Johnson
PPTX
Johnson & johnson Business Strategy
J & J Final Presentation 9-49pm.pptx
Johnson and Johnson Case Competition RU Team J
Johnson & Johnson Marketing efforts analysis
Factors affecting Johnson and johnson
Johnson & Johnson: Elevating employee advocacy: A case study, presented by De...
Timberland: Social media case study, presented by Frank Hwang
Johnson & Johnson
Johnson & johnson Business Strategy
Ad

Similar to MySQL 内存分析 (20)

PDF
Loadays MySQL
PDF
iloug2015.Mysql.for.oracle.dba.V2
PDF
InnoDB architecture and performance optimization (Пётр Зайцев)
PDF
Innodb 和 XtraDB 结构和性能优化
PDF
Congratsyourthedbatoo
PDF
MySQL Performance Tuning London Meetup June 2017
PPTX
MySQL Architecture and Engine
PDF
mysql architecture.pdf
PDF
MySQL Performance Metrics that Matter
PDF
Linux performance tuning & stabilization tips (mysqlconf2010)
PDF
2008 MySQL Conference Recap
PPTX
MySQL database
KEY
DPC Tutorial
PDF
InnoDB Architecture and Performance Optimization, Peter Zaitsev
PDF
Storage Methods for Nonstandard Data Patterns
PDF
Inno Db Performance And Usability Patches
ODP
Mysql For Developers
ODP
The care and feeding of a MySQL database
PPT
Fudcon talk.ppt
PPTX
Percona Live UK 2014 Part III
Loadays MySQL
iloug2015.Mysql.for.oracle.dba.V2
InnoDB architecture and performance optimization (Пётр Зайцев)
Innodb 和 XtraDB 结构和性能优化
Congratsyourthedbatoo
MySQL Performance Tuning London Meetup June 2017
MySQL Architecture and Engine
mysql architecture.pdf
MySQL Performance Metrics that Matter
Linux performance tuning & stabilization tips (mysqlconf2010)
2008 MySQL Conference Recap
MySQL database
DPC Tutorial
InnoDB Architecture and Performance Optimization, Peter Zaitsev
Storage Methods for Nonstandard Data Patterns
Inno Db Performance And Usability Patches
Mysql For Developers
The care and feeding of a MySQL database
Fudcon talk.ppt
Percona Live UK 2014 Part III

More from YUCHENG HU (20)

PDF
Confluencewiki 使用空间
PDF
PDF
Presta shop 1.6 如何安装简体中文语言文件
PDF
Logback 介绍
PDF
Presta shop 1.6 详细安装指南
PDF
Presta shop 1.6 的安装环境
PDF
Presta shop 1.6 如何安装简体中文语言文件
PDF
Presta shop 1.6 图文安装教程
PDF
V tiger 5.4.0 图文安装教程
PDF
Confluence 回顾(retrospectives) 蓝图 cwikiossez
PDF
Confluence 会议记录(meeting notes)蓝图 cwikiossez
PDF
VTIGER - 销售机会 - CWIKIOSSEZ
PDF
Confluence 使用一个模板新建一个页面 cwikiossez
PDF
Confluence 使用模板
PDF
Cwikiossez confluence 订阅页面更新邮件通知
PDF
Cwikiossez confluence 关注页面 博客页面和空间
PDF
My sql università di enna a.a. 2005-06
PDF
My sql would you like transactions
PDF
MySQL 指南
PDF
MySQL 简要介绍
Confluencewiki 使用空间
Presta shop 1.6 如何安装简体中文语言文件
Logback 介绍
Presta shop 1.6 详细安装指南
Presta shop 1.6 的安装环境
Presta shop 1.6 如何安装简体中文语言文件
Presta shop 1.6 图文安装教程
V tiger 5.4.0 图文安装教程
Confluence 回顾(retrospectives) 蓝图 cwikiossez
Confluence 会议记录(meeting notes)蓝图 cwikiossez
VTIGER - 销售机会 - CWIKIOSSEZ
Confluence 使用一个模板新建一个页面 cwikiossez
Confluence 使用模板
Cwikiossez confluence 订阅页面更新邮件通知
Cwikiossez confluence 关注页面 博客页面和空间
My sql università di enna a.a. 2005-06
My sql would you like transactions
MySQL 指南
MySQL 简要介绍

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Machine Learning_overview_presentation.pptx
PPTX
1. Introduction to Computer Programming.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Empathic Computing: Creating Shared Understanding
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine Learning_overview_presentation.pptx
1. Introduction to Computer Programming.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Empathic Computing: Creating Shared Understanding
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
NewMind AI Weekly Chronicles - August'25-Week II
Accuracy of neural networks in brain wave diagnosis of schizophrenia
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Network Security Unit 5.pdf for BCA BBA.

MySQL 内存分析

  • 1. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Feed me more: MySQL Memory analysed FOSDEM MySQL Devroom 2013 Raghavendra Prabhu raghavendra.prabhu@percona.com Percona 3rd Feb, 2013 Raghavendra Prabhu Percona MySQL Memory analysed
  • 2. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Outline Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Raghavendra Prabhu Percona MySQL Memory analysed
  • 3. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Overview During capacity planning, a frequent question which pops up is “How much memory should I allocate for MySQL and for the system in general?”. Memory is quite underestimated much like everything else but more so than others. Umpteen thumb rules about this on the Internet, often overruns the memory and/or frequently OOMs. Raghavendra Prabhu Percona MySQL Memory analysed
  • 4. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Bufferbloat Buffers read_buffer, read_rnd_buffer, join_buffer_size, sort_buffer_size cache->length=length+blobs*sizeof(char*); cache->blobs=blobs; *blob_ptr=0; size=max(thd->variables.join_buff_size, cache->length); MySQL variables - max_connections, table_cache and open_files_limit wanted_files=10+max_connections+table_cache_size*2; max_open_files=max(max(wanted_files, max_connections*5),open_files_limit) tmp_table_size and max_heap_size on tmpfs tmpdir and tmpfs Raghavendra Prabhu Percona MySQL Memory analysed
  • 5. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion InnoDB Buffer pool Bounded Not initialized at startup unless done so (Twitter, XtraDB) O_DIRECT, ALL_O_DIRECT Adaptive Hash Index Role, Bounded, LRU/Reclaim and disable/enable Multiple partitions - implications on locking Hash tables & Internals: mem_heap_create_in_btr_search, MEM_HEAP_BTR_SEARCH, MEM_HEAP_BUFFER, MEM_HEAP_DYNAMIC Data dictionary Unbounded XtraDB variable - innodb_dict_size_limit Other ways Change buffer XtraDB variable to limit this / Why to limit Raghavendra Prabhu Percona MySQL Memory analysed
  • 6. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion OS Sysctls vm.swappiness, vm.vfs_cache_pressure, vm.drop_caches vm.overcommit_memory, vm.zone_reclaim_mode NUMA NUMA policies: DEFAULT, BIND, INTERLEAVE, PREFERRED Numastat: numa_hit, numa_miss, numa_foreign, interleave_hit, local_node, other_node; lp:1083488 numad and AutoNUMA Raghavendra Prabhu Percona MySQL Memory analysed
  • 7. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Instrumentation/Tools Instrumentation getrusage - RUSAGE_THREAD, RUSAGE_SELF, RUSAGE_CHILDREN Malloc tcmalloc - also supports profiling jemalloc and e/glibc malloc additional_mem_size and malloc, use_sys_malloc Perf perf-top, perf-list perf-record, perf-report perf-timechart Tools smem, atop, page-types - PSS, stall/pag, memory-map Valgrind - massif, memcheck, callgrind - UNIV_DEBUG_VALGRIND LLVM/Clang - ASAN, MSAN - CTI v/s DBI Raghavendra Prabhu Percona MySQL Memory analysed
  • 8. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Code Hinting Not with O_DIRECT handles, Users: Galera, Xtrabackup, MySQL Madvise and Fadvise MADV_DONTDUMP MADV_WILLNEED, MADV_DONTNEED, MADV_SEQUENTIAL Caveats Fincore sudo linux-fincore /data/mysql/galera.cache filename –––– /data/mysql/galera.cache –- total cached size: 15,944,663,040 Don’t mix O_DIRECT and others Raghavendra Prabhu Percona MySQL Memory analysed
  • 9. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion OOM and Cgroups OOM adjustments vm.panic_on_oom, oom_kill_allocating_task, oom_score_adj Memory Cgroups Multiple instances and/or shared Per instance settings like swappiness Overhead? OOM: Proactive and Reactive measures Proactive: Turn down the load Reactive: Kill! or move Raghavendra Prabhu Percona MySQL Memory analysed
  • 10. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Virtualization Memory ballooning You balloon the memory whenever required Qemu monitor: info balloon balloon virtio KSM with KVM/Xen Raghavendra Prabhu Percona MySQL Memory analysed
  • 11. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Misc Hugepages huge pages Supported in mysql Boot-time allocation better Fragmentation and performance Transparent Huge pages No need for setup Possible bugs? - compaction_alloc and compact_zone Disable the defrag Raghavendra Prabhu Percona MySQL Memory analysed
  • 12. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Cases NUMA and swap mem_cgroup_del_lru_list and watermark 19.08% [kernel] [k] mem_cgroup_del_lru_list 14.52% [kernel] [k] intel_idle 7.98% [kernel] [k] __isolate_lru_page 6.14% [kernel] [k] shrink_inactive_list 3.83% [kernel] [k] mem_cgroup_add_lru_list 3.60% mysqld [.] 0x4c584e 3.14% [kernel] [k] page_waitqueue 3.09% [kernel] [k] isolate_pages_global Raghavendra Prabhu Percona MySQL Memory analysed
  • 13. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Examples smem stack smem -m -t -k -P aurora Map PIDs AVGPSS PSS [stack:34760] 1 1.8M 1.8M [stack:34668] 1 2.0M 2.0M [stack:34694] 1 2.2M 2.2M [heap] 1 6.4M 6.4M [stack:34746] 1 9.2M 9.2M [stack:35015] 1 19.5M 19.5M /usr/lib/aurora/libxul.so 1 24.4M 24.4M <anonymous> 2 337.8M 675.7M Raghavendra Prabhu Percona MySQL Memory analysed
  • 14. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Examples (contd.) Valgrind ./mysql-test-run.pl –valgrind –valgrind-option="–suppressions=$PWD/valgrind.supp" –valgrind-option=’–show-reachable=yes’ –valgrind-option=’–gen-suppressions=all’ –vardir=$HOME/mysql t/fake.test =13145== 16,384 bytes in 1 blocks are still reachable in loss record 738 o =13145== at 0x4C2C1DE: realloc (in /usr/lib/valgrind/vgpreload_memcheck-a =13145== by 0x5D78B60: CRYPTO_realloc (in /usr/lib/libcrypto.so.1.0.0) =13145== by 0x5E20E31: lh_insert (in /usr/lib/libcrypto.so.1.0.0) =13145== by 0x5E23E0D: int_err_set_item (in /usr/lib/libcrypto.so.1.0.0) =13145== by 0x5E24458: ERR_load_strings (in /usr/lib/libcrypto.so.1.0.0) =13145== by 0x5AF99BD: ERR_load_SSL_strings (in /usr/lib/libssl.so.1.0.0) =13145== by 0xA3C315: new_VioSSLFd (viosslfactories.c:159) =13145== by 0xA3C91E: new_VioSSLAcceptorFd (viosslfactories.c:288) =13145== by 0x51D509: mysqld_main(int, char**) (mysqld.cc:3735) =13145== by 0x513974: main (main.cc:25) Raghavendra Prabhu Percona MySQL Memory analysed
  • 15. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Examples (contd.) Perf-report # 7.15% mysqld mysqld [.] 0x11b0fe - 0x959389 - 91.87% yaSSL::SSL::makeMasterSecret() - 79.56% yaSSL::CertManager::sendVerify() const page_cur_parse_insert_rec.clone.0 row_search_for_mysql row_search_for_mysql - row_search_for_mysql - 61.21% row_vers_impl_x_locked_off_kernel Create_func_from_unixtime::create_native(THD*, st_mysq Create_func_is_used_lock::create(THD*, Item*) Item_func_set_user_var::fix_length_and_dec() Item_func::fix_fields(THD*, Item**) handler::delete_table(char const*) Item_copy_string::val_int() Item_field::val_bool_result() Item_cache_datetime::val_str(String*) Item_type_holder::make_field_by_type(TABLE*) Item_param::set_param_type_and_swap_value(Item_param*) Raghavendra Prabhu Percona MySQL Memory analysed
  • 16. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion MySQL 5.6 Multi thread purge Data dictionary LRU Malloc Grouping allocations Stack instead of heap Removing allocations Page size - XtraDB 5.5 and MySQL 5.6 Raghavendra Prabhu Percona MySQL Memory analysed
  • 17. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Bugs/Features Bugs reported / in-review Per thread variables: http://dev.mysql.com/worklog/task/?id=681 Fadvise relay logs: https://bugs.launchpad.net/percona-server/+bug/1073170 LRU and AHI: https://bugs.launchpad.net/percona-server/+bug/1083536 Data Dictionary and Buffer pool: https://bugs.launchpad.net/percona-server/+bug/1083514 MADV_DONTDUMP: https://bugs.launchpad.net/percona-server/+bug/1092645 SSL leak: https://bugs.launchpad.net/percona-server/+bug/1049076 Leak on a filtered slave: https://bugs.launchpad.net/percona-server/+bug/1042946 Features planned/interest Raghavendra Prabhu Percona MySQL Memory analysed
  • 18. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Appendix I Insert call-chain btr_search_build_page_hash_index btr_search_update_hash_on_insert btr_search_update_hash_ref ha_insert_for_fold mem_heap_alloc(hash_get_heap(table, fold), sizeof(ha_node_t)) mem_heap_add_block mem_heap_create_block buf_block_alloc Raghavendra Prabhu Percona MySQL Memory analysed
  • 19. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Appendix II Hash table struct hash_table_struct { ulint n_cells; hash_cell_t* array; ulint n_mutexes; mutex_t* mutexes; mem_heap_t** heaps; mem_heap_t* heap; }; Raghavendra Prabhu Percona MySQL Memory analysed
  • 20. Introduction MySQL - Buffers and storage engines OS/Tools/Instrumentation Solutions Cases / Examples Future Conclusion Appendix III Heap structure struct mem_block_info_struct { ulint magic_n; char file_name[8]; ulint line; UT_LIST_BASE_NODE_T(mem_block_t) base; UT_LIST_NODE_T(mem_block_t) list; ulint len; ulint total_size; ulint type; ulint free; ulint start; void* free_block; void* buf_block; }; Raghavendra Prabhu Percona MySQL Memory analysed