Skip to content

Commit 8ccb3ca

Browse files
committed
MDEV-17491 micro optimize page_id_t further
Let us define page_id_t as a thin wrapper of uint64_t so that the comparison operators can be simplified. This is a follow-up to the original commit 14be814. The comparison operator for recv_sys.pages.emplace() turned out to be a busy spot in a recovery benchmark. That data structure was introduced in MDEV-19586 in commit 177a571.
1 parent f3dac59 commit 8ccb3ca

File tree

2 files changed

+46
-80
lines changed

2 files changed

+46
-80
lines changed

storage/innobase/buf/buf0buf.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2008, Google Inc.
5-
Copyright (c) 2013, 2019, MariaDB Corporation.
5+
Copyright (c) 2013, 2020, MariaDB Corporation.
66
77
Portions of this file contain modifications contributed and copyrighted by
88
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -7144,14 +7144,11 @@ buf_pool_check_no_pending_io(void)
71447144
@param[in,out] out the output stream
71457145
@param[in] page_id the page_id_t object to be printed
71467146
@return the output stream */
7147-
std::ostream&
7148-
operator<<(
7149-
std::ostream& out,
7150-
const page_id_t page_id)
7147+
std::ostream& operator<<(std::ostream &out, const page_id_t page_id)
71517148
{
7152-
out << "[page id: space=" << page_id.m_space
7153-
<< ", page number=" << page_id.m_page_no << "]";
7154-
return(out);
7149+
out << "[page id: space=" << page_id.space()
7150+
<< ", page number=" << page_id.page_no() << "]";
7151+
return out;
71557152
}
71567153

71577154
/** Print the given buf_pool_t object.

storage/innobase/include/buf0types.h

Lines changed: 41 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
4-
Copyright (c) 2019, MariaDB Corporation.
4+
Copyright (c) 2019, 2020, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -135,80 +135,49 @@ this must be equal to srv_page_size */
135135
/* @} */
136136

137137
/** Page identifier. */
138-
class page_id_t {
138+
class page_id_t
139+
{
139140
public:
140-
141-
/** Constructor from (space, page_no).
142-
@param[in] space tablespace id
143-
@param[in] page_no page number */
144-
page_id_t(ulint space, ulint page_no)
145-
: m_space(uint32_t(space)), m_page_no(uint32(page_no))
146-
{
147-
ut_ad(space <= 0xFFFFFFFFU);
148-
ut_ad(page_no <= 0xFFFFFFFFU);
149-
}
150-
151-
bool operator==(const page_id_t& rhs) const
152-
{
153-
return m_space == rhs.m_space && m_page_no == rhs.m_page_no;
154-
}
155-
bool operator!=(const page_id_t& rhs) const { return !(*this == rhs); }
156-
157-
bool operator<(const page_id_t& rhs) const
158-
{
159-
if (m_space == rhs.m_space) {
160-
return m_page_no < rhs.m_page_no;
161-
}
162-
163-
return m_space < rhs.m_space;
164-
}
165-
166-
/** Retrieve the tablespace id.
167-
@return tablespace id */
168-
uint32_t space() const { return m_space; }
169-
170-
/** Retrieve the page number.
171-
@return page number */
172-
uint32_t page_no() const { return m_page_no; }
173-
174-
/** Retrieve the fold value.
175-
@return fold value */
176-
ulint fold() const { return (m_space << 20) + m_space + m_page_no; }
177-
178-
/** Reset the page number only.
179-
@param[in] page_no page number */
180-
void set_page_no(ulint page_no)
181-
{
182-
m_page_no = uint32_t(page_no);
183-
184-
ut_ad(page_no <= 0xFFFFFFFFU);
185-
}
186-
187-
/** Set the FIL_NULL for the space and page_no */
188-
void set_corrupt_id()
189-
{
190-
m_space = m_page_no = ULINT32_UNDEFINED;
191-
}
141+
/** Constructor from (space, page_no).
142+
@param[in] space tablespace id
143+
@param[in] page_no page number */
144+
page_id_t(ulint space, ulint page_no) : m_id(uint64_t{space} << 32 | page_no)
145+
{
146+
ut_ad(space <= 0xFFFFFFFFU);
147+
ut_ad(page_no <= 0xFFFFFFFFU);
148+
}
149+
150+
bool operator==(const page_id_t& rhs) const { return m_id == rhs.m_id; }
151+
bool operator!=(const page_id_t& rhs) const { return m_id != rhs.m_id; }
152+
153+
bool operator<(const page_id_t& rhs) const { return m_id < rhs.m_id; }
154+
155+
/** Retrieve the tablespace id.
156+
@return tablespace id */
157+
uint32_t space() const { return static_cast<uint32_t>(m_id >> 32); }
158+
159+
/** Retrieve the page number.
160+
@return page number */
161+
uint32_t page_no() const { return static_cast<uint32_t>(m_id); }
162+
163+
/** Retrieve the fold value.
164+
@return fold value */
165+
ulint fold() const { return (space() << 20) + space() + page_no(); }
166+
167+
/** Reset the page number only.
168+
@param[in] page_no page number */
169+
void set_page_no(ulint page_no)
170+
{
171+
ut_ad(page_no <= 0xFFFFFFFFU);
172+
m_id= (m_id & ~uint64_t{0} << 32) | page_no;
173+
}
174+
175+
/** Set the FIL_NULL for the space and page_no */
176+
void set_corrupt_id() { m_id= ~uint64_t{0}; }
192177

193178
private:
194-
195-
/** Tablespace id. */
196-
uint32_t m_space;
197-
198-
/** Page number. */
199-
uint32_t m_page_no;
200-
201-
/** Declare the overloaded global operator<< as a friend of this
202-
class. Refer to the global declaration for further details. Print
203-
the given page_id_t object.
204-
@param[in,out] out the output stream
205-
@param[in] page_id the page_id_t object to be printed
206-
@return the output stream */
207-
friend
208-
std::ostream&
209-
operator<<(
210-
std::ostream& out,
211-
const page_id_t page_id);
179+
/** The page identifier */
180+
uint64_t m_id;
212181
};
213182

214183
#ifndef UNIV_INNOCHECKSUM

0 commit comments

Comments
 (0)