Skip to content

Experiment: atomic buf page fields - #6130

Draft
polchawa-percona wants to merge 1 commit into
percona:8.4from
polchawa-percona:atomic-buf-page-fields
Draft

Experiment: atomic buf page fields#6130
polchawa-percona wants to merge 1 commit into
percona:8.4from
polchawa-percona:atomic-buf-page-fields

Conversation

@polchawa-percona

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread storage/innobase/include/buf0buf.h Outdated
@return true if the state is BUF_BLOCK_MEMORY, or false. */
[[nodiscard]] bool is_memory() const noexcept {
return state == BUF_BLOCK_MEMORY;
return state.load(std::memory_order_seq_cst) == BUF_BLOCK_MEMORY;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seq_cst is default, do we want to specify it?

Comment thread storage/innobase/buf/buf0buf.cc Outdated
<< ",\"old\":" << page.old
<< ",\"first_accessed\":" << time_elapsed(page.access_time)
<< ",\"old\":" << page.old << ",\"first_accessed\":"
<< time_elapsed(page.access_time.load(std::memory_order_seq_cst))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are not using relaxed, while in other peek reads we do - why?

Comment thread storage/innobase/buf/buf0buf.cc Outdated
atomic, but was never protected by block_mutex to begin with (see
its invariant at the field declaration and buf_block_modify_clock_inc()
in buf0buf.ic) -- this read is an inherently best-effort snapshot,
reconfirmed below (line ~4796) under a real latch, same as before

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line ref is not a good idea...

checked earlier. This check is to reduce contention on page mutex
for hot pages (access time would be set only if it was zero anyway). */
if (access_time == std::chrono::steady_clock::time_point{}) {
buf_page_mutex_enter(block);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is still here?
Shouldn't all this code, access_time local variable, all the comments etc be removed?
Just check if the field is empty and call buf_page_set_accessed - I don't understand why we are doing all that here.
buf_page_set_accessed should return bool if the access time was changed out from empty.
A local bool was_not_accessed_before{} should be added and set to the buf_page_set_accessed result.

Furthermore, look at all usages of buf_page_set_accessed. Some have similar pattern:

 if (access_time == std::chrono::steady_clock::time_point{}) {
    buf_page_mutex_enter(block);

    buf_page_set_accessed(&block->page);

    buf_page_mutex_exit(block);
  }

We could rewrite them to buf_page_set_accessed(&block->page); only.
Also, the if (access_time == std::chrono::steady_clock::time_point{}) { should be inside the buf_page_set_accessed itself - doing costly CAS directly alone would not be best.

This all is not a must, the code works as it is now, but it seems we could prune more mutex enters from hot-ish paths and remove a lot of code.

Comment thread storage/innobase/include/buf0buf.ic Outdated
/* Make this the time of the first access. */
bpage->access_time = std::chrono::steady_clock::now();
}
/* Make this the time of the first access, unless access_time is already

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unconditional CAS is more costly than a check first, especially when we assume the CAS will fail most of the time - the value will usually not be empty.
This is a problem in buf_page_get_known_nowait most probably - a test using a lot of AHI could regress.
This comment is very related to my longer review comment in the optimistic get function.

Add a global acquire fence in place of the removed mutex to preserve
the memory ordering guarantee for the state/modify_clock check.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants