Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-33840

tpool - switch off maintenance timer when not needed

Details

    Description

      Reported by monty:
      The maintenance timer is there to prevent deadlocks, i.e create additional threads when tpool does not make progress. It is only rarely needed, but it still wakes up every 400 milliseconds.
      It could be switched off, or frequency lowered, when server is idle.

      Update April 17 2024. It is not possible to switch that timer entirely OFF, attempts to do this are deadlock prone (mostly due to mysys thr_timer, which holds global lock for entire duration of the callback). If we ever try out luck, then with another timer implementation, not mysys.
      However switch between longer and shorter timer periods are still possible, so this path will be taken

      Attachments

        Issue Links

          Activity

            wlad Vladislav Vaintroub added a comment - - edited

            thr_timer deadlocking, when attempting to switch timer off entirely. LOCK_timer is held in frame #17, and new lock attempt is in frame #9

            #7  0x000055a8fafbed30 in safe_mutex_lock (mp=0x55a8fc56f100 <LOCK_timer>, my_flags=0, file=0x55a8fb51cf08 "/home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c", line=221) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_mutex.c:262
            #8  0x000055a8fafb873b in psi_mutex_lock (that=0x55a8fc56f100 <LOCK_timer>, file=0x55a8fb51cf08 "/home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c", line=221) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/my_thr_init.c:487
            #9  0x000055a8fafc05f9 in inline_mysql_mutex_lock (that=0x55a8fc56f100 <LOCK_timer>, src_file=0x55a8fb51cf08 "/home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c", src_line=221) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/include/mysql/psi/mysql_thread.h:746
            #10 0x000055a8fafc0e7f in thr_timer_end (timer_data=0x55a8fca9c0e8) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c:221
            #11 0x000055a8faf1ed3e in tpool::thread_pool_generic::timer_generic::set_time (this=0x55a8fca9c0e0, initial_delay_ms=0, period_ms=400) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:397
            #12 0x000055a8faf1e1ad in tpool::thread_pool_generic::switch_timer (this=0x55a8fca9be40, state=tpool::thread_pool_generic::timer_state_t::ON, lk=...) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:932
            #13 0x000055a8faf1d358 in tpool::thread_pool_generic::add_thread (this=0x55a8fca9be40, lk=...) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:733
            #14 0x000055a8faf1db50 in tpool::thread_pool_generic::maybe_wake_or_create_thread (this=0x55a8fca9be40, lk=...) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:840
            #15 0x000055a8faf1dd1d in tpool::thread_pool_generic::submit_task (this=0x55a8fca9be40, task=0x55a8fcbf99a0) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:873
            #16 0x000055a8faf1eb1c in tpool::thread_pool_generic::timer_generic::submit_task (arg=0x55a8fcbf9960) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:370
            #17 0x000055a8fafc103d in process_timers (now=0x7f5a39693b20) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c:271
            #18 0x000055a8fafc122e in timer_handler (arg=0x0) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c:315
            #19 0x000055a8fa9f4e51 in pfs_spawn_thread (arg=0x55a8fc9be5c8) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/storage/perfschema/pfs.cc:220
            

            wlad Vladislav Vaintroub added a comment - - edited thr_timer deadlocking, when attempting to switch timer off entirely. LOCK_timer is held in frame #17, and new lock attempt is in frame #9 #7 0x000055a8fafbed30 in safe_mutex_lock (mp=0x55a8fc56f100 <LOCK_timer>, my_flags=0, file=0x55a8fb51cf08 "/home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c", line=221) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_mutex.c:262 #8 0x000055a8fafb873b in psi_mutex_lock (that=0x55a8fc56f100 <LOCK_timer>, file=0x55a8fb51cf08 "/home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c", line=221) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/my_thr_init.c:487 #9 0x000055a8fafc05f9 in inline_mysql_mutex_lock (that=0x55a8fc56f100 <LOCK_timer>, src_file=0x55a8fb51cf08 "/home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c", src_line=221) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/include/mysql/psi/mysql_thread.h:746 #10 0x000055a8fafc0e7f in thr_timer_end (timer_data=0x55a8fca9c0e8) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c:221 #11 0x000055a8faf1ed3e in tpool::thread_pool_generic::timer_generic::set_time (this=0x55a8fca9c0e0, initial_delay_ms=0, period_ms=400) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:397 #12 0x000055a8faf1e1ad in tpool::thread_pool_generic::switch_timer (this=0x55a8fca9be40, state=tpool::thread_pool_generic::timer_state_t::ON, lk=...) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:932 #13 0x000055a8faf1d358 in tpool::thread_pool_generic::add_thread (this=0x55a8fca9be40, lk=...) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:733 #14 0x000055a8faf1db50 in tpool::thread_pool_generic::maybe_wake_or_create_thread (this=0x55a8fca9be40, lk=...) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:840 #15 0x000055a8faf1dd1d in tpool::thread_pool_generic::submit_task (this=0x55a8fca9be40, task=0x55a8fcbf99a0) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:873 #16 0x000055a8faf1eb1c in tpool::thread_pool_generic::timer_generic::submit_task (arg=0x55a8fcbf9960) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/tpool/tpool_generic.cc:370 #17 0x000055a8fafc103d in process_timers (now=0x7f5a39693b20) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c:271 #18 0x000055a8fafc122e in timer_handler (arg=0x0) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysys/thr_timer.c:315 #19 0x000055a8fa9f4e51 in pfs_spawn_thread (arg=0x55a8fc9be5c8) at /home/buildbot/amd64-ubuntu-2204-debug-ps/build/storage/perfschema/pfs.cc:220

            People

              wlad Vladislav Vaintroub
              wlad Vladislav Vaintroub
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.