MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / init_key_cache

Function init_key_cache

mysys/mf_keycache.c:366–528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364*/
365
366int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
367 size_t use_mem, uint division_limit,
368 uint age_threshold)
369{
370 ulong blocks, hash_links;
371 size_t length;
372 int error;
373 DBUG_ENTER("init_key_cache");
374 DBUG_ASSERT(key_cache_block_size >= 512);
375
376 KEYCACHE_DEBUG_OPEN;
377 if (keycache->key_cache_inited && keycache->disk_blocks > 0)
378 {
379 DBUG_PRINT("warning",("key cache already in use"));
380 DBUG_RETURN(0);
381 }
382
383 keycache->global_cache_w_requests= keycache->global_cache_r_requests= 0;
384 keycache->global_cache_read= keycache->global_cache_write= 0;
385 keycache->disk_blocks= -1;
386 if (! keycache->key_cache_inited)
387 {
388 keycache->key_cache_inited= 1;
389 /*
390 Initialize these variables once only.
391 Their value must survive re-initialization during resizing.
392 */
393 keycache->in_resize= 0;
394 keycache->resize_in_flush= 0;
395 keycache->cnt_for_resize_op= 0;
396 keycache->waiting_for_resize_cnt.last_thread= NULL;
397 keycache->in_init= 0;
398 mysql_mutex_init(key_KEY_CACHE_cache_lock,
399 &keycache->cache_lock, MY_MUTEX_INIT_FAST);
400 keycache->resize_queue.last_thread= NULL;
401 }
402
403 keycache->key_cache_mem_size= use_mem;
404 keycache->key_cache_block_size= key_cache_block_size;
405 DBUG_PRINT("info", ("key_cache_block_size: %u",
406 key_cache_block_size));
407
408 blocks= (ulong) (use_mem / (sizeof(BLOCK_LINK) + 2 * sizeof(HASH_LINK) +
409 sizeof(HASH_LINK*) * 5/4 + key_cache_block_size));
410 /* It doesn't make sense to have too few blocks (less than 8) */
411 if (blocks >= 8)
412 {
413 for ( ; ; )
414 {
415 /* Set my_hash_entries to the next bigger 2 power */
416 if ((keycache->hash_entries= next_power(blocks)) < blocks * 5/4)
417 keycache->hash_entries<<= 1;
418 hash_links= 2 * blocks;
419#if defined(MAX_THREADS)
420 if (hash_links < MAX_THREADS + blocks - 1)
421 hash_links= MAX_THREADS + blocks - 1;
422#endif
423 while ((length= (ALIGN_SIZE(blocks * sizeof(BLOCK_LINK)) +

Callers 1

resize_key_cacheFunction · 0.85

Calls 6

next_powerFunction · 0.85
my_large_mallocFunction · 0.85
my_mallocFunction · 0.85
my_large_freeFunction · 0.85
my_errorFunction · 0.85
my_freeFunction · 0.85

Tested by

no test coverage detected