Bug #99556 Avoid sequentially consistent atomics for atomic counters
Submitted: 13 May 2020 18:18 Modified: 15 May 2020 11:48
Reporter: Sergey Glushchenko Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S5 (Performance)
Version:8.0.20 OS:Any
Assigned to: CPU Architecture:ARM

[13 May 2020 18:18] Sergey Glushchenko
Description:
std::atomic defaults to sequentially consistent memory ordering.
However there are counters that don't really need to use SEQ_CST
memory order, they only need atomicity. While there is no
difference on x86 CPUs, on ARM servers we can see significant
scalability improvements when using weaker memory ordering.

Good example of such counter is the number of running threads,
which we can get rid of entirely as discussed in bug #99412.

Another example is atomic_global_query_id, which becomes the
bottleneck after fixing the bug #99412.

How to repeat:
Run in-memory sysbench oltp_ps with 1024 threads on ARM server and analyze scalability bottlenecks.

Suggested fix:
The patch below
[13 May 2020 18:20] Sergey Glushchenko
suggested fix

Attachment: bug99556.patch (application/octet-stream, text), 8.39 KiB.

[14 May 2020 3:00] Krunal Bauskar
Why introduce another structure when existing invocations that are limited could be fixed to using fetch_add/fetch_sub with the needed memory model.
[14 May 2020 12:45] MySQL Verification Team
HI Mr. Glushchenko and Mr. Bauskar,

Thank you for your important contribution.

However, as far as I understand, your patch requires additional simplification.

Please, do let me know when new patch is ready and I will verify this bug report ASAP.
[15 May 2020 6:57] Sergey Glushchenko
Hi Mr. Milivojevic,

I think this patch is good to go. Atomics are often used just as counters in server code and InnoDB, their use is not limited to the cases fixed in this patch. In the future I plan to submit another patch fixing some hot InnoDB counters.

Also, introducing the new datatype makes the patch smaller.

And finally, if we need to use one of the counters in the new code or modify existing code we don't need to remember to explicitly specify memory order.
[15 May 2020 11:48] MySQL Verification Team
Hello  Mr. Glushchenko,

This report is verified as reported.

Thank you for your contribution.