| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2013, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/page0size.h |
| 29 |
A class describing a page size. |
| 30 |
|
| 31 |
Created Nov 14, 2013 Vasil Dimov |
| 32 |
*******************************************************/ |
| 33 |
|
| 34 |
#ifndef page0size_t |
| 35 |
#define page0size_t |
| 36 |
|
| 37 |
#include "fsp0types.h" |
| 38 |
|
| 39 |
constexpr size_t FIELD_REF_SIZE = 20; |
| 40 |
|
| 41 |
/** A BLOB field reference full of zero, for use in assertions and |
| 42 |
tests.Initially, BLOB field references are set to zero, in |
| 43 |
dtuple_convert_big_rec(). */ |
| 44 |
extern const byte field_ref_zero[FIELD_REF_SIZE]; |
| 45 |
|
| 46 |
constexpr size_t PAGE_SIZE_T_SIZE_BITS = 17; |
| 47 |
|
| 48 |
/** Page size descriptor. Contains the physical and logical page size, as well |
| 49 |
as whether the page is compressed or not. */ |
| 50 |
class page_size_t { |
| 51 |
public: |
| 52 |
/** Constructor from (physical, logical, is_compressed). |
| 53 |
@param[in] physical physical (on-disk/zipped) page size |
| 54 |
@param[in] logical logical (in-memory/unzipped) page size |
| 55 |
@param[in] is_compressed whether the page is compressed */ |
| 56 |
page_size_t(uint32_t physical, uint32_t logical, bool is_compressed) { |
| 57 |
if (physical == 0) { |
| 58 |
physical = UNIV_PAGE_SIZE_ORIG; |
| 59 |
} |
| 60 |
if (logical == 0) { |
| 61 |
logical = UNIV_PAGE_SIZE_ORIG; |
| 62 |
} |
| 63 |
|
| 64 |
m_physical = static_cast<unsigned>(physical); |
| 65 |
m_logical = static_cast<unsigned>(logical); |
| 66 |
m_is_compressed = static_cast<unsigned>(is_compressed); |
| 67 |
|
| 68 |
ut_ad(physical <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
| 69 |
ut_ad(logical <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
| 70 |
|
| 71 |
ut_ad(ut_is_2pow(physical)); |
| 72 |
ut_ad(ut_is_2pow(logical)); |
| 73 |
|
| 74 |
ut_ad(logical <= UNIV_PAGE_SIZE_MAX); |
| 75 |
ut_ad(logical >= physical); |
| 76 |
ut_ad(!is_compressed || physical <= UNIV_ZIP_SIZE_MAX); |
| 77 |
} |
| 78 |
|
| 79 |
/** Constructor from (fsp_flags). |
| 80 |
@param[in] fsp_flags filespace flags */ |
| 81 |
explicit page_size_t(uint32_t fsp_flags) { |
| 82 |
uint32_t ssize = FSP_FLAGS_GET_PAGE_SSIZE(fsp_flags); |
| 83 |
|
| 84 |
/* If the logical page size is zero in fsp_flags, then use the |
| 85 |
legacy 16k page size. */ |
| 86 |
ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize; |
| 87 |
|
| 88 |
/* Convert from a 'log2 minus 9' to a page size in bytes. */ |
| 89 |
const ulint size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize); |
| 90 |
|
| 91 |
ut_ad(size <= UNIV_PAGE_SIZE_MAX); |
| 92 |
ut_ad(size <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
| 93 |
|
| 94 |
m_logical = size; |
| 95 |
|
| 96 |
ssize = FSP_FLAGS_GET_ZIP_SSIZE(fsp_flags); |
| 97 |
|
| 98 |
/* If the fsp_flags have zero in the zip_ssize field, then |
| 99 |
it means that the tablespace does not have compressed pages |
| 100 |
and the physical page size is the same as the logical page |
| 101 |
size. */ |
| 102 |
if (ssize == 0) { |
| 103 |
m_is_compressed = false; |
| 104 |
m_physical = m_logical; |
| 105 |
} else { |
| 106 |
m_is_compressed = true; |
| 107 |
|
| 108 |
/* Convert from a 'log2 minus 9' to a page size |
| 109 |
in bytes. */ |
| 110 |
const ulint phy = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize); |
| 111 |
|
| 112 |
ut_ad(phy <= UNIV_ZIP_SIZE_MAX); |
| 113 |
ut_ad(phy <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
| 114 |
|
| 115 |
m_physical = phy; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
/** Retrieve the physical page size (on-disk). |
| 120 |
@return physical page size in bytes */ |
| 121 |
inline size_t physical() const { |
| 122 |
ut_ad(m_physical > 0); |
| 123 |
|
| 124 |
return (m_physical); |
| 125 |
} |
| 126 |
|
| 127 |
/** Retrieve the logical page size (in-memory). |
| 128 |
@return logical page size in bytes */ |
| 129 |
inline size_t logical() const { |
| 130 |
ut_ad(m_logical > 0); |
| 131 |
return (m_logical); |
| 132 |
} |
| 133 |
|
| 134 |
page_no_t extent_size() const { |
| 135 |
page_no_t size = 0; |
| 136 |
switch (m_physical) { |
| 137 |
case 4096: |
| 138 |
size = 256; |
| 139 |
break; |
| 140 |
case 8192: |
| 141 |
size = 128; |
| 142 |
break; |
| 143 |
case 16384: |
| 144 |
case 32768: |
| 145 |
case 65536: |
| 146 |
size = 64; |
| 147 |
break; |
| 148 |
default: |
| 149 |
ut_d(ut_error); |
| 150 |
} |
| 151 |
return (size); |
| 152 |
} |
| 153 |
|
| 154 |
size_t extents_per_xdes() const { return (m_physical / extent_size()); } |
| 155 |
|
| 156 |
/** Check whether the page is compressed on disk. |
| 157 |
@return true if compressed */ |
| 158 |
inline bool is_compressed() const { return (m_is_compressed); } |
| 159 |
|
| 160 |
/** Copy the values from a given page_size_t object. |
| 161 |
@param[in] src page size object whose values to fetch */ |
| 162 |
inline void copy_from(const page_size_t &src) { |
| 163 |
m_physical = src.physical(); |
| 164 |
m_logical = src.logical(); |
| 165 |
m_is_compressed = src.is_compressed(); |
| 166 |
} |
| 167 |
|
| 168 |
/** Check if a given page_size_t object is equal to the current one. |
| 169 |
@param[in] a page_size_t object to compare |
| 170 |
@return true if equal */ |
| 171 |
inline bool equals_to(const page_size_t &a) const { |
| 172 |
return (a.physical() == m_physical && a.logical() == m_logical && |
| 173 |
a.is_compressed() == (bool)m_is_compressed); |
| 174 |
} |
| 175 |
|
| 176 |
inline void set_flag(uint32_t fsp_flags) { |
| 177 |
uint32_t ssize = FSP_FLAGS_GET_PAGE_SSIZE(fsp_flags); |
| 178 |
|
| 179 |
/* If the logical page size is zero in fsp_flags, then |
| 180 |
use the legacy 16k page size. */ |
| 181 |
ssize = (0 == ssize) ? UNIV_PAGE_SSIZE_ORIG : ssize; |
| 182 |
|
| 183 |
/* Convert from a 'log2 minus 9' to a page size in bytes. */ |
| 184 |
const uint32_t size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize); |
| 185 |
|
| 186 |
ut_ad(size <= UNIV_PAGE_SIZE_MAX); |
| 187 |
ut_ad(size <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
| 188 |
|
| 189 |
m_logical = size; |
| 190 |
|
| 191 |
ssize = FSP_FLAGS_GET_ZIP_SSIZE(fsp_flags); |
| 192 |
|
| 193 |
/* If the fsp_flags have zero in the zip_ssize field, |
| 194 |
then it means that the tablespace does not have |
| 195 |
compressed pages and the physical page size is the same |
| 196 |
as the logical page size. */ |
| 197 |
if (ssize == 0) { |
| 198 |
m_is_compressed = false; |
| 199 |
m_physical = m_logical; |
| 200 |
} else { |
| 201 |
m_is_compressed = true; |
| 202 |
|
| 203 |
/* Convert from a 'log2 minus 9' to a page size |
| 204 |
in bytes. */ |
| 205 |
const ulint phy = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize); |
| 206 |
|
| 207 |
ut_ad(phy <= UNIV_ZIP_SIZE_MAX); |
| 208 |
ut_ad(phy <= (1 << PAGE_SIZE_T_SIZE_BITS)); |
| 209 |
|
| 210 |
m_physical = phy; |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
page_size_t &operator=(const page_size_t &) = default; |
| 215 |
page_size_t(const page_size_t &) = default; |
| 216 |
|
| 217 |
private: |
| 218 |
/* For non compressed tablespaces, physical page size is equal to |
| 219 |
the logical page size and the data is stored in buf_page_t::frame |
| 220 |
(and is also always equal to univ_page_size (--innodb-page-size=)). |
| 221 |
|
| 222 |
For compressed tablespaces, physical page size is the compressed |
| 223 |
page size as stored on disk and in buf_page_t::zip::data. The logical |
| 224 |
page size is the uncompressed page size in memory - the size of |
| 225 |
buf_page_t::frame (currently also always equal to univ_page_size |
| 226 |
(--innodb-page-size=)). */ |
| 227 |
|
| 228 |
/** Physical page size. */ |
| 229 |
unsigned m_physical : PAGE_SIZE_T_SIZE_BITS; |
| 230 |
|
| 231 |
/** Logical page size. */ |
| 232 |
unsigned m_logical : PAGE_SIZE_T_SIZE_BITS; |
| 233 |
|
| 234 |
/** Flag designating whether the physical page is compressed, which is |
| 235 |
true IFF the whole tablespace where the page belongs is compressed. */ |
| 236 |
unsigned m_is_compressed : 1; |
| 237 |
}; |
| 238 |
|
| 239 |
/* Overloading the global output operator to conveniently print an object |
| 240 |
of type the page_size_t. |
| 241 |
@param[in,out] out the output stream |
| 242 |
@param[in] obj an object of type page_size_t to be printed |
| 243 |
@retval the output stream */ |
| 244 |
inline std::ostream &operator<<(std::ostream &out, const page_size_t &obj) { |
| 245 |
out << "[page size: physical=" << obj.physical() |
| 246 |
<< ", logical=" << obj.logical() << ", compressed=" << obj.is_compressed() |
| 247 |
<< "]"; |
| 248 |
return (out); |
| 249 |
} |
| 250 |
|
| 251 |
extern page_size_t univ_page_size; |
| 252 |
|
| 253 |
#endif /* page0size_t */ |