• Marko Mäkelä's avatar
    MDEV-32374 log_sys.lsn_lock is a performance hog · 7443ad1c
    Marko Mäkelä authored
    The log_sys.lsn_lock that was introduced in
    commit a635c406
    had better be located in the same cache line with log_sys.latch
    so that log_t::append_prepare() needs to modify only two first
    cache lines where log_sys is stored.
    
    log_t::lsn_lock: On Linux, change the type from pthread_mutex_t to
    something that may be as small as 32 bits, to pack more data members
    in the same cache line. On Microsoft Windows, CRITICAL_SECTION works
    better.
    
    log_t::check_flush_or_checkpoint_: Renamed to need_checkpoint.
    There is no need to pause all writer threads in log_free_check() when
    we only need to write log_sys.buf to ib_logfile0. That will be done in
    mtr_t::commit().
    
    log_t::append_prepare_wait(): Make the member function non-static
    to simplify the call interface, and add a parameter for the LSN.
    
    log_t::append_prepare(): Invoke append_prepare_wait() at most once.
    Only set_check_for_checkpoint() if a log checkpoint needs to
    be written. If the log buffer needs to be written, we will take care
    of it ourselves later in our caller. This will reduce interference
    with log_free_check() in other threads.
    
    mtr_t::commit(): Call log_write_up_to() if needed.
    
    log_t::get_write_target(): Return a log_write_up_to() target
    to mtr_t::commit().
    
    buf_flush_ahead(): If we are in furious flushing, call
    log_sys.set_check_for_checkpoint() so that all writers will wait
    in log_free_check() until the checkpoint is done. Otherwise,
    the test innodb.insert_into_empty could occasionally report
    an error "Crash recovery is broken".
    
    log_check_margins(): Replaced by log_free_check().
    
    log_flush_margin(): Removed. This is part of mtr_t::commit()
    and other operations that write log.
    
    log_t::create(), log_t::attach(): Guarantee that buf_free < max_buf_free
    will always hold on PMEM, to satisfy an assumption of
    log_t::get_write_target().
    
    log_write_up_to(): Assert lsn!=0. Such calls are not incorrect, but it
    is cheaper to test that single unlikely condition in mtr_t::commit()
    rather than test several conditions in log_write_up_to().
    
    innodb_drop_database(), unlock_and_close_files(): Check the LSN before
    calling log_write_up_to().
    
    ha_innobase::commit_inplace_alter_table(): Remove redundant calls to
    log_write_up_to() after calling unlock_and_close_files().
    
    Reviewed by: Vladislav Vaintroub
    Stress tested by: Matthias Leich
    Performance tested by: Steve Shaw
    7443ad1c
srw_lock.h 15.4 KB