InnoDB allocation policy and performance for additional memory pools

Source: Internet
Author: User

InnoDB additional memory pool allocation policy and performance tomorrow will be better. QQ:715169549remark: without permission, reprint is forbidden, thank you for your cooperation. //memory Pool structure Body/** Data structure for a memory pool. The space is allocated using the Buddyalgorithm, where free list I contains areas of size 2 to power I.*/structmem_pool_t{byte* BUF;/*!< Memory Pool*/ulint size; /*!< Memory Common pool size*/ulint reserved; /*!< amount of currently allocated memory*/ib_mutex_t Mutex; /*!< Mutex protecting this struct*/ut_list_base_node_t (mem_area_t) free_list[ -];/*!< lists of free memory Areas:an area was put to the list whose number is the 2-logarithm of the area size*/};//structure that records the usage of blocks in a memory pool/** Memory Area header*/structmem_area_t{Ulint Size_and_free; /*!< Memory Area size was obtained by anding with ~mem_area_free; List if anding with mem_area_free results in nonzero*/ut_list_node_t (mem_area_t) free_list; /*!< free list node*/};//additional memory pool allocation functionsvoidSrv_general_init (void)/*==================*/{ut_mem_init (); /*Reset The system variables in the recovery module.*/Recv_sys_var_init ();    Os_sync_init ();    Sync_init (); //srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size; //an additional memory pool allocation is performed here for the size of Srv_mem_pool_sizeMem_init (srv_mem_pool_size);    Que_init (); Row_mysql_init ();}//Memory Initialization FunctionsvoidMem_init (/*=====*/ulint size)/*!< in:common Pool size in bytes*/{#ifdef univ_mem_debug ulint i; /*Initialize the hash table*/ut_a (FALSE==mem_hash_initialized); Mutex_create (Mem_hash_mutex_key,&Mem_hash_mutex, Sync_mem_hash);  for(i =0; i < mem_hash_size; i++) {Ut_list_init (*Mem_hash_get_nth_cell (i));    } ut_list_init (Mem_all_list_base); Mem_hash_initialized=TRUE;#endif    //if the value of Srv_use_sys_malloc is initialized by Innodb_use_sys_malloc. //Innodb_use_sys_malloc=0 represents a one-time allocation using an additional pool of memory, and subsequent releases and requests are made in this memory pool without the need for additional//make a malloc request    if(univ_likely (Srv_use_sys_malloc)) {/*When Innodb_use_sys_malloc are set, the Mem_comm_pool won ' t be used for any allocations. We Create a dummy mem_comm_pool, because some statistics and debugging code relies on it being initialized. */size=1;//if innodb_use_sys_malloc=1, the memory pool structure body size (mem_pool_t->size) of the additional memory pool during the entire MySQL run is 1 bytes. } mem_comm_pool=mem_pool_create (size);} Srv_use_sys_malloc: This parameter controls the way the InnoDB extra memory is allocated;1), which indicates that the memory request is in malloc, the memory usage request size is recorded in mem_area_t, the size of the additional memory pool structure is only one byte size;0), the InnoDB memory pool is used for allocation. Note that this is only a memory match for the additional memory pool (Univ_intern mem_pool_t* Mem_comm_pool = NULL). When srv_use_sys_malloc=at 0, after MySQL is started, a one-time request for Srv_mem_pool_size bytes of memory is put into mem_pool_t, and each usage structure (mem_area_t) is initialized. If Srv_use_sys_malloc=1, which means that the memory request is using malloc. Mem_heap_create_block_func (/*=======================*/mem_heap_t* Heap,/*!< in:memory Heap or NULL if first block should be created*/ulint N,/*!< In:number of bytes needed for user data*/#ifdef Univ_debugConst Char* file_name,/*!< in:file name where created*/Ulint Line,/*!< In:line where created*/#endif/* Univ_debug */ulint type)/*!< In:type of heap:mem_heap_dynamic or Mem_heap_buffer*/Description: Call Mem_area_alloc in Mem_heap_create_block_func (&Len, Mem_comm_pool)); This function mainly records the free_list information in mem_pool_t (how much memory was requested) at this time Mem_comm_pool-size is 1, only the information in the free_list is changed. void*Mem_area_alloc (/*===========*/Ulint* Psize,/*!< in:requested size in bytes; For optimum space usage, the size should be a power of 2                Minus mem_area_extra_size; out:allocated size in bytes (greater than or equal to the requested size)*/mem_pool_t* Pool)/*!< in:memory Pool*/Description: The Mem_area_alloc function returns return (Ut_malloc (size)) and uses the Malloc method to request additional memory pool services. //Official Note:14.13.3Configuring the Memory Allocator forInnodbwhen InnoDB was developed, the memory allocators supplied with operating systems and run-time libraries were often lackinginchPerformance and scalability. At that time, there were no memory allocator libraries tuned forMulti-Core CPUs. Therefore, InnoDB implemented its own memory allocatorinchThe MEM subsystem. This allocator isGuarded by a single mutex, which may become a bottleneck. InnoDB also implements a wrapperInterfaceAround the system allocator (mallocand Free) that islikewise guarded by a single mutex. Today, asMulti-Core Systems has become more widely available, and asOperating systems has matured, significant improvements has been madeinchThe memory allocators provided with operating systems. New memory allocators perform better and is more scalable than they wereinchThe past. The leading high-performance memory allocators include hoard, Libumem, Mtmalloc, Ptmalloc, Tbbmalloc, and Tcmalloc. Most workloads, especially thosewhereMemory isFrequently allocated and released (such asMulti-Table joins), benefit from usingA more highly tuned memory allocator asOpposed to theInternal, innodb-specific memory allocator.  You can control whether InnoDB uses it own memory allocator or an allocator of the operating system, by setting the value Of the System configuration parameter Innodb_use_sys_mallocinchThe MySQL option file (MY.CNF or My.ini). IfSetTo ON or1(Thedefault), InnoDB uses themallocand FreeFunctions of the underlying system rather than manage memory pools itself. This parameter isNot dynamic, and takes effect only when the system isStarted. ToContinueTo use the InnoDB memory allocator,SetInnodb_use_sys_malloc to0. When the InnoDB memory allocator isDisabled, InnoDB ignores the value of the parameter innodb_additional_mem_pool_size. The InnoDB memory allocator uses an additional memory pool forSatisfying allocation requests without have to fall back to the system memory allocator. When the InnoDB memory allocator isdisabled, all such allocation requests is fulfilled by the system memory allocator. On Unix-like systems, use dynamic linking, replacing the memory allocator asEasy asmaking the environment variable ld_preload or ld_library_path point to the dynamic LIBRARY that implements the Alloca Tor. On other systems, some relinking is necessary. Please refer to the documentation of the memory allocator library of your choice. Since InnoDB cannot track all memory with when the system memory allocator isUsed (Innodb_use_sys_malloc isOn), the section "BUFFER POOL and MEMORY"inchThe output of the SHOW ENGINE INNODB STATUS command only includes the buffer pool statisticsinchThe "Total memory allocated". Any memory allocatedusingThe MEM subsystem orusingUt_malloc isexcluded. Noteinnodb_use_sys_malloc and innodb_additional_mem_pool_size are deprecatedinchMysql5.6.3and would be removedinchA future release.

InnoDB allocation policy and performance for additional memory pools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.