Connect memory usage

You are viewing an old version of this article. View the current version here.

When creating a connection, a THD object is created for that connection. This contains all connection information and also caches to speed up queries and avoid frequent malloc() calls.

When creating a new connection, the following malloc() calls are done for the THD:

Following information is the state in MariaDB 10.6.1 when compiled without debugging.

Local thread memory

This is part of select memory_used from information_schema.processlist .

Amount allocatedWhere allocated Description
26646THD::THDAllocation of THD object
256Statement_map::Statement_map(), my_hash_init(key_memory_prepared_statement_map, &st_hashPrepared statements
256my_hash_init(key_memory_prepared_statement_map, &names_hashNames of used prepared statements
128wsrep_wfc(), Opt_trace_context(), dynamic_array()
1024Diagnostics_area::init(),init_sql_alloc(PSI_INSTRUMENT_ME, &m_warn_root
120Session_sysvars_tracker, global_system_variables.session_track_system_variablesTracking of changed session variables
280THD::THD,my_hash_init(key_memory_user_var_entry,&user_vars
280THD::THD,my_hash_init(PSI_INSTRUMENT_ME, &sequencesCache of used sequences
1048THD::THD, m_token_array= my_malloc(PSI_INSTRUMENT_ME, max_digest_length
16416CONNECT::create_thd(), my_net_init(), net_allocate_new_packet()This is for reading data from the connected user
16416check_connection(), thd->packet.alloc()This is for sending data to connected user

Objects stored in THD->memroot during connect

Amount allocatedWhere allocatedDescription
72send_server_handshake_packet, mpvio->cached_server_packet.pkt=
64parse_client_handshake_packet, thd->copy_with_error(...db,db_len)
32parse_client_handshake_packet, sctx->user=
368ACL_USER::copy(), root=
56ACL_USER::copy(), dst->user= safe_lexcstrdup_root(root, user)
56ACL_USER::copy()
56ACL_USER::copy()
64ACL_USER::copy()
64ACL_USER::copy()
32mysql_change_db()
48dbname_cache->insert(db_name)
40mysql_change_db(), my_register_filename(db.opt)
8216load_db_opt(), init_io_cache()Disk cache for reading db.opt
1112load_db_opts(), put_dbopts()

State at first call to mysql_execute_command

(gdb) p thd->status_var.local_memory_used
$24 = 75496
(gdb) p thd->status_var.global_memory_used
$25 = 17544
(gdb) p thd->variables.query_prealloc_size
$30 = 24576
(gdb) p thd->variables.query_alloc_block_size
$29 = 16384

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.