Bug #95989 Possible to avoid merging ibuf for undo spaces in buf_page_create()?
Submitted: 26 Jun 2019 2:32 Modified: 12 Aug 2019 16:48
Reporter: Fungo Wang (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S5 (Performance)
Version:8.0.16 OS:Any
Assigned to: CPU Architecture:Any
Tags: buf_page_create, ibuf, temporary space, undo space

[26 Jun 2019 2:32] Fungo Wang
Description:
I guess we can optimize away ibuf_merge_or_delete_for_page() invoking in buf_page_create() for undo spaces.

The corresponding stack is:
#0  ibuf_merge_or_delete_for_page 
#1  0x0000000005fe8d14 in buf_page_create
#2  0x00000000062372bf in fsp_page_create
#3  0x0000000006238244 in fsp_alloc_free_page
#4  0x000000000623fb79 in fseg_alloc_free_page_low
#5  0x000000000623c238 in fseg_create_general
#6  0x0000000005e9f26f in trx_undo_seg_create
#7  0x0000000005ea3add in trx_undo_create
#8  0x0000000005ea493a in trx_undo_assign_undo
#9  0x0000000005e4ebfe in trx_undo_report_row_operation

Ibuf will not cache changes for temporary or undo spaces, so normally there is no need to try ibuf_merge_or_delete_for_page() for them.

There is no ibuf entry for undo pages, but ibuf_merge_or_delete_for_page() still need to check whether there is ibuf entry, just as normal procedure.
And this checking need to get RW_X_LATCH on the ibuf page, which is unnecessary.

There is already such optimization for temporary spaces in ibuf_merge_or_delete_for_page():

4017  if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE ||
4018      trx_sys_hdr_page(page_id) || fsp_is_system_temporary(page_id.space())) {
4019    return;
4020  }

And for both temporary and undo sapces while reading page in buf_page_io_complete()

5186    if (uncompressed && !Compression::is_compressed_page(frame) &&
5187        !recv_no_ibuf_operations &&
5188        fil_page_get_type(frame) == FIL_PAGE_INDEX && page_is_leaf(frame) &&
5189        !fsp_is_system_temporary(bpage->id.space()) &&
5190        !fsp_is_undo_tablespace(bpage->id.space())) {
5191      ibuf_merge_or_delete_for_page((buf_block_t *)bpage, bpage->id,
5192                                    &bpage->size, TRUE);
5193    }
5194  }

How to repeat:
Read the code

Suggested fix:
Like for temporary spaces, we can also skip merging ibuf entry for undo spaces.
[26 Jun 2019 12:30] MySQL Verification Team
Hello Mr. Wang,

Thank you for this performance optimisation report.

I agree with you on this one.

Verified as reported.
[12 Aug 2019 16:48] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 8.0.18 release, and here's the changelog entry:

The ibuf_merge_or_delete_for_page() function, responsible for merging and
deleting pages in the change buffer, is no longer called for undo
tablespaces and temporary tablespaces. The change buffer does not contain
entries for those tablespace types.
[13 Aug 2019 12:46] MySQL Verification Team
Thank you, Daniel ....