MySQL  8.0.23
Source Code Documentation
buf0buf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2020, 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 also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/buf0buf.h
28  The database buffer pool high-level routines
29 
30  Created 11/5/1995 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef buf0buf_h
34 #define buf0buf_h
35 
36 #include "buf0dblwr.h"
37 #include "buf0types.h"
38 #include "fil0fil.h"
39 #include "hash0hash.h"
40 #include "log0log.h"
41 #include "mtr0types.h"
42 #include "os0proc.h"
43 #include "page0types.h"
44 #include "srv0shutdown.h"
45 #include "srv0srv.h"
46 #include "univ.i"
47 #include "ut0byte.h"
48 #include "ut0rbt.h"
49 
50 #include "buf/buf.h"
51 
52 #include <ostream>
53 
54 // Forward declaration
55 struct fil_addr_t;
56 
57 /** @name Modes for buf_page_get_gen */
58 /** @{ */
59 enum class Page_fetch {
60  /** Get always */
61  NORMAL,
62 
63  /** Same as NORMAL, but hint that the fetch is part of a large scan.
64  Try not to flood the buffer pool with pages that may not be accessed again
65  any time soon. */
66  SCAN,
67 
68  /** get if in pool */
69  IF_IN_POOL,
70 
71  /** get if in pool, do not make the block young in the LRU list */
73 
74  /** get and bufferfix, but set no latch; we have separated this case, because
75  it is error-prone programming not to set a latch, and it should be used with
76  care */
77  NO_LATCH,
78 
79  /** Get the page only if it's in the buffer pool, if not then set a watch on
80  the page. */
82 
83  /** Like Page_fetch::NORMAL, but do not mind if the file page has been
84  freed. */
86 };
87 /** @} */
88 
89 /** @name Modes for buf_page_get_known_nowait */
90 
91 /** @{ */
92 enum class Cache_hint {
93  /** Move the block to the start of the LRU list if there is a danger that the
94  block would drift out of the buffer pool*/
95  MAKE_YOUNG = 51,
96 
97  /** Preserve the current LRU position of the block. */
98  KEEP_OLD = 52
99 };
100 
101 /** @} */
102 
103 /** Number of bits to representing a buffer pool ID */
104 constexpr ulint MAX_BUFFER_POOLS_BITS = 6;
105 
106 /** The maximum number of buffer pools that can be defined */
107 constexpr ulint MAX_BUFFER_POOLS = (1 << MAX_BUFFER_POOLS_BITS);
108 
109 /** Maximum number of concurrent buffer pool watches */
110 #define BUF_POOL_WATCH_SIZE (srv_n_purge_threads + 1)
111 
112 /** The maximum number of page_hash locks */
113 constexpr ulint MAX_PAGE_HASH_LOCKS = 1024;
114 
115 /** The buffer pools of the database */
116 extern buf_pool_t *buf_pool_ptr;
117 
118 #ifdef UNIV_HOTBACKUP
119 /** first block, for --apply-log */
120 extern buf_block_t *back_block1;
121 /** second block, for page reorganize */
122 extern buf_block_t *back_block2;
123 #endif /* UNIV_HOTBACKUP */
124 
125 /** @brief States of a control block
126 @see buf_page_t
127 
128 The enumeration values must be 0..7. */
129 enum buf_page_state : uint8_t {
130  /** A sentinel for the buffer pool watch, element of buf_pool->watch[] */
132  /** Contains a clean compressed page */
134  /** Contains a compressed page that is in the buf_pool->flush_list */
136 
137  /** Is in the free list; must be after the BUF_BLOCK_ZIP_ constants for
138  compressed-only pages @see buf_block_state_valid() */
140 
141  /** When buf_LRU_get_free_block returns a block, it is in this state */
143 
144  /** Contains a buffered file page */
146 
147  /** Contains some main memory object */
149 
150  /** Hash index should be removed before putting to the free list */
152 };
153 
154 /** This structure defines information we will fetch from each buffer pool. It
155 will be used to print table IO stats */
157  /* General buffer pool info */
158  ulint pool_unique_id; /*!< Buffer Pool ID */
159  ulint pool_size; /*!< Buffer Pool size in pages */
160  ulint lru_len; /*!< Length of buf_pool->LRU */
161  ulint old_lru_len; /*!< buf_pool->LRU_old_len */
162  ulint free_list_len; /*!< Length of buf_pool->free list */
163  ulint flush_list_len; /*!< Length of buf_pool->flush_list */
164  ulint n_pend_unzip; /*!< buf_pool->n_pend_unzip, pages
165  pending decompress */
166  ulint n_pend_reads; /*!< buf_pool->n_pend_reads, pages
167  pending read */
168  ulint n_pending_flush_lru; /*!< Pages pending flush in LRU */
169  ulint n_pending_flush_single_page; /*!< Pages pending to be
170  flushed as part of single page
171  flushes issued by various user
172  threads */
173  ulint n_pending_flush_list; /*!< Pages pending flush in FLUSH
174  LIST */
175  ulint n_pages_made_young; /*!< number of pages made young */
176  ulint n_pages_not_made_young; /*!< number of pages not made young */
177  ulint n_pages_read; /*!< buf_pool->n_pages_read */
178  ulint n_pages_created; /*!< buf_pool->n_pages_created */
179  ulint n_pages_written; /*!< buf_pool->n_pages_written */
180  ulint n_page_gets; /*!< buf_pool->n_page_gets */
181  ulint n_ra_pages_read_rnd; /*!< buf_pool->n_ra_pages_read_rnd,
182  number of pages readahead */
183  ulint n_ra_pages_read; /*!< buf_pool->n_ra_pages_read, number
184  of pages readahead */
185  ulint n_ra_pages_evicted; /*!< buf_pool->n_ra_pages_evicted,
186  number of readahead pages evicted
187  without access */
188  ulint n_page_get_delta; /*!< num of buffer pool page gets since
189  last printout */
190 
191  /* Buffer pool access stats */
192  double page_made_young_rate; /*!< page made young rate in pages
193  per second */
194  double page_not_made_young_rate; /*!< page not made young rate
195  in pages per second */
196  double pages_read_rate; /*!< num of pages read per second */
197  double pages_created_rate; /*!< num of pages create per second */
198  double pages_written_rate; /*!< num of pages written per second */
199  ulint page_read_delta; /*!< num of pages read since last
200  printout */
201  ulint young_making_delta; /*!< num of pages made young since
202  last printout */
203  ulint not_young_making_delta; /*!< num of pages not make young since
204  last printout */
205 
206  /* Statistics about read ahead algorithm. */
207  double pages_readahead_rnd_rate; /*!< random readahead rate in pages per
208  second */
209  double pages_readahead_rate; /*!< readahead rate in pages per
210  second */
211  double pages_evicted_rate; /*!< rate of readahead page evicted
212  without access, in pages per second */
213 
214  /* Stats about LRU eviction */
215  ulint unzip_lru_len; /*!< length of buf_pool->unzip_LRU
216  list */
217  /* Counters for LRU policy */
218  ulint io_sum; /*!< buf_LRU_stat_sum.io */
219  ulint io_cur; /*!< buf_LRU_stat_cur.io, num of IO
220  for current interval */
221  ulint unzip_sum; /*!< buf_LRU_stat_sum.unzip */
222  ulint unzip_cur; /*!< buf_LRU_stat_cur.unzip, num
223  pages decompressed in current
224  interval */
225 };
226 
227 /** The occupied bytes of lists in all buffer pools */
229  ulint LRU_bytes; /*!< LRU size in bytes */
230  ulint unzip_LRU_bytes; /*!< unzip_LRU size in bytes */
231  ulint flush_list_bytes; /*!< flush_list size in bytes */
232 };
233 
234 #ifndef UNIV_HOTBACKUP
235 /** Creates the buffer pool.
236 @param[in] total_size Size of the total pool in bytes.
237 @param[in] n_instances Number of buffer pool instances to create.
238 @return DB_SUCCESS if success, DB_ERROR if not enough memory or error */
239 dberr_t buf_pool_init(ulint total_size, ulint n_instances);
240 
241 /** Frees the buffer pool at shutdown. This must not be invoked before
242  freeing all mutexes. */
243 void buf_pool_free_all();
244 
245 /** Determines if a block is intended to be withdrawn. The caller must ensure
246 that there was a sufficient memory barrier to read curr_size and old_size.
247 @param[in] buf_pool buffer pool instance
248 @param[in] block pointer to control block
249 @retval true if will be withdrawn */
250 bool buf_block_will_withdrawn(buf_pool_t *buf_pool, const buf_block_t *block);
251 
252 /** Determines if a frame is intended to be withdrawn. The caller must ensure
253 that there was a sufficient memory barrier to read curr_size and old_size.
254 @param[in] buf_pool buffer pool instance
255 @param[in] ptr pointer to a frame
256 @retval true if will be withdrawn */
257 bool buf_frame_will_withdrawn(buf_pool_t *buf_pool, const byte *ptr);
258 
259 /** This is the thread for resizing buffer pool. It waits for an event and
260 when waked up either performs a resizing and sleeps again. */
261 void buf_resize_thread();
262 
263 /** Checks if innobase_should_madvise_buf_pool() value has changed since we've
264 last check and if so, then updates buf_pool_should_madvise and calls madvise
265 for all chunks in all srv_buf_pool_instances.
266 @see buf_pool_should_madvise comment for a longer explanation. */
268 
269 /** Clears the adaptive hash index on all pages in the buffer pool. */
270 void buf_pool_clear_hash_index(void);
271 
272 /** Gets the current size of buffer buf_pool in bytes.
273  @return size in bytes */
274 UNIV_INLINE
276 /** Gets the current size of buffer buf_pool in frames.
277  @return size in pages */
278 UNIV_INLINE
280 #endif /* !UNIV_HOTBACKUP */
281 
282 /** Gets the smallest oldest_modification lsn among all of the earliest
283 added pages in flush lists. In other words - takes the last dirty page
284 from each flush list, and calculates minimum oldest_modification among
285 all of them. Does not acquire global lock for the whole process, so the
286 result might come from inconsistent view on flush lists.
287 
288 @note Note that because of the relaxed order in each flush list, this
289 functions no longer returns the smallest oldest_modification among all
290 of the dirty pages. If you wanted to have a safe lsn, which is smaller
291 than every oldest_modification, you would need to use another function:
292  buf_pool_get_oldest_modification_lwm().
293 
294 Returns zero if there were no dirty pages (flush lists were empty).
295 
296 @return minimum oldest_modification of last pages from flush lists,
297  zero if flush lists were empty */
299 
300 /** Gets a safe low watermark for oldest_modification. It's guaranteed
301 that there were no dirty pages with smaller oldest_modification in the
302 whole flush lists.
303 
304 Returns zero if flush lists were empty, be careful in such case, because
305 taking the newest lsn is probably not a good idea. If you wanted to rely
306 on some lsn in such case, you would need to follow pattern:
307 
308  dpa_lsn = log_buffer_dirty_pages_added_up_to_lsn(*log_sys);
309 
310  lwm_lsn = buf_pool_get_oldest_modification_lwm();
311 
312  if (lwm_lsn == 0) lwm_lsn = dpa_lsn;
313 
314 The order is important to avoid race conditions.
315 
316 @remarks
317 It's guaranteed that the returned value will not be smaller than the
318 last checkpoint lsn. It's not guaranteed that the returned value is
319 the maximum possible. It's just the best effort for the low cost.
320 It basically takes result of buf_pool_get_oldest_modification_approx()
321 and subtracts maximum possible lag introduced by relaxed order in
322 flush lists (srv_log_recent_closed_size).
323 
324 @return safe low watermark for oldest_modification of dirty pages,
325  or zero if flush lists were empty; if non-zero, it is then
326  guaranteed not to be at block boundary (and it points to lsn
327  inside data fragment of block) */
329 
330 #ifndef UNIV_HOTBACKUP
331 
332 /** Allocates a buf_page_t descriptor. This function must succeed. In case
333  of failure we assert in this function. */
334 UNIV_INLINE
336 
337 /** Free a buf_page_t descriptor.
338 @param[in] bpage bpage descriptor to free */
340 
341 /** Allocates a buffer block.
342  @return own: the allocated block, in state BUF_BLOCK_MEMORY */
344  buf_pool_t *buf_pool); /*!< in: buffer pool instance,
345  or NULL for round-robin selection
346  of the buffer pool */
347 /** Frees a buffer block which does not contain a file page. */
348 UNIV_INLINE
349 void buf_block_free(buf_block_t *block); /*!< in, own: block to be freed */
350 #endif /* !UNIV_HOTBACKUP */
351 
352 /** Copies contents of a buffer frame to a given buffer.
353 @param[in] buf buffer to copy to
354 @param[in] frame buffer frame
355 @return buf */
356 UNIV_INLINE
357 byte *buf_frame_copy(byte *buf, const buf_frame_t *frame);
358 
359 #ifndef UNIV_HOTBACKUP
360 /** NOTE! The following macros should be used instead of buf_page_get_gen,
361  to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
362  in LA! */
363 #define buf_page_get(ID, SIZE, LA, MTR) \
364  buf_page_get_gen(ID, SIZE, LA, NULL, Page_fetch::NORMAL, __FILE__, __LINE__, \
365  MTR)
366 /** Use these macros to bufferfix a page with no latching. Remember not to
367  read the contents of the page unless you know it is safe. Do not modify
368  the contents of the page! We have separated this case, because it is
369  error-prone programming not to set a latch, and it should be used
370  with care. */
371 #define buf_page_get_with_no_latch(ID, SIZE, MTR) \
372  buf_page_get_gen(ID, SIZE, RW_NO_LATCH, NULL, Page_fetch::NO_LATCH, \
373  __FILE__, __LINE__, MTR)
374 
375 /** This is the general function used to get optimistic access to a database
376 page.
377 @param[in] rw_latch RW_S_LATCH, RW_X_LATCH
378 @param[in,out] block Guessed block
379 @param[in] modify_clock Modify clock value
380 @param[in] fetch_mode Fetch mode
381 @param[in] file File name
382 @param[in] line Line where called
383 @param[in,out] mtr Mini-transaction
384 @return true if success */
385 bool buf_page_optimistic_get(ulint rw_latch, buf_block_t *block,
386  uint64_t modify_clock, Page_fetch fetch_mode,
387  const char *file, ulint line, mtr_t *mtr);
388 
389 /** This is used to get access to a known database page, when no waiting can be
390 done.
391 @param[in] rw_latch RW_S_LATCH or RW_X_LATCH.
392 @param[in] block The known page.
393 @param[in] hint Cache_hint::MAKE_YOUNG or Cache_hint::KEEP_OLD
394 @param[in] file File name from where it was called.
395 @param[in] line Line from where it was called.
396 @param[in,out] mtr Mini-transaction covering the fetch
397 @return true if success */
398 bool buf_page_get_known_nowait(ulint rw_latch, buf_block_t *block,
399  Cache_hint hint, const char *file, ulint line,
400  mtr_t *mtr);
401 
402 /** Given a tablespace id and page number tries to get that page. If the
403 page is not in the buffer pool it is not loaded and NULL is returned.
404 Suitable for using when holding the lock_sys latches (as it avoids deadlock).
405 @param[in] page_id page Id
406 @param[in] file File name
407 @param[in] line Line where called
408 @param[in] mtr Mini-transaction
409 @return pointer to a page or NULL */
410 const buf_block_t *buf_page_try_get_func(const page_id_t &page_id,
411  const char *file, ulint line,
412  mtr_t *mtr);
413 
414 /** Given a tablespace id and page number tries to get that page. If the
415 page is not in the buffer pool it is not loaded and NULL is returned.
416 Suitable for using when holding the lock_sys latches (as it avoids deadlock).
417 @param[in] page_id Page identifier
418 @param[in] mtr Mini-transaction
419 @return the page if in buffer pool, NULL if not */
420 #define buf_page_try_get(page_id, mtr) \
421  buf_page_try_get_func((page_id), __FILE__, __LINE__, mtr);
422 
423 /** Get read access to a compressed page (usually of type
424 FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
425 The page must be released with buf_page_release_zip().
426 NOTE: the page is not protected by any latch. Mutual exclusion has to
427 be implemented at a higher level. In other words, all possible
428 accesses to a given page through this function must be protected by
429 the same set of mutexes or latches.
430 @param[in] page_id page id
431 @param[in] page_size page size
432 @return pointer to the block */
433 buf_page_t *buf_page_get_zip(const page_id_t &page_id,
434  const page_size_t &page_size);
435 
436 /** This is the general function used to get access to a database page.
437 @param[in] page_id Page id
438 @param[in] page_size Page size
439 @param[in] rw_latch RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH
440 @param[in] guess Guessed block or NULL
441 @param[in] mode Fetch mode.
442 @param[in] file File name
443 @param[in] line Line where called
444 @param[in] mtr Mini-transaction
445 @param[in] dirty_with_no_latch Mark page as dirty even if page is being
446  pinned without any latch
447 @return pointer to the block or NULL */
448 buf_block_t *buf_page_get_gen(const page_id_t &page_id,
449  const page_size_t &page_size, ulint rw_latch,
450  buf_block_t *guess, Page_fetch mode,
451  const char *file, ulint line, mtr_t *mtr,
452  bool dirty_with_no_latch = false);
453 
454 /** Initializes a page to the buffer buf_pool. The page is usually not read
455 from a file even if it cannot be found in the buffer buf_pool. This is one
456 of the functions which perform to a block a state transition NOT_USED =>
457 FILE_PAGE (the other is buf_page_get_gen). The page is latched by passed mtr.
458 @param[in] page_id Page id
459 @param[in] page_size Page size
460 @param[in] rw_latch RW_SX_LATCH, RW_X_LATCH
461 @param[in] mtr Mini-transaction
462 @return pointer to the block, page bufferfixed */
463 buf_block_t *buf_page_create(const page_id_t &page_id,
464  const page_size_t &page_size,
465  rw_lock_type_t rw_latch, mtr_t *mtr);
466 
467 #else /* !UNIV_HOTBACKUP */
468 
469 /** Inits a page to the buffer buf_pool, for use in mysqlbackup --restore.
470 @param[in] page_id page id
471 @param[in] page_size page size
472 @param[in,out] block block to init */
473 void meb_page_init(const page_id_t &page_id, const page_size_t &page_size,
474  buf_block_t *block);
475 #endif /* !UNIV_HOTBACKUP */
476 
477 #ifndef UNIV_HOTBACKUP
478 /** Releases a compressed-only page acquired with buf_page_get_zip(). */
479 UNIV_INLINE
480 void buf_page_release_zip(buf_page_t *bpage); /*!< in: buffer block */
481 
482 /** Releases a latch, if specified.
483 @param[in] block buffer block
484 @param[in] rw_latch RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
485 UNIV_INLINE
486 void buf_page_release_latch(buf_block_t *block, ulint rw_latch);
487 
488 /** Moves a page to the start of the buffer pool LRU list. This high-level
489 function can be used to prevent an important page from slipping out of
490 the buffer pool.
491 @param[in,out] bpage buffer block of a file page */
492 void buf_page_make_young(buf_page_t *bpage);
493 
494 /** Moved a page to the end of the buffer pool LRU list so that it can be
495 flushed out at the earliest.
496 @param[in] bpage buffer block of a file page */
497 void buf_page_make_old(buf_page_t *bpage);
498 
499 /** Returns TRUE if the page can be found in the buffer pool hash table.
500 NOTE that it is possible that the page is not yet read from disk,
501 though.
502 @param[in] page_id page id
503 @return true if found in the page hash table */
504 UNIV_INLINE
505 ibool buf_page_peek(const page_id_t &page_id);
506 
507 #ifdef UNIV_DEBUG
508 
509 /** Sets file_page_was_freed TRUE if the page is found in the buffer pool.
510 This function should be called when we free a file page and want the
511 debug version to check that it is not accessed any more unless
512 reallocated.
513 @param[in] page_id page id
514 @return control block if found in page hash table, otherwise NULL */
516 
517 /** Sets file_page_was_freed FALSE if the page is found in the buffer pool.
518 This function should be called when we free a file page and want the
519 debug version to check that it is not accessed any more unless
520 reallocated.
521 @param[in] page_id page id
522 @return control block if found in page hash table, otherwise NULL */
524 
525 #endif /* UNIV_DEBUG */
526 /** Reads the freed_page_clock of a buffer block.
527  @return freed_page_clock */
528 UNIV_INLINE
529 ulint buf_page_get_freed_page_clock(const buf_page_t *bpage) /*!< in: block */
530  MY_ATTRIBUTE((warn_unused_result));
531 /** Reads the freed_page_clock of a buffer block.
532  @return freed_page_clock */
533 UNIV_INLINE
534 ulint buf_block_get_freed_page_clock(const buf_block_t *block) /*!< in: block */
535  MY_ATTRIBUTE((warn_unused_result));
536 
537 /** Tells, for heuristics, if a block is still close enough to the MRU end of
538 the LRU list meaning that it is not in danger of getting evicted and also
539 implying that it has been accessed recently.
540 The page must be either buffer-fixed, either its page hash must be locked.
541 @param[in] bpage block
542 @return true if block is close to MRU end of LRU */
543 UNIV_INLINE
544 ibool buf_page_peek_if_young(const buf_page_t *bpage);
545 
546 /** Recommends a move of a block to the start of the LRU list if there is
547 danger of dropping from the buffer pool.
548 NOTE: does not reserve the LRU list mutex.
549 @param[in] bpage block to make younger
550 @return true if should be made younger */
551 UNIV_INLINE
553 
554 /** Gets the youngest modification log sequence number for a frame.
555  Returns zero if not file page or no modification occurred yet.
556  @return newest modification to page */
557 UNIV_INLINE
559  const buf_page_t *bpage); /*!< in: block containing the
560  page frame */
561 
562 /** Increment the modify clock.
563 The caller must
564 (1) own the buf_pool->mutex and block bufferfix count has to be zero,
565 (2) own X or SX latch on the block->lock, or
566 (3) operate on a thread-private temporary table
567 @param[in,out] block buffer block */
568 UNIV_INLINE
570 
571 /** Read the modify clock.
572 @param[in] block buffer block
573 @return modify_clock value */
574 UNIV_INLINE
576 
577 /** Increments the bufferfix count. */
578 #ifdef UNIV_DEBUG
579 /**
580 @param[in] file file name
581 @param[in] line line */
582 #endif /* UNIV_DEBUG */
583 /**
584 @param[in,out] block block to bufferfix */
585 UNIV_INLINE
587 #ifdef UNIV_DEBUG
588  const char *file, ulint line,
589 #endif /* UNIV_DEBUG */
590  buf_block_t *block);
591 
592 /** Increments the bufferfix count.
593 @param[in,out] bpage block to bufferfix
594 @return the count */
595 UNIV_INLINE
596 ulint buf_block_fix(buf_page_t *bpage);
597 
598 /** Increments the bufferfix count.
599 @param[in,out] block block to bufferfix
600 @return the count */
601 UNIV_INLINE
603 
604 /** Decrements the bufferfix count.
605 @param[in,out] bpage block to bufferunfix
606 @return the remaining buffer-fix count */
607 UNIV_INLINE
609 #endif /* !UNIV_HOTBACKUP */
610 /** Decrements the bufferfix count.
611 @param[in,out] block block to bufferunfix
612 @return the remaining buffer-fix count */
613 UNIV_INLINE
615 
616 #ifndef UNIV_HOTBACKUP
617 /** Unfixes the page, unlatches the page,
618 removes it from page_hash and removes it from LRU.
619 @param[in,out] bpage pointer to the block */
621 
622 #ifdef UNIV_DEBUG
623 /** Increments the bufferfix count.
624 @param[in,out] b block to bufferfix
625 @param[in] f file name where requested
626 @param[in] l line number where requested */
627 #define buf_block_buf_fix_inc(b, f, l) buf_block_buf_fix_inc_func(f, l, b)
628 #else /* UNIV_DEBUG */
629 /** Increments the bufferfix count.
630 @param[in,out] b block to bufferfix
631 @param[in] f file name where requested
632 @param[in] l line number where requested */
633 #define buf_block_buf_fix_inc(b, f, l) buf_block_buf_fix_inc_func(b)
634 #endif /* UNIV_DEBUG */
635 #else /* !UNIV_HOTBACKUP */
636 #define buf_block_modify_clock_inc(block) ((void)0)
637 #endif /* !UNIV_HOTBACKUP */
638 
639 #ifndef UNIV_HOTBACKUP
640 
641 /** Gets the space id, page offset, and byte offset within page of a pointer
642 pointing to a buffer frame containing a file page.
643 @param[in] ptr pointer to a buffer frame
644 @param[out] space space id
645 @param[out] addr page offset and byte offset */
646 UNIV_INLINE
647 void buf_ptr_get_fsp_addr(const void *ptr, space_id_t *space, fil_addr_t *addr);
648 
649 /** Gets the hash value of a block. This can be used in searches in the
650  lock hash table.
651  @return lock hash value */
652 UNIV_INLINE
653 ulint buf_block_get_lock_hash_val(const buf_block_t *block) /*!< in: block */
654  MY_ATTRIBUTE((warn_unused_result));
655 #ifdef UNIV_DEBUG
656 /** Finds a block in the buffer pool that points to a
657 given compressed page. Used only to confirm that buffer pool does not contain a
658 given pointer, thus protected by zip_free_mutex.
659 @param[in] buf_pool buffer pool instance
660 @param[in] data pointer to compressed page
661 @return buffer block pointing to the compressed page, or NULL */
662 buf_block_t *buf_pool_contains_zip(buf_pool_t *buf_pool, const void *data);
663 #endif /* UNIV_DEBUG */
664 
665 /***********************************************************************
666 FIXME_FTS: Gets the frame the pointer is pointing to. */
667 UNIV_INLINE
669  /* out: pointer to frame */
670  byte *ptr); /* in: pointer to a frame */
671 
672 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
673 /** Validates the buffer pool data structure.
674  @return true */
675 ibool buf_validate(void);
676 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
677 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
678 /** Prints info of the buffer pool data structure. */
679 void buf_print(void);
680 #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
681 #endif /* !UNIV_HOTBACKUP */
683  /** Do not crash at the end of buf_page_print(). */
685  /** Do not print the full page dump. */
687 };
688 
689 /** Prints a page to stderr.
690 @param[in] read_buf a database page
691 @param[in] page_size page size
692 @param[in] flags 0 or BUF_PAGE_PRINT_NO_CRASH or
693 BUF_PAGE_PRINT_NO_FULL */
694 void buf_page_print(const byte *read_buf, const page_size_t &page_size,
695  ulint flags);
696 
697 /** Decompress a block.
698  @return true if successful */
699 ibool buf_zip_decompress(buf_block_t *block, /*!< in/out: block */
700  ibool check); /*!< in: TRUE=verify the page checksum */
701 #ifndef UNIV_HOTBACKUP
702 #ifdef UNIV_DEBUG
703 /** Returns the number of latched pages in the buffer pool.
704  @return number of latched pages */
705 ulint buf_get_latched_pages_number(void);
706 #endif /* UNIV_DEBUG */
707 /** Returns the number of pending buf pool read ios.
708  @return number of pending read I/O operations */
709 ulint buf_get_n_pending_read_ios(void);
710 /** Prints info of the buffer i/o. */
711 void buf_print_io(FILE *file); /*!< in: file where to print */
712 /** Collect buffer pool stats information for a buffer pool. Also
713  record aggregated stats if there are more than one buffer pool
714  in the server */
716  buf_pool_t *buf_pool, /*!< in: buffer pool */
717  ulint pool_id, /*!< in: buffer pool ID */
718  buf_pool_info_t *all_pool_info); /*!< in/out: buffer pool info
719  to fill */
720 /** Return the ratio in percents of modified pages in the buffer pool /
721 database pages in the buffer pool.
722 @return modified page percentage ratio */
723 double buf_get_modified_ratio_pct(void);
724 /** Refresh the statistics used to print per-second averages. */
726 
727 /** Assert that all file pages in the buffer are in a replaceable state. */
728 void buf_must_be_all_freed(void);
729 
730 /** Checks that there currently are no pending i/o-operations for the buffer
731 pool.
732 @return number of pending i/o */
733 ulint buf_pool_check_no_pending_io(void);
734 
735 /** Invalidates the file pages in the buffer pool when an archive recovery is
736  completed. All the file pages buffered must be in a replaceable state when
737  this function is called: not latched and not modified. */
738 void buf_pool_invalidate(void);
739 #endif /* !UNIV_HOTBACKUP */
740 
741 /*========================================================================
742 --------------------------- LOWER LEVEL ROUTINES -------------------------
743 =========================================================================*/
744 
745 #ifdef UNIV_DEBUG
746 /** Adds latch level info for the rw-lock protecting the buffer frame. This
747 should be called in the debug version after a successful latching of a page if
748 we know the latching order level of the acquired latch.
749 @param[in] block buffer page where we have acquired latch
750 @param[in] level latching order level */
751 UNIV_INLINE
753 #else /* UNIV_DEBUG */
754 #define buf_block_dbg_add_level(block, level) /* nothing */
755 #endif /* UNIV_DEBUG */
756 
757 /** Gets the state of a block.
758  @return state */
759 UNIV_INLINE
761  const buf_page_t *bpage); /*!< in: pointer to the control block */
762 /** Gets the state of a block.
763  @return state */
764 UNIV_INLINE
766  const buf_block_t *block) /*!< in: pointer to the control block */
767  MY_ATTRIBUTE((warn_unused_result));
768 
769 /** Sets the state of a block.
770 @param[in,out] bpage pointer to control block
771 @param[in] state state */
772 UNIV_INLINE
774 
775 /** Sets the state of a block.
776 @param[in,out] block pointer to control block
777 @param[in] state state */
778 UNIV_INLINE
780 
781 /** Determines if a block is mapped to a tablespace.
782  @return true if mapped */
783 UNIV_INLINE
785  const buf_page_t *bpage) /*!< in: pointer to control block */
786  MY_ATTRIBUTE((warn_unused_result));
787 #ifndef UNIV_HOTBACKUP
788 /** Determines if a block should be on unzip_LRU list.
789  @return true if block belongs to unzip_LRU */
790 UNIV_INLINE
792  const buf_page_t *bpage) /*!< in: pointer to control block */
793  MY_ATTRIBUTE((warn_unused_result));
794 
795 /** Gets the mutex of a block.
796  @return pointer to mutex protecting bpage */
797 UNIV_INLINE
799  const buf_page_t *bpage) /*!< in: pointer to control block */
800  MY_ATTRIBUTE((warn_unused_result));
801 
802 /** Get the flush type of a page.
803  @return flush type */
804 UNIV_INLINE
806  const buf_page_t *bpage) /*!< in: buffer page */
807  MY_ATTRIBUTE((warn_unused_result));
808 
809 /** Set the flush type of a page.
810 @param[in] bpage buffer page
811 @param[in] flush_type flush type */
812 UNIV_INLINE
814 
815 /** Map a block to a file page.
816 @param[in,out] block pointer to control block
817 @param[in] page_id page id */
818 UNIV_INLINE
819 void buf_block_set_file_page(buf_block_t *block, const page_id_t &page_id);
820 
821 /** Gets the io_fix state of a block.
822  @return io_fix state */
823 UNIV_INLINE
825  const buf_page_t *bpage) /*!< in: pointer to the control block */
826  MY_ATTRIBUTE((warn_unused_result));
827 /** Gets the io_fix state of a block.
828  @return io_fix state */
829 UNIV_INLINE
831  const buf_block_t *block) /*!< in: pointer to the control block */
832  MY_ATTRIBUTE((warn_unused_result));
833 
834 /** Sets the io_fix state of a block.
835 @param[in,out] bpage control block
836 @param[in] io_fix io_fix state */
837 UNIV_INLINE
838 void buf_page_set_io_fix(buf_page_t *bpage, enum buf_io_fix io_fix);
839 
840 /** Sets the io_fix state of a block.
841 @param[in,out] block control block
842 @param[in] io_fix io_fix state */
843 UNIV_INLINE
844 void buf_block_set_io_fix(buf_block_t *block, enum buf_io_fix io_fix);
845 
846 /** Makes a block sticky. A sticky block implies that even after we release
847 the buf_pool->LRU_list_mutex and the block->mutex:
848 * it cannot be removed from the flush_list
849 * the block descriptor cannot be relocated
850 * it cannot be removed from the LRU list
851 Note that:
852 * the block can still change its position in the LRU list
853 * the next and previous pointers can change.
854 @param[in,out] bpage control block */
855 UNIV_INLINE
857 
858 /** Removes stickiness of a block. */
859 UNIV_INLINE
860 void buf_page_unset_sticky(buf_page_t *bpage); /*!< in/out: control block */
861 /** Determine if a buffer block can be relocated in memory. The block
862  can be dirty, but it must not be I/O-fixed or bufferfixed. */
863 UNIV_INLINE
865  const buf_page_t *bpage) /*!< control block being relocated */
866  MY_ATTRIBUTE((warn_unused_result));
867 
868 /** Determine if a block has been flagged old.
869 @param[in] bpage control block
870 @return true if old */
871 UNIV_INLINE
872 ibool buf_page_is_old(const buf_page_t *bpage)
873  MY_ATTRIBUTE((warn_unused_result));
874 
875 /** Flag a block old.
876 @param[in,out] bpage control block
877 @param[in] old old */
878 UNIV_INLINE
879 void buf_page_set_old(buf_page_t *bpage, ibool old);
880 
881 /** Determine the time of first access of a block in the buffer pool.
882  @return ut_time_monotonic_ms() at the time of first access, 0 if not accessed
883  */
884 UNIV_INLINE
885 unsigned buf_page_is_accessed(const buf_page_t *bpage) /*!< in: control block */
886  MY_ATTRIBUTE((warn_unused_result));
887 /** Flag a block accessed. */
888 UNIV_INLINE
889 void buf_page_set_accessed(buf_page_t *bpage); /*!< in/out: control block */
890 
891 /** Gets the buf_block_t handle of a buffered file block if an uncompressed
892 page frame exists, or NULL. page frame exists, or NULL. The caller must hold
893 either the appropriate hash lock in any mode, either the LRU list mutex. Note:
894 even though bpage is not declared a const we don't update its value. It is safe
895 to make this pure.
896 @param[in] bpage control block, or NULL
897 @return control block, or NULL */
898 UNIV_INLINE
900  MY_ATTRIBUTE((warn_unused_result));
901 #ifdef UNIV_DEBUG
902 /** Gets a pointer to the memory frame of a block.
903  @return pointer to the frame */
904 UNIV_INLINE
906  const buf_block_t *block) /*!< in: pointer to the control block */
907  MY_ATTRIBUTE((warn_unused_result));
908 #else /* UNIV_DEBUG */
909 #define buf_block_get_frame(block) (block)->frame
910 #endif /* UNIV_DEBUG */
911 #else /* !UNIV_HOTBACKUP */
912 #define buf_block_get_frame(block) (block)->frame
913 #endif /* !UNIV_HOTBACKUP */
914 /** Gets the compressed page descriptor corresponding to an uncompressed page
915  if applicable. */
916 #define buf_block_get_page_zip(block) \
917  ((block)->page.zip.data ? &(block)->page.zip : NULL)
918 
919 /** Get a buffer block from an adaptive hash index pointer.
920 This function does not return if the block is not identified.
921 @param[in] ptr pointer to within a page frame
922 @return pointer to block, never NULL */
923 buf_block_t *buf_block_from_ahi(const byte *ptr);
924 
925 /** Find out if a block pointer points into one of currently used chunks of
926 the buffer pool. This is useful if you stored the pointer some time ago, and
927 want to dereference it now, and are afraid that buffer pool resize could free
928 the memory pointed by it. Thus calling this function requires holding at least
929 one of the latches which prevent freeing memory from buffer pool for the
930 duration of the call and until you pin the block in some other way, as otherwise
931 the result of this function might be obsolete by the time you dereference the
932 block (an s-latch on buf_page_hash_lock_get for any bucket is enough).
933 @param buf_pool The buffer pool instance to search in.
934 @param ptr A pointer which you want to check. This function will not
935  dereference it.
936 @return true iff `block` points inside one of the chunks of the `buf_pool`
937 */
938 bool buf_is_block_in_instance(const buf_pool_t *buf_pool,
939  const buf_block_t *ptr);
940 
941 #ifndef UNIV_HOTBACKUP
942 
943 /** Inits a page for read to the buffer buf_pool. If the page is
944 (1) already in buf_pool, or
945 (2) if we specify to read only ibuf pages and the page is not an ibuf page, or
946 (3) if the space is deleted or being deleted,
947 then this function does nothing.
948 Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
949 on the buffer frame. The io-handler must take care that the flag is cleared
950 and the lock released later.
951 @param[out] err DB_SUCCESS or DB_TABLESPACE_DELETED
952 @param[in] mode BUF_READ_IBUF_PAGES_ONLY, ...
953 @param[in] page_id page id
954 @param[in] page_size page size
955 @param[in] unzip TRUE=request uncompressed page
956 @return pointer to the block or NULL */
958  const page_id_t &page_id,
959  const page_size_t &page_size, ibool unzip);
960 
961 /** Completes an asynchronous read or write request of a file page to or from
962 the buffer pool.
963 @param[in] bpage pointer to the block in question
964 @param[in] evict whether or not to evict the page from LRU list
965 @return true if successful */
966 bool buf_page_io_complete(buf_page_t *bpage, bool evict);
967 
968 /** Free a stale page. Caller must hold the LRU mutex. Upon successful page
969 free the LRU mutex will be released.
970 @param[in,out] buf_pool Buffer pool the page belongs to.
971 @param[in,out] bpage Page to free.
972 @return true if page was freed. */
973 bool buf_page_free_stale(buf_pool_t *buf_pool, buf_page_t *bpage) noexcept;
974 
975 /** Free a stale page. Caller must be holding the hash_lock in S mode if
976 hash_lock parameter is not nullptr. The hash lock will be released upon return
977 always. Caller must hold the LRU mutex if and only if the hash_lock parameter
978 is nullptr. Upon unsuccessful page free the LRU mutex will not be released if
979 hash_lock is nullptr.
980 @param[in,out] buf_pool Buffer pool the page belongs to.
981 @param[in,out] bpage Page to free.
982 @param[in,out] hash_lock Hash lock covering the fetch from the hash table if
983 latched in S mode. nullptr otherwise.
984 @return true if page was freed. */
985 bool buf_page_free_stale(buf_pool_t *buf_pool, buf_page_t *bpage,
986  rw_lock_t *hash_lock) noexcept;
987 
988 /** Free a stale page that is being written. The caller must be within the
989 page's write code path.
990 @param[in,out] bpage Page to free.
991 @param[in] owns_sx_lock SX lock on block->lock is set. */
993  bool owns_sx_lock = false) noexcept;
994 
995 /** Calculates the index of a buffer pool to the buf_pool[] array.
996  @return the position of the buffer pool in buf_pool[] */
997 UNIV_INLINE
998 ulint buf_pool_index(const buf_pool_t *buf_pool) /*!< in: buffer pool */
999  MY_ATTRIBUTE((warn_unused_result));
1000 /** Returns the buffer pool instance given a page instance
1001  @return buf_pool */
1002 UNIV_INLINE
1004  const buf_page_t *bpage); /*!< in: buffer pool page */
1005 /** Returns the buffer pool instance given a block instance
1006  @return buf_pool */
1007 UNIV_INLINE
1008 buf_pool_t *buf_pool_from_block(const buf_block_t *block); /*!< in: block */
1009 
1010 /** Returns the buffer pool instance given a page id.
1011 @param[in] page_id page id
1012 @return buffer pool */
1013 UNIV_INLINE
1015 
1016 /** Returns the buffer pool instance given its array index
1017  @return buffer pool */
1018 UNIV_INLINE
1019 buf_pool_t *buf_pool_from_array(ulint index); /*!< in: array index to get
1020  buffer pool instance from */
1021 
1022 /** Returns the control block of a file page, NULL if not found.
1023 @param[in] buf_pool buffer pool instance
1024 @param[in] page_id page id
1025 @return block, NULL if not found */
1026 UNIV_INLINE
1028  const page_id_t &page_id);
1029 
1030 /** Returns the control block of a file page, NULL if not found.
1031 If the block is found and lock is not NULL then the appropriate
1032 page_hash lock is acquired in the specified lock mode. Otherwise,
1033 mode value is ignored. It is up to the caller to release the
1034 lock. If the block is found and the lock is NULL then the page_hash
1035 lock is released by this function.
1036 @param[in] buf_pool buffer pool instance
1037 @param[in] page_id page id
1038 @param[in,out] lock lock of the page hash acquired if bpage is
1039 found, NULL otherwise. If NULL is passed then the hash_lock is released by
1040 this function.
1041 @param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
1042 lock == NULL
1043 @param[in] watch if true, return watch sentinel also.
1044 @return pointer to the bpage or NULL; if NULL, lock is also NULL or
1045 a watch sentinel. */
1046 UNIV_INLINE
1048  const page_id_t &page_id, rw_lock_t **lock,
1049  ulint lock_mode, bool watch = false);
1050 
1051 /** Returns the control block of a file page, NULL if not found.
1052 If the block is found and lock is not NULL then the appropriate
1053 page_hash lock is acquired in the specified lock mode. Otherwise,
1054 mode value is ignored. It is up to the caller to release the
1055 lock. If the block is found and the lock is NULL then the page_hash
1056 lock is released by this function.
1057 @param[in] buf_pool buffer pool instance
1058 @param[in] page_id page id
1059 @param[in,out] lock lock of the page hash acquired if bpage is
1060 found, NULL otherwise. If NULL is passed then the hash_lock is released by
1061 this function.
1062 @param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
1063 lock == NULL
1064 @return pointer to the block or NULL; if NULL, lock is also NULL. */
1065 UNIV_INLINE
1067  const page_id_t &page_id,
1068  rw_lock_t **lock, ulint lock_mode);
1069 
1070 /* There are four different ways we can try to get a bpage or block
1071 from the page hash:
1072 1) Caller already holds the appropriate page hash lock: in the case call
1073 buf_page_hash_get_low() function.
1074 2) Caller wants to hold page hash lock in x-mode
1075 3) Caller wants to hold page hash lock in s-mode
1076 4) Caller doesn't want to hold page hash lock */
1077 #define buf_page_hash_get_s_locked(b, page_id, l) \
1078  buf_page_hash_get_locked(b, page_id, l, RW_LOCK_S)
1079 #define buf_page_hash_get_x_locked(b, page_id, l) \
1080  buf_page_hash_get_locked(b, page_id, l, RW_LOCK_X)
1081 #define buf_page_hash_get(b, page_id) \
1082  buf_page_hash_get_locked(b, page_id, NULL, 0)
1083 #define buf_page_get_also_watch(b, page_id) \
1084  buf_page_hash_get_locked(b, page_id, NULL, 0, true)
1085 
1086 #define buf_block_hash_get_s_locked(b, page_id, l) \
1087  buf_block_hash_get_locked(b, page_id, l, RW_LOCK_S)
1088 #define buf_block_hash_get_x_locked(b, page_id, l) \
1089  buf_block_hash_get_locked(b, page_id, l, RW_LOCK_X)
1090 #define buf_block_hash_get(b, page_id) \
1091  buf_block_hash_get_locked(b, page_id, NULL, 0)
1092 
1093 /** Gets the current length of the free list of buffer blocks.
1094  @return length of the free list */
1096 
1097 /** Determine if a block is a sentinel for a buffer pool watch.
1098  @return true if a sentinel for a buffer pool watch, false if not */
1100  const buf_pool_t *buf_pool, /*!< buffer pool instance */
1101  const buf_page_t *bpage) /*!< in: block */
1102  MY_ATTRIBUTE((warn_unused_result));
1103 
1104 /** Stop watching if the page has been read in.
1105 buf_pool_watch_set(same_page_id) must have returned NULL before.
1106 @param[in] page_id page id */
1107 void buf_pool_watch_unset(const page_id_t &page_id);
1108 
1109 /** Check if the page has been read in.
1110 This may only be called after buf_pool_watch_set(same_page_id)
1111 has returned NULL and before invoking buf_pool_watch_unset(same_page_id).
1112 @param[in] page_id page id
1113 @return false if the given page was not read in, true if it was */
1114 ibool buf_pool_watch_occurred(const page_id_t &page_id)
1115  MY_ATTRIBUTE((warn_unused_result));
1116 
1117 /** Get total buffer pool statistics.
1118 @param[out] LRU_len Length of all lru lists
1119 @param[out] free_len Length of all free lists
1120 @param[out] flush_list_len Length of all flush lists */
1121 void buf_get_total_list_len(ulint *LRU_len, ulint *free_len,
1122  ulint *flush_list_len);
1123 
1124 /** Get total list size in bytes from all buffer pools. */
1126  buf_pools_list_size_t *buf_pools_list_size); /*!< out: list sizes
1127  in all buffer pools */
1128 /** Get total buffer pool statistics. */
1129 void buf_get_total_stat(
1130  buf_pool_stat_t *tot_stat); /*!< out: buffer pool stats */
1131 
1132 /** Get the nth chunk's buffer block in the specified buffer pool.
1133 @param[in] buf_pool buffer pool instance
1134 @param[in] n nth chunk in the buffer pool
1135 @param[in] chunk_size chunk_size
1136 @return the nth chunk's buffer block. */
1137 UNIV_INLINE
1139  ulint *chunk_size);
1140 
1141 /** Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit,
1142 if needed.
1143 @param[in] size size in bytes
1144 @return aligned size */
1145 UNIV_INLINE
1146 ulint buf_pool_size_align(ulint size);
1147 
1148 /** Adjust the proposed chunk unit size so that it satisfies all invariants
1149 @param[in] size proposed size of buffer pool chunk unit in bytes
1150 @return adjusted size which meets invariants */
1152 
1153 /** Calculate the checksum of a page from compressed table and update the
1154 page.
1155 @param[in,out] page page to update
1156 @param[in] size compressed page size
1157 @param[in] lsn LSN to stamp on the page
1158 @param[in] skip_lsn_check true to skip check for lsn (in DEBUG) */
1160  bool skip_lsn_check);
1161 
1162 #endif /* !UNIV_HOTBACKUP */
1163 
1164 /** Return how many more pages must be added to the withdraw list to reach the
1165 withdraw target of the currently ongoing buffer pool resize.
1166 @param[in] buf_pool buffer pool instance
1167 @return page count to be withdrawn or zero if the target is already achieved or
1168 if the buffer pool is not currently being resized. */
1169 UNIV_INLINE
1171 
1172 /** Gets the io_fix state of a buffer block. Does not assert that the
1173 buf_page_get_mutex() mutex is held, to be used in the cases where it is safe
1174 not to hold it.
1175 @param[in] block pointer to the buffer block
1176 @return page io_fix state */
1177 UNIV_INLINE
1179  MY_ATTRIBUTE((warn_unused_result));
1180 
1181 /** Gets the io_fix state of a buffer page. Does not assert that the
1182 buf_page_get_mutex() mutex is held, to be used in the cases where it is safe
1183 not to hold it.
1184 @param[in] bpage pointer to the buffer page
1185 @return page io_fix state */
1186 UNIV_INLINE
1188  MY_ATTRIBUTE((warn_unused_result));
1189 
1190 /** The common buffer control block structure
1191 for compressed and uncompressed frames */
1192 
1193 /** Number of bits used for buffer page states. */
1194 #define BUF_PAGE_STATE_BITS 3
1196 class buf_fix_count_atomic_t : public std::atomic<uint32_t> {
1197  public:
1199  : std::atomic<uint32_t>(other.load()) {}
1200 };
1201 
1202 class buf_page_t {
1203  public:
1204  /** Copy constructor.
1205  @param[in] other Instance to copy from. */
1206  buf_page_t(const buf_page_t &other)
1207  : id(other.id),
1208  size(other.size),
1210  io_fix(other.io_fix),
1211  state(other.state),
1212  flush_type(other.flush_type),
1214 #ifndef UNIV_HOTBACKUP
1215  hash(other.hash),
1216 #endif /* !UNIV_HOTBACKUP */
1217  list(other.list),
1220  LRU(other.LRU),
1221  zip(other.zip)
1222 #ifndef UNIV_HOTBACKUP
1223  ,
1225  m_space(other.m_space),
1227  access_time(other.access_time),
1228  m_version(other.m_version),
1229  m_dblwr_id(other.m_dblwr_id),
1230  old(other.old)
1231 #ifdef UNIV_DEBUG
1232  ,
1235  in_free_list(other.in_free_list),
1236  in_LRU_list(other.in_LRU_list),
1237  in_page_hash(other.in_page_hash),
1238  in_zip_hash(other.in_zip_hash)
1239 #endif /* UNIV_DEBUG */
1240 #endif /* !UNIV_HOTBACKUP */
1241  {
1242 #ifndef UNIV_HOTBACKUP
1243  m_space->inc_ref();
1244 #endif /* !UNIV_HOTBACKUP */
1245  }
1246 
1247 #ifndef UNIV_HOTBACKUP
1248  /** Set the doublewrite buffer ID.
1249  @param[in] batch_id Double write batch ID that flushed the page. */
1250  void set_dblwr_batch_id(uint16_t batch_id) { m_dblwr_id = batch_id; }
1251 
1252  /** @return the double write batch id, or uint16_t max if undefined. */
1253  uint16_t get_dblwr_batch_id() const MY_ATTRIBUTE((warn_unused_result)) {
1254  return (m_dblwr_id);
1255  }
1256 
1257  /** Retrieve the tablespace id.
1258  @return tablespace id */
1259  space_id_t space() const noexcept MY_ATTRIBUTE((warn_unused_result)) {
1260  return id.space();
1261  }
1262 
1263  /** Retrieve the page number.
1264  @return page number */
1265  page_no_t page_no() const noexcept MY_ATTRIBUTE((warn_unused_result)) {
1266  return id.page_no();
1267  }
1268 
1269  /** Checks if this space reference saved during last page ID initialization
1270  was deleted or truncated since.
1271  @return true when space reference stored leads was deleted or truncated and
1272  this page should be discarded. Result is up to date until the fil_shard mutex
1273  is released. */
1274  inline bool is_stale() const {
1275  ut_a(m_space != nullptr);
1276  ut_a(id.space() == m_space->id);
1277  ut_a(m_version <= m_space->get_current_version());
1279  ut_a(!m_space->is_deleted());
1280  return false;
1281  } else {
1282  return true;
1283  }
1284  }
1285 
1286  /** Checks if this space reference saved during last page ID initialization
1287  was deleted or truncated since.
1288  @return true when space reference stored leads was deleted or truncated and
1289  this page should be discarded. When false is returned, the status of stale is
1290  checked to be guaranteed. */
1291  inline bool was_stale() const {
1292  ut_a(m_space != nullptr);
1293  ut_a(id.space() == m_space->id);
1294  /* If the the version is OK, then the space must not be deleted.
1295  However, version is modified before the deletion flag is set, so reading
1296  these values need to be executed in reversed order. The atomic reads
1297  cannot be relaxed for it to work. */
1298  bool was_not_deleted = m_space->was_not_deleted();
1299  if (m_version == m_space->get_recent_version()) {
1300  ut_a(was_not_deleted);
1301  return false;
1302  } else {
1303  return true;
1304  }
1305  }
1306 
1307  /** Retrieve the tablespace object if one was available during page ID
1308  initialization. The returned object is safe to use as long as this buf_page_t
1309  object is not changed. Caller should have a IO fix, buffer fix, mutex or any
1310  other mean to assure the page will not be freed. After that is released the
1311  space object may be freed.
1312  @return tablespace object */
1313  inline fil_space_t *get_space() const { return m_space; }
1314 
1315  /** Sets stored page ID to the new value. Handles space object reference
1316  count.
1317  @param[in] new_page_id new page ID to be set. */
1318  inline void reset_page_id(page_id_t new_page_id) {
1319  if (m_space != nullptr) {
1320  /* If we reach this line through a call chain:
1321  srv_shutdown -> buf_pool_free_all -> buf_pool_free_instance ->
1322  buf_page_free_descriptor, then we are already past the fil system
1323  shutdown, and all fil_space_t objects were already freed. */
1325  m_space->dec_ref();
1326  }
1327  }
1328  id = new_page_id;
1329  space_id_changed();
1330  }
1331 
1332  /** Sets stored value to invalid/empty value. Handles space object reference
1333  count. */
1334  inline void reset_page_id() {
1335  reset_page_id(page_id_t(UINT32_UNDEFINED, UINT32_UNDEFINED));
1336  }
1337 
1338  private:
1339  /** Updates new space reference and acquires "reference count latch" and the
1340  current version of the space object. */
1341  inline void space_id_changed() {
1342  m_space = nullptr;
1343  m_version = 0;
1344  if (id.space() != UINT32_UNDEFINED) {
1345  m_space = fil_space_get(id.space());
1346  if (m_space) {
1347  m_space->inc_ref();
1348  /* We don't have a way to check the MDL locks, which are guarding the
1349  version number, so we don't use get_current_version(). */
1351  }
1352  }
1353  }
1354 
1355  public:
1356  /** @return the flush observer instance. */
1358 
1359  /** Set the flush observer for the page.
1360  @param[in] flush_observer The flush observer to set. */
1361  void set_flush_observer(FlushObserver *flush_observer) noexcept {
1362  /* Don't allow to set flush observer from non-null to null, or from one
1363  observer to another. */
1364  ut_a(m_flush_observer == nullptr || m_flush_observer == flush_observer);
1365  m_flush_observer = flush_observer;
1366  }
1367 
1368  /** Remove the flush observer. */
1369  void reset_flush_observer() noexcept { m_flush_observer = nullptr; }
1370 #endif /* !UNIV_HOTBACKUP */
1371 
1372  /** @return the LSN of the latest modification. */
1373  lsn_t get_newest_lsn() const noexcept { return newest_modification; }
1374 
1375  /** @return the LSN of the first modification since the last time
1376  it was clean. */
1377  lsn_t get_oldest_lsn() const noexcept { return oldest_modification; }
1378 
1379  /** @return true if the page is dirty. */
1380  bool is_dirty() const noexcept { return get_oldest_lsn() > 0; }
1381 
1382  /** Set the latest modification LSN.
1383  @param[in] lsn Latest modification lSN. */
1385 
1386  /** Set the LSN when the page is modified for the first time.
1387  @param[in] lsn First modification LSN. */
1388  void set_oldest_lsn(lsn_t lsn) noexcept;
1389 
1390  /** Set page to clean state. */
1391  void set_clean() noexcept { set_oldest_lsn(0); }
1392 
1393  /** @name General fields
1394  None of these bit-fields must be modified without holding
1395  buf_page_get_mutex() [buf_block_t::mutex or
1396  buf_pool->zip_mutex], since they can be stored in the same
1397  machine word. */
1398  /** @{ */
1399 
1400  /** Page id. */
1402 
1403  /** Page size. */
1405 
1406  /** Count of how many fold this block is currently bufferfixed. */
1408 
1409  /** Type of pending I/O operation. */
1411 
1412  /** Block state. @see buf_page_in_file */
1414 
1415  /** If this block is currently being flushed to disk, this tells
1416  the flush_type. @see buf_flush_t */
1418 
1419  /** Index number of the buffer pool that this block belongs to */
1421 
1422  static_assert(MAX_BUFFER_POOLS <= 64,
1423  "MAX_BUFFER_POOLS > 64; redefine buf_pool_index");
1424 
1425  /** @} */
1426 #ifndef UNIV_HOTBACKUP
1427  /** Node used in chaining to buf_pool->page_hash or buf_pool->zip_hash */
1429 #endif /* !UNIV_HOTBACKUP */
1430 
1431  /** @name Page flushing fields
1432  All these are protected by buf_pool->mutex. */
1433  /** @{ */
1434 
1435  /** Based on state, this is a list node, protected by the corresponding list
1436  mutex, in one of the following lists in buf_pool:
1437 
1438  - BUF_BLOCK_NOT_USED: free, withdraw
1439  - BUF_BLOCK_FILE_PAGE: flush_list
1440  - BUF_BLOCK_ZIP_DIRTY: flush_list
1441  - BUF_BLOCK_ZIP_PAGE: zip_clean
1442 
1443  The node pointers are protected by the corresponding list mutex.
1444 
1445  The contents of the list node is undefined if !in_flush_list &&
1446  state == BUF_BLOCK_FILE_PAGE, or if state is one of
1447  BUF_BLOCK_MEMORY,
1448  BUF_BLOCK_REMOVE_HASH or
1449  BUF_BLOCK_READY_IN_USE. */
1450 
1452 
1453  private:
1454  /** The flush LSN, LSN when this page was written to the redo log. For
1455  non redo logged pages this is set using: buf_flush_borrow_lsn() */
1457 
1458  /** log sequence number of the youngest modification to this block, zero
1459  if not modified. Protected by block mutex */
1461 
1462  public:
1463  /** log sequence number of the START of the log entry written of the oldest
1464  modification to this block which has not yet been flushed on disk; zero if
1465  all modifications are on disk. Writes to this field must be covered by both
1466  block->mutex and buf_pool->flush_list_mutex. Hence reads can happen while
1467  holding any one of the two mutexes */
1468  /** @} */
1469 
1470  /** @name LRU replacement algorithm fields
1471  These fields are protected by both buf_pool->LRU_list_mutex and the
1472  block mutex. */
1473  /** @{ */
1474 
1475  /** node of the LRU list */
1477 
1478  /** compressed page; zip.data (but not the data it points to) is
1479  protected by buf_pool->zip_mutex; state == BUF_BLOCK_ZIP_PAGE and
1480  zip.data == NULL means an active buf_pool->watch */
1482 
1483 #ifndef UNIV_HOTBACKUP
1484  /** Flush observer instance. */
1486 
1487  /** Tablespace instance that this page belongs to. */
1489 
1490  /** The value of buf_pool->freed_page_clock when this block was the last
1491  time put to the head of the LRU list; a thread is allowed to read this
1492  for heuristic purposes without holding any mutex or latch */
1494 
1495  /** @} */
1496  /** Time of first access, or 0 if the block was never accessed in the
1497  buffer pool. Protected by block mutex */
1498  uint32_t access_time;
1499 
1500  /** Version of fil_space_t when the page was updated. It can also be viewed as
1501  the truncation number. */
1502  uint32_t m_version{};
1503 
1504  /** Double write instance ordinal value during writes. This is used
1505  by IO completion (writes) to select the double write instance.*/
1506  uint16_t m_dblwr_id{};
1507 
1508  /** true if the block is in the old blocks in buf_pool->LRU_old */
1509  bool old;
1510 
1511 #ifdef UNIV_DEBUG
1512  /** This is set to TRUE when fsp frees a page in buffer pool;
1513  protected by buf_pool->zip_mutex or buf_block_t::mutex. */
1515 
1516  /** TRUE if in buf_pool->flush_list; when buf_pool->flush_list_mutex
1517  is free, the following should hold:
1518  in_flush_list == (state == BUF_BLOCK_FILE_PAGE ||
1519  state == BUF_BLOCK_ZIP_DIRTY)
1520  Writes to this field must be covered by both buf_pool->flush_list_mutex
1521  and block->mutex. Hence reads can happen while holding any one of the
1522  two mutexes */
1524 
1525  /** true if in buf_pool->free; when buf_pool->free_list_mutex is free, the
1526  following should hold: in_free_list == (state == BUF_BLOCK_NOT_USED) */
1528 
1529  /** true if the page is in the LRU list; used in debugging */
1531 
1532  /** true if in buf_pool->page_hash */
1534 
1535  /** true if in buf_pool->zip_hash */
1537 #endif /* UNIV_DEBUG */
1538 
1539 #endif /* !UNIV_HOTBACKUP */
1540 };
1541 
1542 /** The buffer control block structure */
1543 
1544 struct buf_block_t {
1545  /** @name General fields */
1546  /** @{ */
1547 
1548  /** page information; this must be the first field, so
1549  that buf_pool->page_hash can point to buf_page_t or buf_block_t */
1551 
1552 #ifndef UNIV_HOTBACKUP
1553  /** read-write lock of the buffer frame */
1555 
1556 #endif /* UNIV_HOTBACKUP */
1557 
1558  /** pointer to buffer frame which is of size UNIV_PAGE_SIZE, and aligned
1559  to an address divisible by UNIV_PAGE_SIZE */
1560  byte *frame;
1561 
1562  /** node of the decompressed LRU list; a block is in the unzip_LRU list if
1563  page.state == BUF_BLOCK_FILE_PAGE and page.zip.data != NULL. Protected by
1564  both LRU_list_mutex and the block mutex. */
1566 #ifdef UNIV_DEBUG
1567 
1568  /** TRUE if the page is in the decompressed LRU list; used in debugging */
1570 
1572 #endif /* UNIV_DEBUG */
1573 
1574  /** hashed value of the page address in the record lock hash table;
1575  protected by buf_block_t::lock (or buf_block_t::mutex in buf_page_get_gen(),
1576  buf_page_init_for_read() and buf_page_create()) */
1577  uint32_t lock_hash_val;
1578  /** @} */
1579 
1580  /** @name Hash search fields (unprotected)
1581  NOTE that these fields are NOT protected by any semaphore! */
1582  /** @{ */
1583 
1584  /** Counter which controls building of a new hash index for the page */
1585  uint32_t n_hash_helps;
1586 
1587  /** Recommended prefix length for hash search: number of bytes in an
1588  incomplete last field */
1589  volatile uint32_t n_bytes;
1590 
1591  /** Recommended prefix length for hash search: number of full fields */
1592  volatile uint32_t n_fields;
1593 
1594  /** true or false, depending on whether the leftmost record of several
1595  records with the same prefix should be indexed in the hash index */
1596  volatile bool left_side;
1597  /** @} */
1598 
1599  /** @name Hash search fields
1600  These 5 fields may only be modified when:
1601  we are holding the appropriate x-latch in btr_search_latches[], and
1602  one of the following holds:
1603  (1) the block state is BUF_BLOCK_FILE_PAGE, and
1604  we are holding an s-latch or x-latch on buf_block_t::lock, or
1605  (2) buf_block_t::buf_fix_count == 0, or
1606  (3) the block state is BUF_BLOCK_REMOVE_HASH.
1607 
1608  An exception to this is when we init or create a page
1609  in the buffer pool in buf0buf.cc.
1610 
1611  Another exception for buf_pool_clear_hash_index() is that
1612  assigning block->index = NULL (and block->n_pointers = 0)
1613  is allowed whenever btr_search_own_all(RW_LOCK_X).
1614 
1615  Another exception is that ha_insert_for_fold_func() may
1616  decrement n_pointers without holding the appropriate latch
1617  in btr_search_latches[]. Thus, n_pointers must be
1618  protected by atomic memory access.
1619 
1620  This implies that the fields may be read without race
1621  condition whenever any of the following hold:
1622  - the btr_search_latches[] s-latch or x-latch is being held, or
1623  - the block state is not BUF_BLOCK_FILE_PAGE or BUF_BLOCK_REMOVE_HASH,
1624  and holding some latch prevents the state from changing to that.
1625 
1626  Some use of assert_block_ahi_empty() or assert_block_ahi_valid()
1627  is prone to race conditions while buf_pool_clear_hash_index() is
1628  executing (the adaptive hash index is being disabled). Such use
1629  is explicitly commented. */
1630 
1631  /** @{ */
1632 
1633 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1634  /** used in debugging: the number of pointers in the adaptive hash index
1635  pointing to this frame; protected by atomic memory access or
1636  btr_search_own_all(). */
1637  std::atomic<ulint> n_pointers;
1638 
1639 #define assert_block_ahi_empty(block) ut_a((block)->n_pointers.load() == 0)
1640 #define assert_block_ahi_empty_on_init(block) \
1641  do { \
1642  UNIV_MEM_VALID(&(block)->n_pointers, sizeof(block)->n_pointers); \
1643  assert_block_ahi_empty(block); \
1644  } while (0)
1645 
1646 #define assert_block_ahi_valid(block) \
1647  ut_a((block)->index || (block)->n_pointers.load() == 0)
1648 #else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1649 #define assert_block_ahi_empty(block) /* nothing */
1650 #define assert_block_ahi_empty_on_init(block) /* nothing */
1651 #define assert_block_ahi_valid(block) /* nothing */
1652 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1653 
1654  /** prefix length for hash indexing: number of full fields */
1655  uint16_t curr_n_fields;
1656 
1657  /** number of bytes in hash indexing */
1658  uint16_t curr_n_bytes;
1659 
1660  /** TRUE or FALSE in hash indexing */
1662 
1663  /** true if block has been made dirty without acquiring X/SX latch as the
1664  block belongs to temporary tablespace and block is always accessed by a
1665  single thread. */
1667 
1668  /** Index for which the adaptive hash index has been created, or NULL if
1669  the page does not exist in the index. Note that it does not guarantee that
1670  the index is complete, though: there may have been hash collisions, record
1671  deletions, etc. */
1673 
1674  /** @} */
1675 #ifndef UNIV_HOTBACKUP
1676 #ifdef UNIV_DEBUG
1677  /** @name Debug fields */
1678  /** @{ */
1679  /** In the debug version, each thread which bufferfixes the block acquires
1680  an s-latch here; so we can use the debug utilities in sync0rw */
1682  /** @} */
1683 #endif /* UNIV_DEBUG */
1684 #endif /* !UNIV_HOTBACKUP */
1685 
1686  /** @name Optimistic search field */
1687  /** @{ */
1688 
1689  /** This clock is incremented every time a pointer to a record on the page
1690  may become obsolete; this is used in the optimistic cursor positioning: if
1691  the modify clock has not changed, we know that the pointer is still valid;
1692  this field may be changed if the thread (1) owns the LRU list mutex and the
1693  page is not bufferfixed, or (2) the thread has an x-latch on the block,
1694  or (3) the block must belong to an intrinsic table */
1695  uint64_t modify_clock;
1696 
1697  /** @} */
1698 
1699  /** mutex protecting this block: state (also protected by the buffer
1700  pool mutex), io_fix, buf_fix_count, and accessed; we introduce this
1701  new mutex in InnoDB-5.1 to relieve contention on the buffer pool mutex */
1703 
1704  /** Get the page number and space id of the current buffer block.
1705  @return page number of the current buffer block. */
1706  const page_id_t &get_page_id() const { return page.id; }
1707 
1708  /** Get the page number of the current buffer block.
1709  @return page number of the current buffer block. */
1710  page_no_t get_page_no() const { return (page.id.page_no()); }
1711 
1712  /** Get the next page number of the current buffer block.
1713  @return next page number of the current buffer block. */
1715  return (mach_read_from_4(frame + FIL_PAGE_NEXT));
1716  }
1717 
1718  /** Get the prev page number of the current buffer block.
1719  @return prev page number of the current buffer block. */
1721  return (mach_read_from_4(frame + FIL_PAGE_PREV));
1722  }
1723 
1724  /** Get the page type of the current buffer block.
1725  @return page type of the current buffer block. */
1727  return (mach_read_from_2(frame + FIL_PAGE_TYPE));
1728  }
1729 
1730  /** Get the page type of the current buffer block as string.
1731  @return page type of the current buffer block as string. */
1732  const char *get_page_type_str() const noexcept
1733  MY_ATTRIBUTE((warn_unused_result));
1734 };
1735 
1736 /** Check if a buf_block_t object is in a valid state
1737 @param block buffer block
1738 @return true if valid */
1739 #define buf_block_state_valid(block) \
1740  (buf_block_get_state(block) >= BUF_BLOCK_NOT_USED && \
1741  (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1742 
1743 /** Compute the hash fold value for blocks in buf_pool->zip_hash. */
1744 /** @{ */
1745 #define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint)(ptr) / UNIV_PAGE_SIZE)
1746 #define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1747 #define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t *)(b))
1748 /** @} */
1749 
1750 /** A "Hazard Pointer" class used to iterate over page lists
1751 inside the buffer pool. A hazard pointer is a buf_page_t pointer
1752 which we intend to iterate over next and we want it remain valid
1753 even after we release the buffer pool mutex. */
1755  public:
1756  /** Constructor
1757  @param buf_pool buffer pool instance
1758  @param mutex mutex that is protecting the hp. */
1759  HazardPointer(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1760  : m_buf_pool(buf_pool)
1761 #ifdef UNIV_DEBUG
1762  ,
1763  m_mutex(mutex)
1764 #endif /* UNIV_DEBUG */
1765  ,
1766  m_hp() {
1767  }
1768 
1769  /** Destructor */
1770  virtual ~HazardPointer() {}
1771 
1772  /** Get current value */
1773  buf_page_t *get() const {
1774  ut_ad(mutex_own(m_mutex));
1775  return (m_hp);
1776  }
1777 
1778  /** Set current value
1779  @param bpage buffer block to be set as hp */
1780  void set(buf_page_t *bpage);
1781 
1782  /** Checks if a bpage is the hp
1783  @param bpage buffer block to be compared
1784  @return true if it is hp */
1785  bool is_hp(const buf_page_t *bpage);
1786 
1787  /** Adjust the value of hp. This happens when some
1788  other thread working on the same list attempts to
1789  remove the hp from the list. Must be implemented
1790  by the derived classes.
1791  @param bpage buffer block to be compared */
1792  virtual void adjust(const buf_page_t *bpage) = 0;
1793 
1794  /** Adjust the value of hp for moving. This happens
1795  when some other thread working on the same list
1796  attempts to relocate the hp of the page.
1797  @param bpage buffer block to be compared
1798  @param dpage buffer block to be moved to */
1799  void move(const buf_page_t *bpage, buf_page_t *dpage);
1800 
1801  protected:
1802  /** Disable copying */
1805 
1806  /** Buffer pool instance */
1808 
1809 #ifdef UNIV_DEBUG
1810  /** mutex that protects access to the m_hp. */
1811  const ib_mutex_t *m_mutex;
1812 #endif /* UNIV_DEBUG */
1813 
1814  /** hazard pointer. */
1816 };
1817 
1818 /** Class implementing buf_pool->flush_list hazard pointer */
1819 class FlushHp : public HazardPointer {
1820  public:
1821  /** Constructor
1822  @param buf_pool buffer pool instance
1823  @param mutex mutex that is protecting the hp. */
1824  FlushHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1825  : HazardPointer(buf_pool, mutex) {}
1826 
1827  /** Destructor */
1828  ~FlushHp() override {}
1829 
1830  /** Adjust the value of hp. This happens when some
1831  other thread working on the same list attempts to
1832  remove the hp from the list.
1833  @param bpage buffer block to be compared */
1834  void adjust(const buf_page_t *bpage) override;
1835 };
1836 
1837 /** Class implementing buf_pool->LRU hazard pointer */
1838 class LRUHp : public HazardPointer {
1839  public:
1840  /** Constructor
1841  @param buf_pool buffer pool instance
1842  @param mutex mutex that is protecting the hp. */
1843  LRUHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1844  : HazardPointer(buf_pool, mutex) {}
1845 
1846  /** Destructor */
1847  ~LRUHp() override {}
1848 
1849  /** Adjust the value of hp. This happens when some
1850  other thread working on the same list attempts to
1851  remove the hp from the list.
1852  @param bpage buffer block to be compared */
1853  void adjust(const buf_page_t *bpage) override;
1854 };
1855 
1856 /** Special purpose iterators to be used when scanning the LRU list.
1857 The idea is that when one thread finishes the scan it leaves the
1858 itr in that position and the other thread can start scan from
1859 there */
1860 class LRUItr : public LRUHp {
1861  public:
1862  /** Constructor
1863  @param buf_pool buffer pool instance
1864  @param mutex mutex that is protecting the hp. */
1865  LRUItr(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1866  : LRUHp(buf_pool, mutex) {}
1867 
1868  /** Destructor */
1869  ~LRUItr() override {}
1870 
1871  /** Selects from where to start a scan. If we have scanned
1872  too deep into the LRU list it resets the value to the tail
1873  of the LRU list.
1874  @return buf_page_t from where to start scan. */
1875  buf_page_t *start();
1876 };
1877 
1878 /** Struct that is embedded in the free zip blocks */
1880  union {
1881  ulint size; /*!< size of the block */
1882  byte bytes[FIL_PAGE_DATA];
1883  /*!< stamp[FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID]
1884  == BUF_BUDDY_FREE_STAMP denotes a free
1885  block. If the space_id field of buddy
1886  block != BUF_BUDDY_FREE_STAMP, the block
1887  is not in any zip_free list. If the
1888  space_id is BUF_BUDDY_FREE_STAMP then
1889  stamp[0] will contain the
1890  buddy block size. */
1891  } stamp;
1892 
1893  buf_page_t bpage; /*!< Embedded bpage descriptor */
1895  /*!< Node of zip_free list */
1896 };
1897 
1898 /** @brief The buffer pool statistics structure. */
1901 
1902  /** Number of page gets performed; also successful searches through the
1903  adaptive hash index are counted as page gets; this field is NOT protected
1904  by the buffer pool mutex */
1906 
1907  /** Number of read operations. */
1908  std::atomic<uint64_t> n_pages_read;
1909 
1910  /** Number of write operations. */
1911  std::atomic<uint64_t> n_pages_written;
1912 
1913  /** number of pages created in the pool with no read. */
1914  std::atomic<uint64_t> n_pages_created;
1915 
1916  /** Number of pages read in as part of random read ahead. */
1917  std::atomic<uint64_t> n_ra_pages_read_rnd;
1918 
1919  /** Number of pages read in as part of read ahead. */
1920  std::atomic<uint64_t> n_ra_pages_read;
1921 
1922  /** Number of read ahead pages that are evicted without being accessed.
1923  Protected by LRU_list_mutex. */
1925 
1926  /** Number of pages made young, in calls to buf_LRU_make_block_young().
1927  Protected by LRU_list_mutex. */
1929 
1930  /** Number of pages not made young because the first access was not long
1931  enough ago, in buf_page_peek_if_too_old(). Not protected. */
1933 
1934  /** LRU size in bytes. Protected by LRU_list_mutex. */
1935  uint64_t LRU_bytes;
1936 
1937  /** Flush_list size in bytes. Protected by flush_list_mutex */
1939 
1940  static void copy(buf_pool_stat_t &dst, const buf_pool_stat_t &src) noexcept {
1941  Counter::copy(dst.m_n_page_gets, src.m_n_page_gets);
1942 
1943  dst.n_pages_read.store(src.n_pages_read.load());
1944 
1945  dst.n_pages_written.store(src.n_pages_written.load());
1946 
1947  dst.n_pages_created.store(src.n_pages_created.load());
1948 
1949  dst.n_ra_pages_read_rnd.store(src.n_ra_pages_read_rnd.load());
1950 
1951  dst.n_ra_pages_read.store(src.n_ra_pages_read.load());
1952 
1953  dst.n_ra_pages_evicted = src.n_ra_pages_evicted;
1954 
1955  dst.n_pages_made_young = src.n_pages_made_young;
1956 
1957  dst.n_pages_not_made_young = src.n_pages_not_made_young;
1958 
1959  dst.LRU_bytes = src.LRU_bytes;
1960 
1961  dst.flush_list_bytes = src.flush_list_bytes;
1962  }
1963 
1964  void reset() {
1965  Counter::clear(m_n_page_gets);
1966 
1967  n_pages_read = 0;
1968  n_pages_written = 0;
1969  n_pages_created = 0;
1970  n_ra_pages_read_rnd = 0;
1971  n_ra_pages_read = 0;
1972  n_ra_pages_evicted = 0;
1973  n_pages_made_young = 0;
1974  n_pages_not_made_young = 0;
1975  LRU_bytes = 0;
1976  flush_list_bytes = 0;
1977  }
1978 };
1979 
1980 /** Statistics of buddy blocks of a given size. */
1982  /** Number of blocks allocated from the buddy system. */
1983  std::atomic<ulint> used;
1984  /** Number of blocks relocated by the buddy system.
1985  Protected by buf_pool zip_free_mutex. */
1986  uint64_t relocated;
1987  /** Total duration of block relocations, in microseconds.
1988  Protected by buf_pool zip_free_mutex. */
1989  uint64_t relocated_usec;
1990 
1991  struct snapshot_t {
1992  ulint used;
1993  uint64_t relocated;
1994  uint64_t relocated_usec;
1995  };
1996 
1998  return {used.load(), relocated, relocated_usec};
1999  }
2000 };
2001 
2002 /** @brief The buffer pool structure.
2003 
2004 NOTE! The definition appears here only for other modules of this
2005 directory (buf) to see it. Do not use from outside! */
2006 
2007 struct buf_pool_t {
2008  /** @name General fields */
2009  /** @{ */
2010  /** protects (de)allocation of chunks:
2011  - changes to chunks, n_chunks are performed while holding this latch,
2012  - reading buf_pool_should_madvise requires holding this latch for any
2013  buf_pool_t
2014  - writing to buf_pool_should_madvise requires holding these latches
2015  for all buf_pool_t-s */
2017 
2018  /** LRU list mutex */
2020 
2021  /** free and withdraw list mutex */
2023 
2024  /** buddy allocator mutex */
2026 
2027  /** zip_hash mutex */
2029 
2030  /** Flush state protection mutex */
2031  ib_mutex_t flush_state_mutex;
2032 
2033  /** Zip mutex of this buffer pool instance, protects compressed only pages (of
2034  type buf_page_t, not buf_block_t */
2036 
2037  /** Array index of this buffer pool instance */
2039 
2040  /** Current pool size in bytes */
2042 
2043  /** Reserve this much of the buffer pool for "old" blocks */
2045 #ifdef UNIV_DEBUG
2046  /** Number of frames allocated from the buffer pool to the buddy system.
2047  Protected by zip_hash_mutex. */
2049 #endif
2050  /** Allocator used for allocating memory for the the "chunks" member. */
2052 
2053  /** Number of buffer pool chunks */
2054  volatile ulint n_chunks;
2055 
2056  /** New number of buffer pool chunks */
2057  volatile ulint n_chunks_new;
2058 
2059  /** buffer pool chunks */
2060  buf_chunk_t *chunks;
2061 
2062  /** old buffer pool chunks to be freed after resizing buffer pool */
2063  buf_chunk_t *chunks_old;
2064 
2065  /** Current pool size in pages */
2066  ulint curr_size;
2067 
2068  /** Previous pool size in pages */
2069  ulint old_size;
2070 
2071  /** Size in pages of the area which the read-ahead algorithms read
2072  if invoked */
2074 
2075  /** Hash table of buf_page_t or buf_block_t file pages, buf_page_in_file() ==
2076  TRUE, indexed by (space_id, offset). page_hash is protected by an array of
2077  mutexes. */
2079 
2080  /** Old pointer to page_hash to be freed after resizing buffer pool */
2082 
2083  /** Hash table of buf_block_t blocks whose frames are allocated to the zip
2084  buddy system, indexed by block->frame */
2086 
2087  /** Number of pending read operations. Accessed atomically */
2088  std::atomic<ulint> n_pend_reads;
2089 
2090  /** number of pending decompressions. Accessed atomically. */
2091  std::atomic<ulint> n_pend_unzip;
2092 
2093  /** when buf_print_io was last time called. Accesses not protected. */
2095 
2096  /** Statistics of buddy system, indexed by block size. Protected by zip_free
2097  mutex, except for the used field, which is also accessed atomically */
2099 
2100  /** Current statistics */
2102 
2103  /** Old statistics */
2105 
2106  /* @} */
2107 
2108  /** @name Page flushing algorithm fields */
2109 
2110  /** @{ */
2111 
2112  /** Mutex protecting the flush list access. This mutex protects flush_list,
2113  flush_rbt and bpage::list pointers when the bpage is on flush_list. It also
2114  protects writes to bpage::oldest_modification and flush_list_hp */
2116 
2117  /** "Hazard pointer" used during scan of flush_list while doing flush list
2118  batch. Protected by flush_list_mutex */
2120 
2121  /** Entry pointer to scan the oldest page except for system temporary */
2123 
2124  /** Base node of the modified block list */
2126 
2127  /** This is true when a flush of the given type is being initialized.
2128  Protected by flush_state_mutex. */
2129  bool init_flush[BUF_FLUSH_N_TYPES];
2130 
2131  /** This is the number of pending writes in the given flush type. Protected
2132  by flush_state_mutex. */
2133  ulint n_flush[BUF_FLUSH_N_TYPES];
2134 
2135  /** This is in the set state when there is no flush batch of the given type
2136  running. Protected by flush_state_mutex. */
2138 
2139  /** A red-black tree is used exclusively during recovery to speed up
2140  insertions in the flush_list. This tree contains blocks in order of
2141  oldest_modification LSN and is kept in sync with the flush_list. Each
2142  member of the tree MUST also be on the flush_list. This tree is relevant
2143  only in recovery and is set to NULL once the recovery is over. Protected
2144  by flush_list_mutex */
2146 
2147  /** A sequence number used to count the number of buffer blocks removed from
2148  the end of the LRU list; NOTE that this counter may wrap around at 4
2149  billion! A thread is allowed to read this for heuristic purposes without
2150  holding any mutex or latch. For non-heuristic purposes protected by
2151  LRU_list_mutex */
2153 
2154  /** Set to false when an LRU scan for free block fails. This flag is used to
2155  avoid repeated scans of LRU list when we know that there is no free block
2156  available in the scan depth for eviction. Set to TRUE whenever we flush a
2157  batch from the buffer pool. Accessed protected by memory barriers. */
2159 
2160  /** Page Tracking start LSN. */
2162 
2163  /** Maximum LSN for which write io has already started. */
2165 
2166  /* @} */
2167 
2168  /** @name LRU replacement algorithm fields */
2169  /** @{ */
2170 
2171  /** Base node of the free block list */
2173 
2174  /** base node of the withdraw block list. It is only used during shrinking
2175  buffer pool size, not to reuse the blocks will be removed. Protected by
2176  free_list_mutex */
2178 
2179  /** Target length of withdraw block list, when withdrawing */
2181 
2182  /** "hazard pointer" used during scan of LRU while doing
2183  LRU list batch. Protected by buf_pool::LRU_list_mutex */
2185 
2186  /** Iterator used to scan the LRU list when searching for
2187  replaceable victim. Protected by buf_pool::LRU_list_mutex. */
2189 
2190  /** Iterator used to scan the LRU list when searching for
2191  single page flushing victim. Protected by buf_pool::LRU_list_mutex. */
2193 
2194  /** Base node of the LRU list */
2196 
2197  /** Pointer to the about LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV oldest blocks in
2198  the LRU list; NULL if LRU length less than BUF_LRU_OLD_MIN_LEN; NOTE: when
2199  LRU_old != NULL, its length should always equal LRU_old_len */
2201 
2202  /** Length of the LRU list from the block to which LRU_old points onward,
2203  including that block; see buf0lru.cc for the restrictions on this value; 0
2204  if LRU_old == NULL; NOTE: LRU_old_len must be adjusted whenever LRU_old
2205  shrinks or grows! */
2207 
2208  /** Base node of the unzip_LRU list. The list is protected by the
2209  LRU_list_mutex. */
2211 
2212  /** @} */
2213  /** @name Buddy allocator fields
2214  The buddy allocator is used for allocating compressed page
2215  frames and buf_page_t descriptors of blocks that exist
2216  in the buffer pool only in compressed form. */
2217  /** @{ */
2218 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2219  /** Unmodified compressed pages */
2221 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
2222 
2223  /** Buddy free lists */
2225 
2226  /** Sentinel records for buffer pool watches. Scanning the array is protected
2227  by taking all page_hash latches in X. Updating or reading an individual
2228  watch page is protected by a corresponding individual page_hash latch. */
2230 
2231  /** A wrapper for buf_pool_t::allocator.alocate_large which also advices the
2232  OS that this chunk should not be dumped to a core file if that was requested.
2233  Emits a warning to the log and disables @@global.core_file if advising was
2234  requested but could not be performed, but still return true as the allocation
2235  itself succeeded.
2236  @param[in] mem_size number of bytes to allocate
2237  @param[in,out] chunk mem and mem_pfx fields of this chunk will be updated
2238  to contain information about allocated memory region
2239  @return true iff allocated successfully */
2240  bool allocate_chunk(ulonglong mem_size, buf_chunk_t *chunk);
2241 
2242  /** A wrapper for buf_pool_t::allocator.deallocate_large which also advices
2243  the OS that this chunk can be dumped to a core file.
2244  Emits a warning to the log and disables @@global.core_file if advising was
2245  requested but could not be performed.
2246  @param[in] chunk mem and mem_pfx fields of this chunk will be used to
2247  locate the memory region to free */
2248  void deallocate_chunk(buf_chunk_t *chunk);
2249 
2250  /** Advices the OS that all chunks in this buffer pool instance can be dumped
2251  to a core file.
2252  Emits a warning to the log if could not succeed.
2253  @return true iff succeeded, false if no OS support or failed */
2254  bool madvise_dump();
2255 
2256  /** Advices the OS that all chunks in this buffer pool instance should not
2257  be dumped to a core file.
2258  Emits a warning to the log if could not succeed.
2259  @return true iff succeeded, false if no OS support or failed */
2260  bool madvise_dont_dump();
2261 
2262 #if BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN
2263 #error "BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN"
2264 #endif
2265  /** @} */
2266 };
2267 
2268 /** Print the given buf_pool_t object.
2269 @param[in,out] out the output stream
2270 @param[in] buf_pool the buf_pool_t object to be printed
2271 @return the output stream */
2272 std::ostream &operator<<(std::ostream &out, const buf_pool_t &buf_pool);
2273 
2274 /** @name Accessors for buffer pool mutexes
2275 Use these instead of accessing buffer pool mutexes directly. */
2276 /** @{ */
2277 
2278 #ifndef UNIV_HOTBACKUP
2279 /** Test if flush list mutex is owned. */
2280 #define buf_flush_list_mutex_own(b) mutex_own(&(b)->flush_list_mutex)
2282 /** Acquire the flush list mutex. */
2283 #define buf_flush_list_mutex_enter(b) \
2284  do { \
2285  mutex_enter(&(b)->flush_list_mutex); \
2286  } while (0)
2287 /** Release the flush list mutex. */
2288 #define buf_flush_list_mutex_exit(b) \
2289  do { \
2290  mutex_exit(&(b)->flush_list_mutex); \
2291  } while (0)
2292 
2293 /** Acquire the block->mutex. */
2294 #define buf_page_mutex_enter(b) \
2295  do { \
2296  mutex_enter(&(b)->mutex); \
2297  } while (0)
2298 
2299 /** Release the block->mutex. */
2300 #define buf_page_mutex_exit(b) \
2301  do { \
2302  (b)->mutex.exit(); \
2303  } while (0)
2304 
2305 /** Get appropriate page_hash_lock. */
2306 #define buf_page_hash_lock_get(buf_pool, page_id) \
2307  hash_get_lock((buf_pool)->page_hash, (page_id).fold())
2308 
2309 /** If not appropriate page_hash_lock, relock until appropriate. */
2310 #define buf_page_hash_lock_s_confirm(hash_lock, buf_pool, page_id) \
2311  hash_lock_s_confirm(hash_lock, (buf_pool)->page_hash, (page_id).fold())
2312 
2313 #define buf_page_hash_lock_x_confirm(hash_lock, buf_pool, page_id) \
2314  hash_lock_x_confirm(hash_lock, (buf_pool)->page_hash, (page_id).fold())
2315 #endif /* !UNIV_HOTBACKUP */
2316 
2317 #if defined(UNIV_DEBUG) && !defined(UNIV_HOTBACKUP)
2318 /** Test if page_hash lock is held in s-mode. */
2319 #define buf_page_hash_lock_held_s(buf_pool, bpage) \
2320  rw_lock_own(buf_page_hash_lock_get((buf_pool), (bpage)->id), RW_LOCK_S)
2321 
2322 /** Test if page_hash lock is held in x-mode. */
2323 #define buf_page_hash_lock_held_x(buf_pool, bpage) \
2324  rw_lock_own(buf_page_hash_lock_get((buf_pool), (bpage)->id), RW_LOCK_X)
2325 
2326 /** Test if page_hash lock is held in x or s-mode. */
2327 #define buf_page_hash_lock_held_s_or_x(buf_pool, bpage) \
2328  (buf_page_hash_lock_held_s((buf_pool), (bpage)) || \
2329  buf_page_hash_lock_held_x((buf_pool), (bpage)))
2330 
2331 #define buf_block_hash_lock_held_s(buf_pool, block) \
2332  buf_page_hash_lock_held_s((buf_pool), &(block)->page)
2333 
2334 #define buf_block_hash_lock_held_x(buf_pool, block) \
2335  buf_page_hash_lock_held_x((buf_pool), &(block)->page)
2336 
2337 #define buf_block_hash_lock_held_s_or_x(buf_pool, block) \
2338  buf_page_hash_lock_held_s_or_x((buf_pool), &(block)->page)
2339 #else /* UNIV_DEBUG && !UNIV_HOTBACKUP */
2340 #define buf_page_hash_lock_held_s(b, p) (TRUE)
2341 #define buf_page_hash_lock_held_x(b, p) (TRUE)
2342 #define buf_page_hash_lock_held_s_or_x(b, p) (TRUE)
2343 #define buf_block_hash_lock_held_s(b, p) (TRUE)
2344 #define buf_block_hash_lock_held_x(b, p) (TRUE)
2345 #define buf_block_hash_lock_held_s_or_x(b, p) (TRUE)
2346 #endif /* UNIV_DEBUG && !UNIV_HOTBACKUP */
2347 
2348 /** @} */
2349 
2350 /**********************************************************************
2351 Let us list the consistency conditions for different control block states.
2352 
2353 NOT_USED: is in free list, not in LRU list, not in flush list, nor
2354  page hash table
2355 READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
2356  hash table
2357 MEMORY: is not in free list, LRU list, or flush list, nor page
2358  hash table
2359 FILE_PAGE: space and offset are defined, is in page hash table
2360  if io_fix == BUF_IO_WRITE,
2361  pool: no_flush[flush_type] is in reset state,
2362  pool: n_flush[flush_type] > 0
2363 
2364  (1) if buf_fix_count == 0, then
2365  is in LRU list, not in free list
2366  is in flush list,
2367  if and only if oldest_modification > 0
2368  is x-locked,
2369  if and only if io_fix == BUF_IO_READ
2370  is s-locked,
2371  if and only if io_fix == BUF_IO_WRITE
2372 
2373  (2) if buf_fix_count > 0, then
2374  is not in LRU list, not in free list
2375  is in flush list,
2376  if and only if oldest_modification > 0
2377  if io_fix == BUF_IO_READ,
2378  is x-locked
2379  if io_fix == BUF_IO_WRITE,
2380  is s-locked
2381 
2382 State transitions:
2383 
2384 NOT_USED => READY_FOR_USE
2385 READY_FOR_USE => MEMORY
2386 READY_FOR_USE => FILE_PAGE
2387 MEMORY => NOT_USED
2388 FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
2389  (1) buf_fix_count == 0,
2390  (2) oldest_modification == 0, and
2391  (3) io_fix == 0.
2392 */
2393 
2394 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2395 #ifndef UNIV_HOTBACKUP
2396 /** Functor to validate the LRU list. */
2398  void operator()(const buf_page_t *elem) const { ut_a(elem->in_LRU_list); }
2399 
2400  static void validate(const buf_pool_t *buf_pool) {
2401  CheckInLRUList check;
2402  ut_list_validate(buf_pool->LRU, check);
2403  }
2404 };
2405 
2406 /** Functor to validate the LRU list. */
2408  void operator()(const buf_page_t *elem) const { ut_a(elem->in_free_list); }
2409 
2410  static void validate(const buf_pool_t *buf_pool) {
2411  CheckInFreeList check;
2412  ut_list_validate(buf_pool->free, check);
2413  }
2414 };
2415 
2417  void operator()(const buf_block_t *elem) const {
2418  ut_a(elem->page.in_LRU_list);
2419  ut_a(elem->in_unzip_LRU_list);
2420  }
2421 
2422  static void validate(const buf_pool_t *buf_pool) {
2424  ut_list_validate(buf_pool->unzip_LRU, check);
2425  }
2426 };
2427 #endif /* !UNIV_HOTBACKUP */
2428 #endif /* UNIV_DEBUG || defined UNIV_BUF_DEBUG */
2429 
2430 #ifndef UNIV_HOTBACKUP
2431 /** Prepare a page before adding to the free list.
2432 @param[in,out] bpage Buffer page to prepare for freeing. */
2433 inline void buf_page_prepare_for_free(buf_page_t *bpage) noexcept {
2434  bpage->reset_page_id();
2435 }
2436 #endif /* !UNIV_HOTBACKUP */
2437 
2438 #include "buf0buf.ic"
2439 
2440 #endif /* !buf0buf_h */
buf_page_create
buf_block_t * buf_page_create(const page_id_t &page_id, const page_size_t &page_size, rw_lock_type_t rw_latch, mtr_t *mtr)
Initializes a page to the buffer buf_pool.
Definition: buf0buf.cc:4876
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
buf_pool_update_madvise
void buf_pool_update_madvise()
Checks if innobase_should_madvise_buf_pool() value has changed since we've last check and if so,...
Definition: buf0buf.cc:941
buf_page_belongs_to_unzip_LRU
UNIV_INLINE bool buf_page_belongs_to_unzip_LRU(const buf_page_t *bpage)
Determines if a block should be on unzip_LRU list.
FIL_PAGE_DATA
constexpr ulint FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:110
buf_pool_t::single_scan_itr
LRUItr single_scan_itr
Iterator used to scan the LRU list when searching for single page flushing victim.
Definition: buf0buf.h:2192
lsn_t
uint64_t lsn_t
Type used for all log sequence number storage and arithmetics.
Definition: log0types.h:60
buf_pool_t::LRU_old_len
ulint LRU_old_len
Length of the LRU list from the block to which LRU_old points onward, including that block; see buf0l...
Definition: buf0buf.h:2206
buf_page_print_flags
buf_page_print_flags
Definition: buf0buf.h:682
Page_fetch::POSSIBLY_FREED
@ POSSIBLY_FREED
Like Page_fetch::NORMAL, but do not mind if the file page has been freed.
buf_page_t::get_space
fil_space_t * get_space() const
Retrieve the tablespace object if one was available during page ID initialization.
Definition: buf0buf.h:1313
buf_block_get_io_fix_unlocked
UNIV_INLINE buf_io_fix buf_block_get_io_fix_unlocked(const buf_block_t *block)
Gets the io_fix state of a buffer block.
buf_page_set_sticky
UNIV_INLINE void buf_page_set_sticky(buf_page_t *bpage)
Makes a block sticky.
os0proc.h
buf_page_peek_if_young
UNIV_INLINE ibool buf_page_peek_if_young(const buf_page_t *bpage)
Tells, for heuristics, if a block is still close enough to the MRU end of the LRU list meaning that i...
lsn
static uint64_t lsn
Definition: xcom_base.cc:429
buf_pool_t::chunks_old
buf_chunk_t * chunks_old
old buffer pool chunks to be freed after resizing buffer pool
Definition: buf0buf.h:2063
Page_fetch::NORMAL
@ NORMAL
Get always.
HazardPointer::adjust
virtual void adjust(const buf_page_t *bpage)=0
Adjust the value of hp.
buf_pool_watch_unset
void buf_pool_watch_unset(const page_id_t &page_id)
Stop watching if the page has been read in.
Definition: buf0buf.cc:2909
buf_pool_t::n_pend_unzip
std::atomic< ulint > n_pend_unzip
number of pending decompressions.
Definition: buf0buf.h:2091
buf_page_t::in_flush_list
bool in_flush_list
TRUE if in buf_pool->flush_list; when buf_pool->flush_list_mutex is free, the following should hold: ...
Definition: buf0buf.h:1523
buf_pools_list_size_t::LRU_bytes
ulint LRU_bytes
LRU size in bytes.
Definition: buf0buf.h:229
buf_page_get_freed_page_clock
UNIV_INLINE ulint buf_page_get_freed_page_clock(const buf_page_t *bpage)
Reads the freed_page_clock of a buffer block.
buf_pool_get_oldest_modification_lwm
lsn_t buf_pool_get_oldest_modification_lwm(void)
Gets a safe low watermark for oldest_modification.
Definition: buf0buf.cc:410
BUF_PAGE_PRINT_NO_FULL
@ BUF_PAGE_PRINT_NO_FULL
Do not print the full page dump.
Definition: buf0buf.h:686
FIL_PAGE_PREV
#define FIL_PAGE_PREV
if there is a 'natural' predecessor of the page, its offset.
Definition: fil0types.h:50
buf_pool_t::LRU_list_mutex
BufListMutex LRU_list_mutex
LRU list mutex.
Definition: buf0buf.h:2019
CheckUnzipLRUAndLRUList::operator()
void operator()(const buf_block_t *elem) const
Definition: buf0buf.h:2417
buf_block_t::in_withdraw_list
bool in_withdraw_list
Definition: buf0buf.h:1571
buf_pool_info_t::unzip_sum
ulint unzip_sum
buf_LRU_stat_sum.unzip
Definition: buf0buf.h:221
BUF_BUDDY_SIZES_MAX
#define BUF_BUDDY_SIZES_MAX
Maximum number of buddy sizes based on the max page size.
Definition: buf0types.h:151
buf_block_t::UT_LIST_NODE_T
UT_LIST_NODE_T(buf_block_t) unzip_LRU
node of the decompressed LRU list; a block is in the unzip_LRU list if page.state == BUF_BLOCK_FILE_P...
HazardPointer::HazardPointer
HazardPointer(const HazardPointer &)
Disable copying.
Page_fetch::PEEK_IF_IN_POOL
@ PEEK_IF_IN_POOL
get if in pool, do not make the block young in the LRU list
buf_page_t::UT_LIST_NODE_T
UT_LIST_NODE_T(buf_page_t) list
Based on state, this is a list node, protected by the corresponding list mutex, in one of the followi...
buf_pool_info_t::pages_readahead_rnd_rate
double pages_readahead_rnd_rate
random readahead rate in pages per second
Definition: buf0buf.h:207
buf_pool_info_t::pool_size
ulint pool_size
Buffer Pool size in pages.
Definition: buf0buf.h:159
buf_pool_t::last_printout_time
ib_time_monotonic_t last_printout_time
when buf_print_io was last time called.
Definition: buf0buf.h:2094
buf_block_modify_clock_inc
UNIV_INLINE void buf_block_modify_clock_inc(buf_block_t *block)
Increment the modify clock.
Cache_hint::MAKE_YOUNG
@ MAKE_YOUNG
Move the block to the start of the LRU list if there is a danger that the block would drift out of th...
buf_block_t::n_bytes
volatile uint32_t n_bytes
Recommended prefix length for hash search: number of bytes in an incomplete last field.
Definition: buf0buf.h:1589
buf_page_t::reset_flush_observer
void reset_flush_observer() noexcept
Remove the flush observer.
Definition: buf0buf.h:1369
buf_pool_t::track_page_lsn
lsn_t track_page_lsn
Page Tracking start LSN.
Definition: buf0buf.h:2161
buf_page_set_file_page_was_freed
buf_page_t * buf_page_set_file_page_was_freed(const page_id_t &page_id)
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
Definition: buf0buf.cc:3007
buf_pool_t::allocator
ut_allocator< unsigned char > allocator
Allocator used for allocating memory for the the "chunks" member.
Definition: buf0buf.h:2051
buf0dblwr.h
buf_get_total_list_len
void buf_get_total_list_len(ulint *LRU_len, ulint *free_len, ulint *flush_list_len)
Get total buffer pool statistics.
Definition: buf0buf.cc:441
buf_buddy_stat_t::snapshot_t::relocated
uint64_t relocated
Definition: buf0buf.h:1993
buf_pool_t::chunks
buf_chunk_t * chunks
buffer pool chunks
Definition: buf0buf.h:2060
buf_page_t::oldest_modification
lsn_t oldest_modification
log sequence number of the youngest modification to this block, zero if not modified.
Definition: buf0buf.h:1460
BUF_BLOCK_POOL_WATCH
@ BUF_BLOCK_POOL_WATCH
A sentinel for the buffer pool watch, element of buf_pool->watch[].
Definition: buf0buf.h:131
buf_pool_get_curr_size
UNIV_INLINE ulint buf_pool_get_curr_size(void)
Gets the current size of buffer buf_pool in bytes.
page0types.h
Page_fetch::IF_IN_POOL_OR_WATCH
@ IF_IN_POOL_OR_WATCH
Get the page only if it's in the buffer pool, if not then set a watch on the page.
LRUHp
Class implementing buf_pool->LRU hazard pointer.
Definition: buf0buf.h:1838
ut_a
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:54
buf_page_hash_get_locked
UNIV_INLINE buf_page_t * buf_page_hash_get_locked(buf_pool_t *buf_pool, const page_id_t &page_id, rw_lock_t **lock, ulint lock_mode, bool watch=false)
Returns the control block of a file page, NULL if not found.
ut_ad
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:66
buf_pool_info_t::free_list_len
ulint free_list_len
Length of buf_pool->free list.
Definition: buf0buf.h:162
buf_block_fix
UNIV_INLINE ulint buf_block_fix(buf_page_t *bpage)
Increments the bufferfix count.
buf_pool_invalidate
void buf_pool_invalidate(void)
Invalidates the file pages in the buffer pool when an archive recovery is completed.
Definition: buf0buf.cc:5669
buf_pool_t::freed_page_clock
ulint freed_page_clock
A sequence number used to count the number of buffer blocks removed from the end of the LRU list; NOT...
Definition: buf0buf.h:2152
buf_pool_stat_t::m_n_page_gets
Shards m_n_page_gets
Number of page gets performed; also successful searches through the adaptive hash index are counted a...
Definition: buf0buf.h:1905
buf_pool_info_t::n_pages_created
ulint n_pages_created
buf_pool->n_pages_created
Definition: buf0buf.h:178
dict_index_t
Data structure for an index.
Definition: dict0mem.h:879
buf_block_will_withdrawn
bool buf_block_will_withdrawn(buf_pool_t *buf_pool, const buf_block_t *block)
Determines if a block is intended to be withdrawn.
Definition: buf0buf.cc:1700
buf_block_t::lock_hash_val
uint32_t lock_hash_val
hashed value of the page address in the record lock hash table; protected by buf_block_t::lock (or bu...
Definition: buf0buf.h:1577
buf_block_t::lock
BPageLock lock
read-write lock of the buffer frame
Definition: buf0buf.h:1554
mtr_t
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
buf_get_modified_ratio_pct
double buf_get_modified_ratio_pct(void)
Return the ratio in percents of modified pages in the buffer pool / database pages in the buffer pool...
Definition: buf0buf.cc:6119
buf_buddy_stat_t::take_snapshot
snapshot_t take_snapshot()
Definition: buf0buf.h:1997
os_event
InnoDB condition variable.
Definition: os0event.cc:66
buf_block_t::get_next_page_no
page_no_t get_next_page_no() const
Get the next page number of the current buffer block.
Definition: buf0buf.h:1714
MAX_PAGE_HASH_LOCKS
constexpr ulint MAX_PAGE_HASH_LOCKS
The maximum number of page_hash locks.
Definition: buf0buf.h:113
HazardPointer::HazardPointer
HazardPointer(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1759
CheckInFreeList::operator()
void operator()(const buf_page_t *elem) const
Definition: buf0buf.h:2408
buf_page_hash_get_low
UNIV_INLINE buf_page_t * buf_page_hash_get_low(buf_pool_t *buf_pool, const page_id_t &page_id)
Returns the control block of a file page, NULL if not found.
BUF_FLUSH_N_TYPES
@ BUF_FLUSH_N_TYPES
Index of last element + 1
Definition: buf0types.h:76
buf_pool_info_t::n_page_get_delta
ulint n_page_get_delta
num of buffer pool page gets since last printout
Definition: buf0buf.h:188
buf_pool_free_all
void buf_pool_free_all()
Frees the buffer pool at shutdown.
Definition: buf0buf.cc:6580
buf_page_optimistic_get
bool buf_page_optimistic_get(ulint rw_latch, buf_block_t *block, uint64_t modify_clock, Page_fetch fetch_mode, const char *file, ulint line, mtr_t *mtr)
This is the general function used to get optimistic access to a database page.
Definition: buf0buf.cc:4300
buf_page_get_io_fix
UNIV_INLINE enum buf_io_fix buf_page_get_io_fix(const buf_page_t *bpage)
Gets the io_fix state of a block.
free
#define free(A)
Definition: fts0ast.h:42
buf_block_t::made_dirty_with_no_latch
bool made_dirty_with_no_latch
true if block has been made dirty without acquiring X/SX latch as the block belongs to temporary tabl...
Definition: buf0buf.h:1666
buf_pool_t::buddy_n_frames
ulint buddy_n_frames
Number of frames allocated from the buffer pool to the buddy system.
Definition: buf0buf.h:2048
BPageMutex
ib_bpmutex_t BPageMutex
Definition: buf0types.h:159
fil_space_t::is_deleted
bool is_deleted() const
Definition: fil0fil.cc:12149
buf_page_get_known_nowait
bool buf_page_get_known_nowait(ulint rw_latch, buf_block_t *block, Cache_hint hint, const char *file, ulint line, mtr_t *mtr)
This is used to get access to a known database page, when no waiting can be done.
Definition: buf0buf.cc:4396
buf_pool_info_t::io_sum
ulint io_sum
buf_LRU_stat_sum.io
Definition: buf0buf.h:218
buf_page_init_for_read
buf_page_t * buf_page_init_for_read(dberr_t *err, ulint mode, const page_id_t &page_id, const page_size_t &page_size, ibool unzip)
Inits a page for read to the buffer buf_pool.
Definition: buf0buf.cc:4673
buf_page_free_stale_during_write
void buf_page_free_stale_during_write(buf_page_t *bpage, bool owns_sx_lock=false) noexcept
Free a stale page that is being written.
Definition: buf0buf.cc:5279
buf_resize_thread
void buf_resize_thread()
This is the thread for resizing buffer pool.
Definition: buf0buf.cc:2504
buf_page_t::old
bool old
true if the block is in the old blocks in buf_pool->LRU_old
Definition: buf0buf.h:1509
buf_pool_t::lru_scan_itr
LRUItr lru_scan_itr
Iterator used to scan the LRU list when searching for replaceable victim.
Definition: buf0buf.h:2188
buf_block_get_modify_clock
UNIV_INLINE uint64_t buf_block_get_modify_clock(const buf_block_t *block)
Read the modify clock.
buf_pool_t::lru_hp
LRUHp lru_hp
"hazard pointer" used during scan of LRU while doing LRU list batch.
Definition: buf0buf.h:2184
buf_pool_size_align
UNIV_INLINE ulint buf_pool_size_align(ulint size)
Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit, if needed.
buf_page_get_gen
buf_block_t * buf_page_get_gen(const page_id_t &page_id, const page_size_t &page_size, ulint rw_latch, buf_block_t *guess, Page_fetch mode, const char *file, ulint line, mtr_t *mtr, bool dirty_with_no_latch=false)
This is the general function used to get access to a database page.
Definition: buf0buf.cc:4234
buf_pool_info_t::page_made_young_rate
double page_made_young_rate
page made young rate in pages per second
Definition: buf0buf.h:192
buf_pool_t::old_size
ulint old_size
Previous pool size in pages.
Definition: buf0buf.h:2069
buf_buddy_stat_t::relocated
uint64_t relocated
Number of blocks relocated by the buddy system.
Definition: buf0buf.h:1986
buf_pool_t::oldest_hp
FlushHp oldest_hp
Entry pointer to scan the oldest page except for system temporary.
Definition: buf0buf.h:2122
buf_block_from_ahi
buf_block_t * buf_block_from_ahi(const byte *ptr)
Get a buffer block from an adaptive hash index pointer.
Definition: buf0buf.cc:3307
buf_fix_count_atomic_t
Definition: buf0buf.h:1196
dberr_t
dberr_t
Definition: db0err.h:38
buf_page_t::freed_page_clock
uint32_t freed_page_clock
The value of buf_pool->freed_page_clock when this block was the last time put to the head of the LRU ...
Definition: buf0buf.h:1493
buf_page_t::buf_page_t
buf_page_t(const buf_page_t &other)
Copy constructor.
Definition: buf0buf.h:1206
Page_fetch::IF_IN_POOL
@ IF_IN_POOL
get if in pool
CheckUnzipLRUAndLRUList::validate
static void validate(const buf_pool_t *buf_pool)
Definition: buf0buf.h:2422
BufListMutex
ib_mutex_t BufListMutex
Definition: buf0types.h:160
buf_page_set_old
UNIV_INLINE void buf_page_set_old(buf_page_t *bpage, ibool old)
Flag a block old.
SRV_SHUTDOWN_EXIT_THREADS
@ SRV_SHUTDOWN_EXIT_THREADS
Exit all threads and free resources.
Definition: srv0shutdown.h:110
buf_page_t::get_flush_observer
FlushObserver * get_flush_observer() noexcept
Definition: buf0buf.h:1357
buf_pool_t::instance_no
ulint instance_no
Array index of this buffer pool instance.
Definition: buf0buf.h:2038
buf_buddy_free_t
Struct that is embedded in the free zip blocks.
Definition: buf0buf.h:1879
buf_page_state
buf_page_state
States of a control block.
Definition: buf0buf.h:129
buf_pool_stat_t::n_ra_pages_evicted
uint64_t n_ra_pages_evicted
Number of read ahead pages that are evicted without being accessed.
Definition: buf0buf.h:1924
buf_block_t
The buffer control block structure.
Definition: buf0buf.h:1544
buf_pool_stat_t::reset
void reset()
Definition: buf0buf.h:1964
buf_pool_t::curr_size
ulint curr_size
Current pool size in pages.
Definition: buf0buf.h:2066
buf_page_t::newest_modification
lsn_t newest_modification
The flush LSN, LSN when this page was written to the redo log.
Definition: buf0buf.h:1456
mach_read_from_2
UNIV_INLINE uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
buf_pool_check_no_pending_io
ulint buf_pool_check_no_pending_io(void)
Checks that there currently are no pending i/o-operations for the buffer pool.
Definition: buf0buf.cc:6471
buf_read_page_handle_error
void buf_read_page_handle_error(buf_page_t *bpage)
Unfixes the page, unlatches the page, removes it from page_hash and removes it from LRU.
Definition: buf0buf.cc:5132
buf_pool_info_t::page_read_delta
ulint page_read_delta
num of pages read since last printout
Definition: buf0buf.h:199
buf_pool_info_t::unzip_cur
ulint unzip_cur
buf_LRU_stat_cur.unzip, num pages decompressed in current interval
Definition: buf0buf.h:222
buf_pool_stat_t::LRU_bytes
uint64_t LRU_bytes
LRU size in bytes.
Definition: buf0buf.h:1935
buf_block_t::debug_latch
rw_lock_t debug_latch
In the debug version, each thread which bufferfixes the block acquires an s-latch here; so we can use...
Definition: buf0buf.h:1681
buf_page_peek_if_too_old
UNIV_INLINE ibool buf_page_peek_if_too_old(const buf_page_t *bpage)
Recommends a move of a block to the start of the LRU list if there is danger of dropping from the buf...
buf_page_unset_sticky
UNIV_INLINE void buf_page_unset_sticky(buf_page_t *bpage)
Removes stickiness of a block.
buf_page_alloc_descriptor
UNIV_INLINE buf_page_t * buf_page_alloc_descriptor(void)
Allocates a buf_page_t descriptor.
mutex_own
#define mutex_own(M)
Checks that the current thread owns the mutex.
Definition: ut0mutex.h:153
buf_block_t::get_page_id
const page_id_t & get_page_id() const
Get the page number and space id of the current buffer block.
Definition: buf0buf.h:1706
buf_pool_init
dberr_t buf_pool_init(ulint total_size, ulint n_instances)
Creates the buffer pool.
Definition: buf0buf.cc:1450
buf_page_t::m_dblwr_id
uint16_t m_dblwr_id
Double write instance ordinal value during writes.
Definition: buf0buf.h:1506
buf_pool_info_t::unzip_lru_len
ulint unzip_lru_len
length of buf_pool->unzip_LRU list
Definition: buf0buf.h:215
buf_block_t::curr_left_side
bool curr_left_side
TRUE or FALSE in hash indexing.
Definition: buf0buf.h:1661
buf_flush_t
buf_flush_t
Flags for flush types.
Definition: buf0types.h:65
FlushHp::FlushHp
FlushHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1824
buf_pool_contains_zip
buf_block_t * buf_pool_contains_zip(buf_pool_t *buf_pool, const void *data)
Finds a block in the buffer pool that points to a given compressed page.
Definition: buf0buf.cc:1109
LRUHp::~LRUHp
~LRUHp() override
Destructor.
Definition: buf0buf.h:1847
Counter::Shards< 64 >
json_binary::err
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
buf_block_t::left_side
volatile bool left_side
true or false, depending on whether the leftmost record of several records with the same prefix shoul...
Definition: buf0buf.h:1596
HazardPointer::m_mutex
const ib_mutex_t * m_mutex
mutex that protects access to the m_hp.
Definition: buf0buf.h:1811
start
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:161
buf_pool_get_oldest_modification_approx
lsn_t buf_pool_get_oldest_modification_approx(void)
Gets the smallest oldest_modification lsn among all of the earliest added pages in flush lists.
Definition: buf0buf.cc:357
buf_get_latched_pages_number
ulint buf_get_latched_pages_number(void)
Returns the number of latched pages in the buffer pool.
Definition: buf0buf.cc:6086
buf_page_t::m_space
fil_space_t * m_space
Tablespace instance that this page belongs to.
Definition: buf0buf.h:1488
fil_space_t
Tablespace or log data space.
Definition: fil0fil.h:220
lock_mode
lock_mode
Definition: lock0types.h:51
buf_page_t::hash
buf_page_t * hash
Node used in chaining to buf_pool->page_hash or buf_pool->zip_hash.
Definition: buf0buf.h:1423
page_zip_des_t
Compressed page descriptor.
Definition: page0types.h:182
lock
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:78
n
int n
Definition: xcom_base.cc:445
buf_pool_info_t::young_making_delta
ulint young_making_delta
num of pages made young since last printout
Definition: buf0buf.h:201
buf_pool_info_t::n_page_gets
ulint n_page_gets
buf_pool->n_page_gets
Definition: buf0buf.h:180
buf_pool_t::LRU_old_ratio
ulint LRU_old_ratio
Reserve this much of the buffer pool for "old" blocks.
Definition: buf0buf.h:2044
LRUItr::LRUItr
LRUItr(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1865
buf_page_t::in_free_list
bool in_free_list
true if in buf_pool->free; when buf_pool->free_list_mutex is free, the following should hold: in_free...
Definition: buf0buf.h:1527
buf_page_release_latch
UNIV_INLINE void buf_page_release_latch(buf_block_t *block, ulint rw_latch)
Releases a latch, if specified.
buf_page_t::zip
page_zip_des_t zip
compressed page; zip.data (but not the data it points to) is protected by buf_pool->zip_mutex; state ...
Definition: buf0buf.h:1481
malloc
#define malloc(A)
Definition: fts0ast.h:41
buf_page_t::page_no
page_no_t page_no() const noexcept
Retrieve the page number.
Definition: buf0buf.h:1265
buf_pool_t::curr_pool_size
ulint curr_pool_size
Current pool size in bytes.
Definition: buf0buf.h:2041
Page_fetch
Page_fetch
Definition: buf0buf.h:59
srv0srv.h
buf_block_t::get_prev_page_no
page_no_t get_prev_page_no() const
Get the prev page number of the current buffer block.
Definition: buf0buf.h:1720
buf_pool_t::watch
buf_page_t * watch
Sentinel records for buffer pool watches.
Definition: buf0buf.h:2229
buf_pool_info_t::pages_read_rate
double pages_read_rate
num of pages read per second
Definition: buf0buf.h:196
buf_page_get_block
UNIV_INLINE buf_block_t * buf_page_get_block(buf_page_t *bpage)
Gets the buf_block_t handle of a buffered file block if an uncompressed page frame exists,...
hash0hash.h
buf_block_t::curr_n_fields
uint16_t curr_n_fields
prefix length for hash indexing: number of full fields
Definition: buf0buf.h:1655
buf_page_t::size
page_size_t size
Page size.
Definition: buf0buf.h:1404
fil_space_t::inc_ref
void inc_ref() noexcept
Increment the page reference count.
Definition: fil0fil.h:267
buf_page_peek
UNIV_INLINE ibool buf_page_peek(const page_id_t &page_id)
Returns TRUE if the page can be found in the buffer pool hash table.
buf_page_t
Definition: buf0buf.h:1202
buf_page_t::get_oldest_lsn
lsn_t get_oldest_lsn() const noexcept
Definition: buf0buf.h:1377
buf_frame_t
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:59
buf_pool_t::UT_LIST_BASE_NODE_T
UT_LIST_BASE_NODE_T(buf_page_t) withdraw
base node of the withdraw block list.
buf_pool_info_t::n_ra_pages_read
ulint n_ra_pages_read
buf_pool->n_ra_pages_read, number of pages readahead
Definition: buf0buf.h:183
buf_pool_t::free_list_mutex
BufListMutex free_list_mutex
free and withdraw list mutex
Definition: buf0buf.h:2022
buf.h
buf_page_t::reset_page_id
void reset_page_id(page_id_t new_page_id)
Sets stored page ID to the new value.
Definition: buf0buf.h:1318
buf_pool_info_t::io_cur
ulint io_cur
buf_LRU_stat_cur.io, num of IO for current interval
Definition: buf0buf.h:219
fil_space_t::id
space_id_t id
Tablespace ID.
Definition: fil0fil.h:306
buf_pool_get_n_pages
UNIV_INLINE ulint buf_pool_get_n_pages(void)
Gets the current size of buffer buf_pool in frames.
buf_pool_info_t::n_pend_reads
ulint n_pend_reads
buf_pool->n_pend_reads, pages pending read
Definition: buf0buf.h:166
buf_pool_from_array
UNIV_INLINE buf_pool_t * buf_pool_from_array(ulint index)
Returns the buffer pool instance given its array index.
buf_page_set_accessed
UNIV_INLINE void buf_page_set_accessed(buf_page_t *bpage)
Flag a block accessed.
hash_table_t
Definition: hash0hash.h:403
buf_page_t::reset_page_id
void reset_page_id()
Sets stored value to invalid/empty value.
Definition: buf0buf.h:1334
buf_block_t::index
dict_index_t * index
Index for which the adaptive hash index has been created, or NULL if the page does not exist in the i...
Definition: buf0buf.h:1672
buf_pool_info_t::n_pages_read
ulint n_pages_read
buf_pool->n_pages_read
Definition: buf0buf.h:177
BUF_BLOCK_READY_FOR_USE
@ BUF_BLOCK_READY_FOR_USE
When buf_LRU_get_free_block returns a block, it is in this state.
Definition: buf0buf.h:142
page_size_t
Page size descriptor.
Definition: page0size.h:49
reference_caching::channel::validate
static mysql_service_status_t validate(reference_caching_channel channel) noexcept
Definition: component.cc:66
ut_list_validate
void ut_list_validate(const List &list, Functor &functor)
Checks the consistency of a two-way list.
Definition: ut0lst.h:377
buf_frame_will_withdrawn
bool buf_frame_will_withdrawn(buf_pool_t *buf_pool, const byte *ptr)
Determines if a frame is intended to be withdrawn.
Definition: buf0buf.cc:1721
buf_page_set_flush_type
UNIV_INLINE void buf_page_set_flush_type(buf_page_t *bpage, buf_flush_t flush_type)
Set the flush type of a page.
buf_pool_adjust_chunk_unit
ulonglong buf_pool_adjust_chunk_unit(ulonglong size)
Adjust the proposed chunk unit size so that it satisfies all invariants.
Definition: buf0buf.cc:1995
buf_block_t::page
buf_page_t page
page information; this must be the first field, so that buf_pool->page_hash can point to buf_page_t o...
Definition: buf0buf.h:1550
HazardPointer::m_hp
buf_page_t * m_hp
hazard pointer.
Definition: buf0buf.h:1815
buf_pool_info_t::n_pending_flush_lru
ulint n_pending_flush_lru
Pages pending flush in LRU.
Definition: buf0buf.h:168
BufPoolZipMutex
BPageMutex BufPoolZipMutex
Definition: buf0types.h:162
buf_block_t::modify_clock
uint64_t modify_clock
This clock is incremented every time a pointer to a record on the page may become obsolete; this is u...
Definition: buf0buf.h:1695
buf_page_t::m_version
uint32_t m_version
Version of fil_space_t when the page was updated.
Definition: buf0buf.h:1502
buf_pool_info_t
This structure defines information we will fetch from each buffer pool.
Definition: buf0buf.h:156
mach_read_from_4
UNIV_INLINE uint32_t mach_read_from_4(const byte *b)
The following function is used to fetch data from 4 consecutive bytes.
buf_pool_stat_t::n_pages_not_made_young
uint64_t n_pages_not_made_young
Number of pages not made young because the first access was not long enough ago, in buf_page_peek_if_...
Definition: buf0buf.h:1932
buf_page_reset_file_page_was_freed
buf_page_t * buf_page_reset_file_page_was_freed(const page_id_t &page_id)
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
Definition: buf0buf.cc:3033
buf_pool_t::page_hash
hash_table_t * page_hash
Hash table of buf_page_t or buf_block_t file pages, buf_page_in_file() == TRUE, indexed by (space_id,...
Definition: buf0buf.h:2078
buf_pool_t::chunks_mutex
BufListMutex chunks_mutex
protects (de)allocation of chunks:
Definition: buf0buf.h:2016
buf_page_t::in_LRU_list
bool in_LRU_list
true if the page is in the LRU list; used in debugging
Definition: buf0buf.h:1530
CheckInFreeList
Functor to validate the LRU list.
Definition: buf0buf.h:2407
HazardPointer::~HazardPointer
virtual ~HazardPointer()
Destructor.
Definition: buf0buf.h:1770
buf_page_can_relocate
UNIV_INLINE ibool buf_page_can_relocate(const buf_page_t *bpage)
Determine if a buffer block can be relocated in memory.
srv0shutdown.h
HazardPointer
A "Hazard Pointer" class used to iterate over page lists inside the buffer pool.
Definition: buf0buf.h:1754
buf_page_set_state
UNIV_INLINE void buf_page_set_state(buf_page_t *bpage, enum buf_page_state state)
Sets the state of a block.
page
int page
Definition: ctype-mb.cc:1234
buf_pool_stat_t::n_pages_written
std::atomic< uint64_t > n_pages_written
Number of write operations.
Definition: buf0buf.h:1911
buf_page_t::UT_LIST_NODE_T
UT_LIST_NODE_T(buf_page_t) LRU
node of the LRU list
fil_space_get
fil_space_t * fil_space_get(space_id_t space_id)
Look up a tablespace.
Definition: fil0fil.cc:2323
buf_pool_info_t::n_pages_not_made_young
ulint n_pages_not_made_young
number of pages not made young
Definition: buf0buf.h:176
buf_pool_stat_t::copy
static void copy(buf_pool_stat_t &dst, const buf_pool_stat_t &src) noexcept
Definition: buf0buf.h:1940
log0log.h
buf_pool_info_t::n_pending_flush_single_page
ulint n_pending_flush_single_page
Pages pending to be flushed as part of single page flushes issued by various user threads.
Definition: buf0buf.h:169
buf_pool_info_t::n_pending_flush_list
ulint n_pending_flush_list
Pages pending flush in FLUSH LIST.
Definition: buf0buf.h:173
buf_page_t::in_page_hash
bool in_page_hash
true if in buf_pool->page_hash
Definition: buf0buf.h:1533
buf_get_free_list_len
ulint buf_get_free_list_len(void)
Gets the current length of the free list of buffer blocks.
buf_block_buf_fix_inc_func
UNIV_INLINE void buf_block_buf_fix_inc_func(const char *file, ulint line, buf_block_t *block)
Increments the bufferfix count.
HazardPointer::m_buf_pool
const buf_pool_t * m_buf_pool
Buffer pool instance.
Definition: buf0buf.h:1807
buf_page_t::set_clean
void set_clean() noexcept
Set page to clean state.
Definition: buf0buf.h:1391
FlushHp::~FlushHp
~FlushHp() override
Destructor.
Definition: buf0buf.h:1828
dd::sdi_file::load
bool load(THD *, const dd::String_type &fname, dd::String_type *buf)
Read an sdi file from disk and store in a buffer.
Definition: sdi_file.cc:306
buf_pool_t::LRU_old
buf_page_t * LRU_old
Pointer to the about LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV oldest blocks in the LRU list; NULL if LRU l...
Definition: buf0buf.h:2200
buf_page_t::set_flush_observer
void set_flush_observer(FlushObserver *flush_observer) noexcept
Set the flush observer for the page.
Definition: buf0buf.h:1361
buf_pool_ptr
buf_pool_t * buf_pool_ptr
The buffer pools of the database.
Definition: buf0buf.cc:295
buf_buddy_stat_t::used
std::atomic< ulint > used
Number of blocks allocated from the buddy system.
Definition: buf0buf.h:1983
buf_print_io
void buf_print_io(FILE *file)
Prints info of the buffer i/o.
Definition: buf0buf.cc:6386
fil_space_t::get_current_version
uint32_t get_current_version() const
Returns current version of the space object.
Definition: fil0fil.cc:12162
buf_pool_info_t::n_ra_pages_read_rnd
ulint n_ra_pages_read_rnd
buf_pool->n_ra_pages_read_rnd, number of pages readahead
Definition: buf0buf.h:181
HazardPointer::operator=
HazardPointer & operator=(const HazardPointer &)
buf_page_t::access_time
uint32_t access_time
Time of first access, or 0 if the block was never accessed in the buffer pool.
Definition: buf0buf.h:1498
buf_pool_t::UT_LIST_BASE_NODE_T
UT_LIST_BASE_NODE_T(buf_page_t) zip_clean
Unmodified compressed pages.
buf_block_set_file_page
UNIV_INLINE void buf_block_set_file_page(buf_block_t *block, const page_id_t &page_id)
Map a block to a file page.
buf_pool_stat_t::n_pages_made_young
uint64_t n_pages_made_young
Number of pages made young, in calls to buf_LRU_make_block_young().
Definition: buf0buf.h:1928
buf_page_t::file_page_was_freed
bool file_page_was_freed
This is set to TRUE when fsp frees a page in buffer pool; protected by buf_pool->zip_mutex or buf_blo...
Definition: buf0buf.h:1514
buf_pool_info_t::lru_len
ulint lru_len
Length of buf_pool->LRU.
Definition: buf0buf.h:160
buf_pool_get
UNIV_INLINE buf_pool_t * buf_pool_get(const page_id_t &page_id)
Returns the buffer pool instance given a page id.
buf_page_set_io_fix
UNIV_INLINE void buf_page_set_io_fix(buf_page_t *bpage, enum buf_io_fix io_fix)
Sets the io_fix state of a block.
buf_pool_t::zip_hash
hash_table_t * zip_hash
Hash table of buf_block_t blocks whose frames are allocated to the zip buddy system,...
Definition: buf0buf.h:2085
buf_pool_t::read_ahead_area
page_no_t read_ahead_area
Size in pages of the area which the read-ahead algorithms read if invoked.
Definition: buf0buf.h:2073
buf_block_t::n_hash_helps
uint32_t n_hash_helps
Counter which controls building of a new hash index for the page.
Definition: buf0buf.h:1585
buf_pool_t::UT_LIST_BASE_NODE_T
UT_LIST_BASE_NODE_T(buf_page_t) LRU
Base node of the LRU list.
buf_pool_t::withdraw_target
ulint withdraw_target
Target length of withdraw block list, when withdrawing.
Definition: buf0buf.h:2180
buf_page_t::buf_pool_index
uint8_t buf_pool_index
Index number of the buffer pool that this block belongs to.
Definition: buf0buf.h:1420
buf_pool_t::old_stat
buf_pool_stat_t old_stat
Old statistics.
Definition: buf0buf.h:2104
FIL_PAGE_TYPE
#define FIL_PAGE_TYPE
file page type: FIL_PAGE_INDEX,..., 2 bytes.
Definition: fil0types.h:75
buf_page_try_get_func
const buf_block_t * buf_page_try_get_func(const page_id_t &page_id, const char *file, ulint line, mtr_t *mtr)
Given a tablespace id and page number tries to get that page.
Definition: buf0buf.cc:4488
buf_page_t::buf_fix_count
buf_fix_count_atomic_t buf_fix_count
Count of how many fold this block is currently bufferfixed.
Definition: buf0buf.h:1407
buf_page_io_complete
bool buf_page_io_complete(buf_page_t *bpage, bool evict)
Completes an asynchronous read or write request of a file page to or from the buffer pool.
Definition: buf0buf.cc:5334
buf_page_prepare_for_free
void buf_page_prepare_for_free(buf_page_t *bpage) noexcept
Prepare a page before adding to the free list.
Definition: buf0buf.h:2433
buf_pool_info_t::pages_evicted_rate
double pages_evicted_rate
rate of readahead page evicted without access, in pages per second
Definition: buf0buf.h:211
buf_block_t::in_unzip_LRU_list
bool in_unzip_LRU_list
TRUE if the page is in the decompressed LRU list; used in debugging.
Definition: buf0buf.h:1569
flush_type
flush_type
Definition: my_sys.h:293
consts::FILE
const std::string FILE("FILE")
buf_pools_list_size_t
The occupied bytes of lists in all buffer pools.
Definition: buf0buf.h:228
buf0types.h
buf_page_t::get_newest_lsn
lsn_t get_newest_lsn() const noexcept
Definition: buf0buf.h:1373
buf_block_t::get_page_type_str
const char * get_page_type_str() const noexcept
Get the page type of the current buffer block as string.
Definition: buf0buf.cc:6573
rw_lock_type_t
rw_lock_type_t
Definition: sync0rw.h:135
buf_block_unfix
UNIV_INLINE ulint buf_block_unfix(buf_page_t *bpage)
Decrements the bufferfix count.
buf_page_t::in_zip_hash
bool in_zip_hash
true if in buf_pool->zip_hash
Definition: buf0buf.h:1536
BUF_PAGE_PRINT_NO_CRASH
@ BUF_PAGE_PRINT_NO_CRASH
Do not crash at the end of buf_page_print().
Definition: buf0buf.h:684
buf_buddy_free_t::size
ulint size
size of the block
Definition: buf0buf.h:1881
buf_pool_stat_t
The buffer pool statistics structure.
Definition: buf0buf.h:1899
buf_get_nth_chunk_block
UNIV_INLINE buf_block_t * buf_get_nth_chunk_block(const buf_pool_t *buf_pool, ulint n, ulint *chunk_size)
Get the nth chunk's buffer block in the specified buffer pool.
buf
Definition: buf0block_hint.cc:29
BUF_BLOCK_MEMORY
@ BUF_BLOCK_MEMORY
Contains some main memory object.
Definition: buf0buf.h:148
buf_pool_t::UT_LIST_BASE_NODE_T
UT_LIST_BASE_NODE_T(buf_page_t) flush_list
Base node of the modified block list.
MAX_BUFFER_POOLS_BITS
constexpr ulint MAX_BUFFER_POOLS_BITS
Number of bits to representing a buffer pool ID.
Definition: buf0buf.h:104
buf_block_get_io_fix
UNIV_INLINE enum buf_io_fix buf_block_get_io_fix(const buf_block_t *block)
Gets the io_fix state of a block.
BUF_BLOCK_REMOVE_HASH
@ BUF_BLOCK_REMOVE_HASH
Hash index should be removed before putting to the free list.
Definition: buf0buf.h:151
FIL_PAGE_NEXT
#define FIL_PAGE_NEXT
if there is a 'natural' successor of the page, its offset.
Definition: fil0types.h:60
buf_buddy_stat_t::snapshot_t::relocated_usec
uint64_t relocated_usec
Definition: buf0buf.h:1994
page_id_t
Page identifier.
Definition: buf0types.h:168
buf_pool_t::zip_mutex
BufPoolZipMutex zip_mutex
Zip mutex of this buffer pool instance, protects compressed only pages (of type buf_page_t,...
Definition: buf0buf.h:2035
buf_pool_watch_is_sentinel
ibool buf_pool_watch_is_sentinel(const buf_pool_t *buf_pool, const buf_page_t *bpage)
Determine if a block is a sentinel for a buffer pool watch.
Definition: buf0buf.cc:2754
Page_fetch::SCAN
@ SCAN
Same as NORMAL, but hint that the fetch is part of a large scan.
buf_page_free_stale
bool buf_page_free_stale(buf_pool_t *buf_pool, buf_page_t *bpage) noexcept
Free a stale page.
Definition: buf0buf.cc:5196
buf_pool_from_block
UNIV_INLINE buf_pool_t * buf_pool_from_block(const buf_block_t *block)
Returns the buffer pool instance given a block instance.
BUF_BLOCK_ZIP_DIRTY
@ BUF_BLOCK_ZIP_DIRTY
Contains a compressed page that is in the buf_pool->flush_list.
Definition: buf0buf.h:135
buf_pool_info_t::n_pages_made_young
ulint n_pages_made_young
number of pages made young
Definition: buf0buf.h:175
buf_pool_info_t::pages_created_rate
double pages_created_rate
num of pages create per second
Definition: buf0buf.h:197
buf_buddy_stat_t::snapshot_t::used
ulint used
Definition: buf0buf.h:1992
buf_pool_stat_t::n_pages_read
std::atomic< uint64_t > n_pages_read
Number of read operations.
Definition: buf0buf.h:1908
fil_space_t::dec_ref
void dec_ref() noexcept
Decrement the page reference count.
Definition: fil0fil.h:273
buf_page_get_mutex
UNIV_INLINE BPageMutex * buf_page_get_mutex(const buf_page_t *bpage)
Gets the mutex of a block.
buf_block_t::mutex
BPageMutex mutex
mutex protecting this block: state (also protected by the buffer pool mutex), io_fix,...
Definition: buf0buf.h:1702
buf_frame_align
UNIV_INLINE buf_frame_t * buf_frame_align(byte *ptr)
buf_pool_stat_t::flush_list_bytes
uint64_t flush_list_bytes
Flush_list size in bytes.
Definition: buf0buf.h:1938
page_type_t
uint16_t page_type_t
Definition: fil0fil.h:1199
buf_pool_stat_t::n_pages_created
std::atomic< uint64_t > n_pages_created
number of pages created in the pool with no read.
Definition: buf0buf.h:1914
buf_pool_watch_occurred
ibool buf_pool_watch_occurred(const page_id_t &page_id)
Check if the page has been read in.
Definition: buf0buf.cc:2936
Cache_hint::KEEP_OLD
@ KEEP_OLD
Preserve the current LRU position of the block.
buf_block_hash_get_locked
UNIV_INLINE buf_block_t * buf_block_hash_get_locked(buf_pool_t *buf_pool, const page_id_t &page_id, rw_lock_t **lock, ulint lock_mode)
Returns the control block of a file page, NULL if not found.
buf_block_get_state
UNIV_INLINE enum buf_page_state buf_block_get_state(const buf_block_t *block)
Gets the state of a block.
ib_rbt_t
Red black tree instance.
Definition: ut0rbt.h:74
MAX_BUFFER_POOLS
constexpr ulint MAX_BUFFER_POOLS
The maximum number of buffer pools that can be defined.
Definition: buf0buf.h:107
buf_page_get_state
UNIV_INLINE enum buf_page_state buf_page_get_state(const buf_page_t *bpage)
Gets the state of a block.
buf_block_set_io_fix
UNIV_INLINE void buf_block_set_io_fix(buf_block_t *block, enum buf_io_fix io_fix)
Sets the io_fix state of a block.
buf_pool_info_t::old_lru_len
ulint old_lru_len
buf_pool->LRU_old_len
Definition: buf0buf.h:161
buf_block_dbg_add_level
UNIV_INLINE void buf_block_dbg_add_level(buf_block_t *block, latch_level_t level)
Adds latch level info for the rw-lock protecting the buffer frame.
buf_pool_t::flush_rbt
ib_rbt_t * flush_rbt
A red-black tree is used exclusively during recovery to speed up insertions in the flush_list.
Definition: buf0buf.h:2145
buf_get_n_pending_read_ios
ulint buf_get_n_pending_read_ios(void)
Returns the number of pending buf pool read ios.
Definition: buf0buf.cc:6105
buf_page_make_young
void buf_page_make_young(buf_page_t *bpage)
Moves a page to the start of the buffer pool LRU list.
Definition: buf0buf.cc:2961
buf_pool_stat_t::n_ra_pages_read
std::atomic< uint64_t > n_ra_pages_read
Number of pages read in as part of read ahead.
Definition: buf0buf.h:1920
buf_page_get_io_fix_unlocked
UNIV_INLINE enum buf_io_fix buf_page_get_io_fix_unlocked(const buf_page_t *bpage)
Gets the io_fix state of a buffer page.
buf_buddy_stat_t::snapshot_t
Definition: buf0buf.h:1991
buf_block_get_freed_page_clock
UNIV_INLINE ulint buf_block_get_freed_page_clock(const buf_block_t *block)
Reads the freed_page_clock of a buffer block.
buf_zip_decompress
ibool buf_zip_decompress(buf_block_t *block, ibool check)
Decompress a block.
Definition: buf0buf.cc:3238
buf_get_total_list_size_in_bytes
void buf_get_total_list_size_in_bytes(buf_pools_list_size_t *buf_pools_list_size)
Get total list size in bytes from all buffer pools.
Definition: buf0buf.cc:461
classic_protocol::column_def::pos::set
constexpr value_type set
Definition: classic_protocol_constants.h:271
buf_page_in_file
UNIV_INLINE ibool buf_page_in_file(const buf_page_t *bpage)
Determines if a block is mapped to a tablespace.
std
Definition: varlen_sort.h:182
buf_pool_from_bpage
UNIV_INLINE buf_pool_t * buf_pool_from_bpage(const buf_page_t *bpage)
Returns the buffer pool instance given a page instance.
buf_pool_info_t::flush_list_len
ulint flush_list_len
Length of buf_pool->flush_list.
Definition: buf0buf.h:163
buf_pool_t::flush_state_mutex
ib_mutex_t flush_state_mutex
Flush state protection mutex.
Definition: buf0buf.h:2031
buf_page_t::state
buf_page_state state
Block state.
Definition: buf0buf.h:1413
CheckInFreeList::validate
static void validate(const buf_pool_t *buf_pool)
Definition: buf0buf.h:2410
buf_page_is_accessed
UNIV_INLINE unsigned buf_page_is_accessed(const buf_page_t *bpage)
Determine the time of first access of a block in the buffer pool.
fil_space_t::get_recent_version
uint32_t get_recent_version() const
Returns current version of the space object.
Definition: fil0fil.cc:12166
buf_pool_index
UNIV_INLINE ulint buf_pool_index(const buf_pool_t *buf_pool)
Calculates the index of a buffer pool to the buf_pool[] array.
fil_space_t::was_not_deleted
bool was_not_deleted() const
Definition: fil0fil.cc:12154
buf_block_get_frame
UNIV_INLINE buf_frame_t * buf_block_get_frame(const buf_block_t *block)
Gets a pointer to the memory frame of a block.
buf_block_get_lock_hash_val
UNIV_INLINE ulint buf_block_get_lock_hash_val(const buf_block_t *block)
Gets the hash value of a block.
BUF_BLOCK_ZIP_PAGE
@ BUF_BLOCK_ZIP_PAGE
Contains a clean compressed page.
Definition: buf0buf.h:133
file
Definition: os0file.h:85
buf_frame_copy
UNIV_INLINE byte * buf_frame_copy(byte *buf, const buf_frame_t *frame)
Copies contents of a buffer frame to a given buffer.
buf_page_t::is_dirty
bool is_dirty() const noexcept
Definition: buf0buf.h:1380
buf_get_total_stat
void buf_get_total_stat(buf_pool_stat_t *tot_stat)
Get total buffer pool statistics.
Definition: buf0buf.cc:482
buf_page_t::is_stale
bool is_stale() const
Checks if this space reference saved during last page ID initialization was deleted or truncated sinc...
Definition: buf0buf.h:1274
buf_block_t::n_fields
volatile uint32_t n_fields
Recommended prefix length for hash search: number of full fields.
Definition: buf0buf.h:1592
HazardPointer::get
buf_page_t * get() const
Get current value.
Definition: buf0buf.h:1773
buf_page_t::space
space_id_t space() const noexcept
Retrieve the tablespace id.
Definition: buf0buf.h:1259
buf_block_t::curr_n_bytes
uint16_t curr_n_bytes
number of bytes in hash indexing
Definition: buf0buf.h:1658
buf_page_t::set_oldest_lsn
void set_oldest_lsn(lsn_t lsn) noexcept
Set the LSN when the page is modified for the first time.
buf_pool_t::UT_LIST_BASE_NODE_T
UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU
Base node of the unzip_LRU list.
buf_must_be_all_freed
void buf_must_be_all_freed(void)
Assert that all file pages in the buffer are in a replaceable state.
Definition: buf0buf.cc:6458
buf_pool_info_t::pages_written_rate
double pages_written_rate
num of pages written per second
Definition: buf0buf.h:198
fil0fil.h
Counter::copy
void copy(Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
Copy the counters, overwrite destination.
Definition: ut0counter.h:353
Cache_hint
Cache_hint
Definition: buf0buf.h:92
Page_fetch::NO_LATCH
@ NO_LATCH
get and bufferfix, but set no latch; we have separated this case, because it is error-prone programmi...
buf_print
void buf_print(void)
Prints info of the buffer pool data structure.
Definition: buf0buf.cc:5989
buf_pool_t::try_LRU_scan
bool try_LRU_scan
Set to false when an LRU scan for free block fails.
Definition: buf0buf.h:2158
buf_pool_t::UT_LIST_BASE_NODE_T
UT_LIST_BASE_NODE_T(buf_buddy_free_t) zip_free[BUF_BUDDY_SIZES_MAX]
Buddy free lists.
buf_pool_info_t::not_young_making_delta
ulint not_young_making_delta
num of pages not make young since last printout
Definition: buf0buf.h:203
space_id_t
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
buf_page_t::io_fix
buf_io_fix io_fix
Type of pending I/O operation.
Definition: buf0buf.h:1410
rw_lock_t
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:568
buf_pools_list_size_t::flush_list_bytes
ulint flush_list_bytes
flush_list size in bytes
Definition: buf0buf.h:231
buf_page_t::space_id_changed
void space_id_changed()
Updates new space reference and acquires "reference count latch" and the current version of the space...
Definition: buf0buf.h:1341
FlushHp
Class implementing buf_pool->flush_list hazard pointer.
Definition: buf0buf.h:1819
buf_pool_info_t::page_not_made_young_rate
double page_not_made_young_rate
page not made young rate in pages per second
Definition: buf0buf.h:194
buf_buddy_stat_t
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:1981
buf_pool_clear_hash_index
void buf_pool_clear_hash_index(void)
Clears the adaptive hash index on all pages in the buffer pool.
Definition: buf0buf.cc:2529
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
LRUItr::~LRUItr
~LRUItr() override
Destructor.
Definition: buf0buf.h:1869
buf_page_get_zip
buf_page_t * buf_page_get_zip(const page_id_t &page_id, const page_size_t &page_size)
Get read access to a compressed page (usually of type FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
Definition: buf0buf.cc:3094
buf_pool_t::n_chunks
volatile ulint n_chunks
Number of buffer pool chunks.
Definition: buf0buf.h:2054
buf_block_t::frame
byte * frame
pointer to buffer frame which is of size UNIV_PAGE_SIZE, and aligned to an address divisible by UNIV_...
Definition: buf0buf.h:1560
buf_pool_stat_t::n_ra_pages_read_rnd
std::atomic< uint64_t > n_ra_pages_read_rnd
Number of pages read in as part of random read ahead.
Definition: buf0buf.h:1917
buf_page_print
void buf_page_print(const byte *read_buf, const page_size_t &page_size, ulint flags)
Prints a page to stderr.
Definition: buf0buf.cc:537
buf_ptr_get_fsp_addr
UNIV_INLINE void buf_ptr_get_fsp_addr(const void *ptr, space_id_t *space, fil_addr_t *addr)
Gets the space id, page offset, and byte offset within page of a pointer pointing to a buffer frame c...
buf_get_withdraw_depth
UNIV_INLINE ulint buf_get_withdraw_depth(buf_pool_t *buf_pool)
Return how many more pages must be added to the withdraw list to reach the withdraw target of the cur...
CheckUnzipLRUAndLRUList
Definition: buf0buf.h:2416
buf_fix_count_atomic_t::buf_fix_count_atomic_t
buf_fix_count_atomic_t(const buf_fix_count_atomic_t &other)
Definition: buf0buf.h:1198
buf_pool_t::n_chunks_new
volatile ulint n_chunks_new
New number of buffer pool chunks.
Definition: buf0buf.h:2057
buf_page_t::set_newest_lsn
void set_newest_lsn(lsn_t lsn) noexcept
Set the latest modification LSN.
Definition: buf0buf.h:1384
buf_page_t::m_flush_observer
FlushObserver * m_flush_observer
Flush observer instance.
Definition: buf0buf.h:1485
buf_page_get_newest_modification
UNIV_INLINE lsn_t buf_page_get_newest_modification(const buf_page_t *bpage)
Gets the youngest modification log sequence number for a frame.
buf_pool_info_t::n_pend_unzip
ulint n_pend_unzip
buf_pool->n_pend_unzip, pages pending decompress
Definition: buf0buf.h:164
BUF_BLOCK_FILE_PAGE
@ BUF_BLOCK_FILE_PAGE
Contains a buffered file page.
Definition: buf0buf.h:145
buf_refresh_io_stats_all
void buf_refresh_io_stats_all()
Refresh the statistics used to print per-second averages.
Definition: buf0buf.cc:6447
buf_pool_t::UT_LIST_BASE_NODE_T
UT_LIST_BASE_NODE_T(buf_page_t) free
Base node of the free block list.
buf_page_release_zip
UNIV_INLINE void buf_page_release_zip(buf_page_t *bpage)
Releases a compressed-only page acquired with buf_page_get_zip().
buf_pool_t::flush_hp
FlushHp flush_hp
"Hazard pointer" used during scan of flush_list while doing flush list batch.
Definition: buf0buf.h:2119
latch_level_t
latch_level_t
Latching order levels.
Definition: sync0types.h:217
buf_stats_get_pool_info
void buf_stats_get_pool_info(buf_pool_t *buf_pool, ulint pool_id, buf_pool_info_t *all_pool_info)
Collect buffer pool stats information for a buffer pool.
Definition: buf0buf.cc:6188
buf_pool_t::n_pend_reads
std::atomic< ulint > n_pend_reads
Number of pending read operations.
Definition: buf0buf.h:2088
buf_validate
ibool buf_validate(void)
Validates the buffer pool data structure.
Definition: buf0buf.cc:5889
buf_pools_list_size_t::unzip_LRU_bytes
ulint unzip_LRU_bytes
unzip_LRU size in bytes
Definition: buf0buf.h:230
buf_block_t::get_page_no
page_no_t get_page_no() const
Get the page number of the current buffer block.
Definition: buf0buf.h:1710
buf_page_t::flush_type
buf_flush_t flush_type
If this block is currently being flushed to disk, this tells the flush_type.
Definition: buf0buf.h:1417
buf_pool_t::max_lsn_io
lsn_t max_lsn_io
Maximum LSN for which write io has already started.
Definition: buf0buf.h:2164
buf_pool_info_t::n_pages_written
ulint n_pages_written
buf_pool->n_pages_written
Definition: buf0buf.h:179
buf_buddy_stat_t::relocated_usec
uint64_t relocated_usec
Total duration of block relocations, in microseconds.
Definition: buf0buf.h:1989
LRUHp::LRUHp
LRUHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1843
buf_block_free
UNIV_INLINE void buf_block_free(buf_block_t *block)
Frees a buffer block which does not contain a file page.
buf_pool_info_t::n_ra_pages_evicted
ulint n_ra_pages_evicted
buf_pool->n_ra_pages_evicted, number of readahead pages evicted without access
Definition: buf0buf.h:185
FlushObserver
We use FlushObserver to track flushing of non-redo logged pages in bulk create index(BtrBulk....
Definition: buf0flu.h:266
buf_pool_t
The buffer pool structure.
Definition: buf0buf.h:2007
buf_pool_t::stat
buf_pool_stat_t stat
Current statistics.
Definition: buf0buf.h:2101
fil_addr_t
File space address.
Definition: fil0fil.h:1154
LRUItr
Special purpose iterators to be used when scanning the LRU list.
Definition: buf0buf.h:1860
buf_block_alloc
buf_block_t * buf_block_alloc(buf_pool_t *buf_pool)
Allocates a buffer block.
Definition: buf0buf.cc:508
page_id_t::page_no
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:204
buf_flush_update_zip_checksum
void buf_flush_update_zip_checksum(buf_frame_t *page, ulint size, lsn_t lsn, bool skip_lsn_check)
Calculate the checksum of a page from compressed table and update the page.
Definition: buf0flu.cc:925
operator<<
std::ostream & operator<<(std::ostream &out, const buf_pool_t &buf_pool)
Print the given buf_pool_t object.
Definition: buf0buf.cc:6546
ib_time_monotonic_t
int64_t ib_time_monotonic_t
Time stamp read from the monotonic clock (returned by ut_time_monotonic()).
Definition: ut0ut.h:89
buf_page_get_flush_type
UNIV_INLINE buf_flush_t buf_page_get_flush_type(const buf_page_t *bpage)
Get the flush type of a page.
ut_allocator< unsigned char >
buf_page_make_old
void buf_page_make_old(buf_page_t *bpage)
Moved a page to the end of the buffer pool LRU list so that it can be flushed out at the earliest.
Definition: buf0buf.cc:2973
BUF_BLOCK_NOT_USED
@ BUF_BLOCK_NOT_USED
Is in the free list; must be after the BUF_BLOCK_ZIP_ constants for compressed-only pages.
Definition: buf0buf.h:139
buf_pool_t::zip_hash_mutex
BufListMutex zip_hash_mutex
zip_hash mutex
Definition: buf0buf.h:2028
ut0rbt.h
buf_pool_t::flush_list_mutex
BufListMutex flush_list_mutex
Mutex protecting the flush list access.
Definition: buf0buf.h:2115
buf_pool_t::page_hash_old
hash_table_t * page_hash_old
Old pointer to page_hash to be freed after resizing buffer pool.
Definition: buf0buf.h:2081
buf_page_is_old
UNIV_INLINE ibool buf_page_is_old(const buf_page_t *bpage)
Determine if a block has been flagged old.
buf_pool_info_t::pool_unique_id
ulint pool_unique_id
Buffer Pool ID.
Definition: buf0buf.h:158
buf_block_t::n_pointers
std::atomic< ulint > n_pointers
used in debugging: the number of pointers in the adaptive hash index pointing to this frame; protecte...
Definition: buf0buf.h:1637
CheckInLRUList
Functor to validate the LRU list.
Definition: buf0buf.h:2397
buf_page_t::was_stale
bool was_stale() const
Checks if this space reference saved during last page ID initialization was deleted or truncated sinc...
Definition: buf0buf.h:1291
buf_pool_t::zip_free_mutex
BufListMutex zip_free_mutex
buddy allocator mutex
Definition: buf0buf.h:2025
buf_io_fix
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:96
stdx::io::mode
mode
Definition: file_handle.h:59
buf_pool_info_t::pages_readahead_rate
double pages_readahead_rate
readahead rate in pages per second
Definition: buf0buf.h:209
buf_buddy_free_t::UT_LIST_NODE_T
UT_LIST_NODE_T(buf_buddy_free_t) list
Node of zip_free list.
mtr0types.h
buf_buddy_free_t::bpage
buf_page_t bpage
Embedded bpage descriptor.
Definition: buf0buf.h:1893
buf_page_free_descriptor
void buf_page_free_descriptor(buf_page_t *bpage)
Free a buf_page_t descriptor.
Definition: buf0buf.cc:1364
buf_page_t::set_dblwr_batch_id
void set_dblwr_batch_id(uint16_t batch_id)
Set the doublewrite buffer ID.
Definition: buf0buf.h:1250
buf_block_t::get_page_type
page_type_t get_page_type() const
Get the page type of the current buffer block.
Definition: buf0buf.h:1726
buf_is_block_in_instance
bool buf_is_block_in_instance(const buf_pool_t *buf_pool, const buf_block_t *ptr)
Find out if a block pointer points into one of currently used chunks of the buffer pool.
Definition: buf0buf.cc:3343
Counter::clear
void clear(Shards< COUNT > &shards) noexcept
Clear the counter - reset to 0.
Definition: ut0counter.h:343
buf_page_t::id
page_id_t id
Page id.
Definition: buf0buf.h:1401
buf_block_set_state
UNIV_INLINE void buf_block_set_state(buf_block_t *block, enum buf_page_state state)
Sets the state of a block.
flags
static int flags[50]
Definition: hp_test1.cc:39
buf_page_t::get_dblwr_batch_id
uint16_t get_dblwr_batch_id() const
Definition: buf0buf.h:1253
ut0byte.h
false
#define false
Definition: config_static.h:43
srv_shutdown_state
std::atomic< enum srv_shutdown_t > srv_shutdown_state
At a shutdown this value climbs from SRV_SHUTDOWN_NONE to SRV_SHUTDOWN_EXIT_THREADS.
Definition: srv0start.cc:166