Skip to content

Defer Memory Allocation of AHI Hash Tables Until AHI Is Enabled - #729

Open
SongLibing wants to merge 1 commit into
mysql:trunkfrom
SongLibing:port_delay_ahi_memory_allocation
Open

Defer Memory Allocation of AHI Hash Tables Until AHI Is Enabled#729
SongLibing wants to merge 1 commit into
mysql:trunkfrom
SongLibing:port_delay_ahi_memory_allocation

Conversation

@SongLibing

@SongLibing SongLibing commented Aug 24, 2026

Copy link
Copy Markdown

Problem

The AHI hash tables are initialized at startup even when AHI is disabled. They are initialized with
buf_pool_get_curr_size()/sizeof(void *)/64 cells. Each cell takes 8 bytes. So the total memory they occupy is approximately equal to 1/64 of the buffer pool size. The memory is wasted if AHI is disabled. On large servers, initializing large hash tables slows startup.

Solution

This commit initializes the AHI hash tables with one cell per AHI partition if AHI is disabled. The hash tables are restored to their normal size before AHI is enabled.

With one slot existing, the AHI system is fully initialized. This preserves the invariant that the per-partition hash table objects always exist.

During a buffer pool resizing, AHI is temporarily disabled. If AHI was enabled when the resize started, its full-sized hash tables are retained and resized only when necessary, avoiding an unnecessary shrink-and-restore cycle.

What does this change do?

https://bugs.mysql.com/bug.php?id=112223

Why is it needed?

This patch reduces memory usage and startup time when AHI is disabled. AHI has been disabled by default since 8.4 and AHI is not recommended for production use. Therefore, without this commit, most of the server would wastes an amount of memory approximately equal to 1/64 of buffer pool size.

How was it tested?

  • Added/updated MTR tests under mysql-test/
  • scripts/ci/mtr.sh passes locally
  • Ran the relevant full suite (name it): ______

Contributor checklist

  • Code is formatted (scripts/ci/format.sh)
  • Commits are focused with descriptive messages

AI assistance

  • I did not use AI assistance for this contribution
  • I used AI assistance for this contribution

If AI assistance was used, describe the tool(s) and extent of use: Port the patch, added more testcases.

Areas touched

InnoDB

Problem
=======
The AHI hash tables are initialized at startup even when AHI
is disabled. They are initialized with
buf_pool_get_curr_size()/sizeof(void *)/64 cells. Each slot takes
8 bytes. So the total memory they occupy is approximately equal to
1/64 of the buffer pool size. The memory is wasted if AHI is disabled.
On large servers, initializing large hash tables slows startup.

Solution
========
This commit initializes the AHI hash tables with one cell per AHI
partition if AHI is disabled. The hash tables are restored to their
normal size before AHI is enabled.

With one slot existing, the AHI system is fully initialized. This
preserves the invariant that the per-partition hash table objects
always exist.

During a buffer pool resizing, AHI is temporarily disabled. If AHI was
enabled when the resize started, its full-sized hash tables are retained
and resized only when necessary, avoiding an unnecessary
shrink-and-restore cycle.
@SongLibing
SongLibing requested a review from a team August 24, 2026 11:09
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Aug 24, 2026
@github-actions github-actions Bot added InnoDB Changes touching InnoDB storage engine code Tests Changes touching test code or test data Review Requested Review requested from code owners labels Aug 24, 2026
@gopshank
gopshank requested review from mayprasa and removed request for seemasundara August 24, 2026 23:43
@github-actions github-actions Bot added Build Passed PR build passed MTR Failed MTR suite failed labels Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build Passed PR build passed InnoDB Changes touching InnoDB storage engine code MTR Failed MTR suite failed OCA Verified All contributors have signed the Oracle Contributor Agreement. Review Requested Review requested from code owners Tests Changes touching test code or test data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant