MySQL 8.0.30
Source Code Documentation
ut0cpu_cache.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2020, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/ut0cpu_cache.h
28Utilities related to CPU cache. */
29
30#ifndef ut0cpu_cache_h
31#define ut0cpu_cache_h
32
33#include "ut0ut.h"
34namespace ut {
35
36/** CPU cache line size */
37#ifdef __powerpc__
38constexpr size_t INNODB_CACHE_LINE_SIZE = 128;
39#else
40constexpr size_t INNODB_CACHE_LINE_SIZE = 64;
41#endif /* __powerpc__ */
42
43/** Default kernel page size (not assuming huge pages support). */
44constexpr size_t INNODB_KERNEL_PAGE_SIZE_DEFAULT = 4 * 1024;
45
46/**
47A utility wrapper class, which adds padding at the end of the wrapped structure,
48so that the next object after it is guaranteed to be in the next cache line.
49This is to avoid false-sharing.
50Use this, as opposed to alignas(), to avoid problems with allocators which do
51not handle over-aligned types.
52 */
53template <typename T>
54struct Cacheline_padded : public T {
56 // "Inherit" constructors
57 using T::T;
58};
59
60/**
61A utility wrapper class, which aligns T to cacheline boundary.
62This is to avoid false-sharing.
63*/
64template <typename T>
65struct alignas(INNODB_CACHE_LINE_SIZE) Cacheline_aligned : public T {
66 // "Inherit" constructors
67 using T::T;
68};
69
70} /* namespace ut */
71
72#endif /* ut0cpu_cache_h */
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:47
constexpr size_t INNODB_CACHE_LINE_SIZE
CPU cache line size.
Definition: ut0cpu_cache.h:40
constexpr size_t INNODB_KERNEL_PAGE_SIZE_DEFAULT
Default kernel page size (not assuming huge pages support).
Definition: ut0cpu_cache.h:44
A utility wrapper class, which aligns T to cacheline boundary.
Definition: ut0cpu_cache.h:65
A utility wrapper class, which adds padding at the end of the wrapped structure, so that the next obj...
Definition: ut0cpu_cache.h:54
char pad[INNODB_CACHE_LINE_SIZE]
Definition: ut0cpu_cache.h:55
Various utilities.