MySQL  8.0.19
Source Code Documentation
buf0buf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2019, Oracle and/or its affiliates. All Rights Reserved.
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 "buf0types.h"
37 #include "fil0fil.h"
38 #include "hash0hash.h"
39 #include "log0log.h"
40 #include "mtr0types.h"
41 #include "os0proc.h"
42 #include "page0types.h"
43 #include "srv0srv.h"
44 #include "univ.i"
45 #include "ut0byte.h"
46 #include "ut0rbt.h"
47 
48 #include "buf/buf.h"
49 
50 #include <ostream>
51 
52 // Forward declaration
53 struct fil_addr_t;
54 
55 /** @name Modes for buf_page_get_gen */
56 /* @{ */
57 enum class Page_fetch {
58  /** Get always */
59  NORMAL,
60 
61  /** Same as NORMAL, but hint that the fetch is part of a large scan.
62  Try not to flood the buffer pool with pages that may not be accessed again
63  any time soon. */
64  SCAN,
65 
66  /** get if in pool */
67  IF_IN_POOL,
68 
69  /** get if in pool, do not make the block young in the LRU list */
71 
72  /** get and bufferfix, but set no latch; we have separated this case, because
73  it is error-prone programming not to set a latch, and it should be used with
74  care */
75  NO_LATCH,
76 
77  /** Get the page only if it's in the buffer pool, if not then set a watch on
78  the page. */
80 
81  /** Like Page_fetch::NORMAL, but do not mind if the file page has been
82  freed. */
84 };
85 /* @} */
86 
87 /** @name Modes for buf_page_get_known_nowait */
88 
89 /* @{ */
90 enum class Cache_hint {
91  /** Move the block to the start of the LRU list if there is a danger that the
92  block would drift out of the buffer pool*/
93  MAKE_YOUNG = 51,
94 
95  /** Preserve the current LRU position of the block. */
96  KEEP_OLD = 52
97 };
98 
99 /* @} */
100 
101 /** Number of bits to representing a buffer pool ID */
102 constexpr ulint MAX_BUFFER_POOLS_BITS = 6;
103 
104 /** The maximum number of buffer pools that can be defined */
105 constexpr ulint MAX_BUFFER_POOLS = (1 << MAX_BUFFER_POOLS_BITS);
106 
107 /** Maximum number of concurrent buffer pool watches */
108 #define BUF_POOL_WATCH_SIZE (srv_n_purge_threads + 1)
109 
110 /** The maximum number of page_hash locks */
111 constexpr ulint MAX_PAGE_HASH_LOCKS = 1024;
112 
113 /** The buffer pools of the database */
114 extern buf_pool_t *buf_pool_ptr;
115 
116 /** true when withdrawing buffer pool pages might cause page relocation */
117 extern volatile bool buf_pool_withdrawing;
118 
119 /** the clock is incremented every time a pointer to a page may become
120 obsolete */
121 extern volatile ulint buf_withdraw_clock;
122 
123 #ifdef UNIV_HOTBACKUP
124 /** first block, for --apply-log */
125 extern buf_block_t *back_block1;
126 /** second block, for page reorganize */
127 extern buf_block_t *back_block2;
128 #endif /* UNIV_HOTBACKUP */
129 
130 /** @brief States of a control block
131 @see buf_page_t
132 
133 The enumeration values must be 0..7. */
135  BUF_BLOCK_POOL_WATCH, /*!< a sentinel for the buffer pool
136  watch, element of buf_pool->watch[] */
137  BUF_BLOCK_ZIP_PAGE, /*!< contains a clean
138  compressed page */
139  BUF_BLOCK_ZIP_DIRTY, /*!< contains a compressed
140  page that is in the
141  buf_pool->flush_list */
142 
143  BUF_BLOCK_NOT_USED, /*!< is in the free list;
144  must be after the BUF_BLOCK_ZIP_
145  constants for compressed-only pages
146  @see buf_block_state_valid() */
147  BUF_BLOCK_READY_FOR_USE, /*!< when buf_LRU_get_free_block
148  returns a block, it is in this state */
149  BUF_BLOCK_FILE_PAGE, /*!< contains a buffered file page */
150  BUF_BLOCK_MEMORY, /*!< contains some main memory
151  object */
152  BUF_BLOCK_REMOVE_HASH /*!< hash index should be removed
153  before putting to the free list */
154 };
155 
156 /** This structure defines information we will fetch from each buffer pool. It
157 will be used to print table IO stats */
159  /* General buffer pool info */
160  ulint pool_unique_id; /*!< Buffer Pool ID */
161  ulint pool_size; /*!< Buffer Pool size in pages */
162  ulint lru_len; /*!< Length of buf_pool->LRU */
163  ulint old_lru_len; /*!< buf_pool->LRU_old_len */
164  ulint free_list_len; /*!< Length of buf_pool->free list */
165  ulint flush_list_len; /*!< Length of buf_pool->flush_list */
166  ulint n_pend_unzip; /*!< buf_pool->n_pend_unzip, pages
167  pending decompress */
168  ulint n_pend_reads; /*!< buf_pool->n_pend_reads, pages
169  pending read */
170  ulint n_pending_flush_lru; /*!< Pages pending flush in LRU */
171  ulint n_pending_flush_single_page; /*!< Pages pending to be
172  flushed as part of single page
173  flushes issued by various user
174  threads */
175  ulint n_pending_flush_list; /*!< Pages pending flush in FLUSH
176  LIST */
177  ulint n_pages_made_young; /*!< number of pages made young */
178  ulint n_pages_not_made_young; /*!< number of pages not made young */
179  ulint n_pages_read; /*!< buf_pool->n_pages_read */
180  ulint n_pages_created; /*!< buf_pool->n_pages_created */
181  ulint n_pages_written; /*!< buf_pool->n_pages_written */
182  ulint n_page_gets; /*!< buf_pool->n_page_gets */
183  ulint n_ra_pages_read_rnd; /*!< buf_pool->n_ra_pages_read_rnd,
184  number of pages readahead */
185  ulint n_ra_pages_read; /*!< buf_pool->n_ra_pages_read, number
186  of pages readahead */
187  ulint n_ra_pages_evicted; /*!< buf_pool->n_ra_pages_evicted,
188  number of readahead pages evicted
189  without access */
190  ulint n_page_get_delta; /*!< num of buffer pool page gets since
191  last printout */
192 
193  /* Buffer pool access stats */
194  double page_made_young_rate; /*!< page made young rate in pages
195  per second */
196  double page_not_made_young_rate; /*!< page not made young rate
197  in pages per second */
198  double pages_read_rate; /*!< num of pages read per second */
199  double pages_created_rate; /*!< num of pages create per second */
200  double pages_written_rate; /*!< num of pages written per second */
201  ulint page_read_delta; /*!< num of pages read since last
202  printout */
203  ulint young_making_delta; /*!< num of pages made young since
204  last printout */
205  ulint not_young_making_delta; /*!< num of pages not make young since
206  last printout */
207 
208  /* Statistics about read ahead algorithm. */
209  double pages_readahead_rnd_rate; /*!< random readahead rate in pages per
210  second */
211  double pages_readahead_rate; /*!< readahead rate in pages per
212  second */
213  double pages_evicted_rate; /*!< rate of readahead page evicted
214  without access, in pages per second */
215 
216  /* Stats about LRU eviction */
217  ulint unzip_lru_len; /*!< length of buf_pool->unzip_LRU
218  list */
219  /* Counters for LRU policy */
220  ulint io_sum; /*!< buf_LRU_stat_sum.io */
221  ulint io_cur; /*!< buf_LRU_stat_cur.io, num of IO
222  for current interval */
223  ulint unzip_sum; /*!< buf_LRU_stat_sum.unzip */
224  ulint unzip_cur; /*!< buf_LRU_stat_cur.unzip, num
225  pages decompressed in current
226  interval */
227 };
228 
229 /** The occupied bytes of lists in all buffer pools */
231  ulint LRU_bytes; /*!< LRU size in bytes */
232  ulint unzip_LRU_bytes; /*!< unzip_LRU size in bytes */
233  ulint flush_list_bytes; /*!< flush_list size in bytes */
234 };
235 
236 #ifndef UNIV_HOTBACKUP
237 /** Creates the buffer pool.
238 @param[in] total_size Size of the total pool in bytes.
239 @param[in] n_instances Number of buffer pool instances to create.
240 @return DB_SUCCESS if success, DB_ERROR if not enough memory or error */
241 dberr_t buf_pool_init(ulint total_size, ulint n_instances);
242 
243 /** Frees the buffer pool at shutdown. This must not be invoked before
244  freeing all mutexes. */
245 void buf_pool_free_all();
246 
247 /** Determines if a block is intended to be withdrawn.
248 @param[in] buf_pool buffer pool instance
249 @param[in] block pointer to control block
250 @retval true if will be withdrawn */
251 bool buf_block_will_withdrawn(buf_pool_t *buf_pool, const buf_block_t *block);
252 
253 /** Determines if a frame is intended to be withdrawn.
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
275 ulint buf_pool_get_curr_size(void);
276 /** Gets the current size of buffer buf_pool in frames.
277  @return size in pages */
278 UNIV_INLINE
279 ulint buf_pool_get_n_pages(void);
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
335 buf_page_t *buf_page_alloc_descriptor(void) MY_ATTRIBUTE((malloc));
336 /** Free a buf_page_t descriptor. */
337 UNIV_INLINE
339  buf_page_t *bpage); /*!< in: 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_t::mutex.
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 /** Tries to get a page.
415 If the page is not in the buffer pool it is not loaded. Suitable for using
416 when holding the lock_sys_t::mutex.
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 /** Returns TRUE if the page can be found in the buffer pool hash table.
495 NOTE that it is possible that the page is not yet read from disk,
496 though.
497 @param[in] page_id page id
498 @return true if found in the page hash table */
499 UNIV_INLINE
500 ibool buf_page_peek(const page_id_t &page_id);
501 
502 #ifdef UNIV_DEBUG
503 
504 /** Sets file_page_was_freed TRUE if the page is found in the buffer pool.
505 This function should be called when we free a file page and want the
506 debug version to check that it is not accessed any more unless
507 reallocated.
508 @param[in] page_id page id
509 @return control block if found in page hash table, otherwise NULL */
511 
512 /** Sets file_page_was_freed FALSE if the page is found in the buffer pool.
513 This function should be called when we free a file page and want the
514 debug version to check that it is not accessed any more unless
515 reallocated.
516 @param[in] page_id page id
517 @return control block if found in page hash table, otherwise NULL */
519 
520 #endif /* UNIV_DEBUG */
521 /** Reads the freed_page_clock of a buffer block.
522  @return freed_page_clock */
523 UNIV_INLINE
524 ulint buf_page_get_freed_page_clock(const buf_page_t *bpage) /*!< in: block */
525  MY_ATTRIBUTE((warn_unused_result));
526 /** Reads the freed_page_clock of a buffer block.
527  @return freed_page_clock */
528 UNIV_INLINE
529 ulint buf_block_get_freed_page_clock(const buf_block_t *block) /*!< in: block */
530  MY_ATTRIBUTE((warn_unused_result));
531 
532 /** Tells, for heuristics, if a block is still close enough to the MRU end of
533 the LRU list meaning that it is not in danger of getting evicted and also
534 implying that it has been accessed recently.
535 The page must be either buffer-fixed, either its page hash must be locked.
536 @param[in] bpage block
537 @return true if block is close to MRU end of LRU */
538 UNIV_INLINE
539 ibool buf_page_peek_if_young(const buf_page_t *bpage);
540 
541 /** Recommends a move of a block to the start of the LRU list if there is
542 danger of dropping from the buffer pool.
543 NOTE: does not reserve the LRU list mutex.
544 @param[in] bpage block to make younger
545 @return true if should be made younger */
546 UNIV_INLINE
547 ibool buf_page_peek_if_too_old(const buf_page_t *bpage);
548 
549 /** Gets the youngest modification log sequence number for a frame.
550  Returns zero if not file page or no modification occurred yet.
551  @return newest modification to page */
552 UNIV_INLINE
554  const buf_page_t *bpage); /*!< in: block containing the
555  page frame */
556 
557 /** Increment the modify clock.
558 The caller must
559 (1) own the buf_pool->mutex and block bufferfix count has to be zero,
560 (2) own X or SX latch on the block->lock, or
561 (3) operate on a thread-private temporary table
562 @param[in,out] block buffer block */
563 UNIV_INLINE
565 
566 /** Read the modify clock.
567 @param[in] block buffer block
568 @return modify_clock value */
569 UNIV_INLINE
570 uint64_t buf_block_get_modify_clock(const buf_block_t *block);
571 
572 /** Increments the bufferfix count.
573 @param[in] file file name
574 @param[in] line line
575 @param[in,out] block block to bufferfix */
576 UNIV_INLINE
578 #ifdef UNIV_DEBUG
579  const char *file, ulint line,
580 #endif /* UNIV_DEBUG */
581  buf_block_t *block);
582 
583 /** Increments the bufferfix count.
584 @param[in,out] bpage block to bufferfix
585 @return the count */
586 UNIV_INLINE
587 ulint buf_block_fix(buf_page_t *bpage);
588 
589 /** Increments the bufferfix count.
590 @param[in,out] block block to bufferfix
591 @return the count */
592 UNIV_INLINE
593 ulint buf_block_fix(buf_block_t *block);
594 
595 /** Decrements the bufferfix count.
596 @param[in,out] bpage block to bufferunfix
597 @return the remaining buffer-fix count */
598 UNIV_INLINE
599 ulint buf_block_unfix(buf_page_t *bpage);
600 #endif /* !UNIV_HOTBACKUP */
601 /** Decrements the bufferfix count.
602 @param[in,out] block block to bufferunfix
603 @return the remaining buffer-fix count */
604 UNIV_INLINE
605 ulint buf_block_unfix(buf_block_t *block);
606 
607 #ifndef UNIV_HOTBACKUP
608 /** Unfixes the page, unlatches the page,
609 removes it from page_hash and removes it from LRU.
610 @param[in,out] bpage pointer to the block */
612 
613 #ifdef UNIV_DEBUG
614 /** Increments the bufferfix count.
615 @param[in,out] b block to bufferfix
616 @param[in] f file name where requested
617 @param[in] l line number where requested */
618 #define buf_block_buf_fix_inc(b, f, l) buf_block_buf_fix_inc_func(f, l, b)
619 #else /* UNIV_DEBUG */
620 /** Increments the bufferfix count.
621 @param[in,out] b block to bufferfix
622 @param[in] f file name where requested
623 @param[in] l line number where requested */
624 #define buf_block_buf_fix_inc(b, f, l) buf_block_buf_fix_inc_func(b)
625 #endif /* UNIV_DEBUG */
626 #else /* !UNIV_HOTBACKUP */
627 #define buf_block_modify_clock_inc(block) ((void)0)
628 #endif /* !UNIV_HOTBACKUP */
629 
630 #ifndef UNIV_HOTBACKUP
631 
632 /** Gets the space id, page offset, and byte offset within page of a pointer
633 pointing to a buffer frame containing a file page.
634 @param[in] ptr pointer to a buffer frame
635 @param[out] space space id
636 @param[out] addr page offset and byte offset */
637 UNIV_INLINE
638 void buf_ptr_get_fsp_addr(const void *ptr, space_id_t *space, fil_addr_t *addr);
639 
640 /** Gets the hash value of a block. This can be used in searches in the
641  lock hash table.
642  @return lock hash value */
643 UNIV_INLINE
644 ulint buf_block_get_lock_hash_val(const buf_block_t *block) /*!< in: block */
645  MY_ATTRIBUTE((warn_unused_result));
646 #ifdef UNIV_DEBUG
647 /** Finds a block in the buffer pool that points to a
648 given compressed page. Used only to confirm that buffer pool does not contain a
649 given pointer, thus protected by zip_free_mutex.
650 @param[in] buf_pool buffer pool instance
651 @param[in] data pointer to compressed page
652 @return buffer block pointing to the compressed page, or NULL */
653 buf_block_t *buf_pool_contains_zip(buf_pool_t *buf_pool, const void *data);
654 #endif /* UNIV_DEBUG */
655 
656 /***********************************************************************
657 FIXME_FTS: Gets the frame the pointer is pointing to. */
658 UNIV_INLINE
660  /* out: pointer to frame */
661  byte *ptr); /* in: pointer to a frame */
662 
663 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
664 /** Validates the buffer pool data structure.
665  @return true */
666 ibool buf_validate(void);
667 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
668 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
669 /** Prints info of the buffer pool data structure. */
670 void buf_print(void);
671 #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
672 #endif /* !UNIV_HOTBACKUP */
674  /** Do not crash at the end of buf_page_print(). */
676  /** Do not print the full page dump. */
678 };
679 
680 /** Prints a page to stderr.
681 @param[in] read_buf a database page
682 @param[in] page_size page size
683 @param[in] flags 0 or BUF_PAGE_PRINT_NO_CRASH or
684 BUF_PAGE_PRINT_NO_FULL */
685 void buf_page_print(const byte *read_buf, const page_size_t &page_size,
686  ulint flags);
687 
688 /** Decompress a block.
689  @return true if successful */
690 ibool buf_zip_decompress(buf_block_t *block, /*!< in/out: block */
691  ibool check); /*!< in: TRUE=verify the page checksum */
692 #ifndef UNIV_HOTBACKUP
693 #ifdef UNIV_DEBUG
694 /** Returns the number of latched pages in the buffer pool.
695  @return number of latched pages */
696 ulint buf_get_latched_pages_number(void);
697 #endif /* UNIV_DEBUG */
698 /** Returns the number of pending buf pool read ios.
699  @return number of pending read I/O operations */
700 ulint buf_get_n_pending_read_ios(void);
701 /** Prints info of the buffer i/o. */
702 void buf_print_io(FILE *file); /*!< in: file where to print */
703 /** Collect buffer pool stats information for a buffer pool. Also
704  record aggregated stats if there are more than one buffer pool
705  in the server */
707  buf_pool_t *buf_pool, /*!< in: buffer pool */
708  ulint pool_id, /*!< in: buffer pool ID */
709  buf_pool_info_t *all_pool_info); /*!< in/out: buffer pool info
710  to fill */
711 /** Return the ratio in percents of modified pages in the buffer pool /
712 database pages in the buffer pool.
713 @return modified page percentage ratio */
714 double buf_get_modified_ratio_pct(void);
715 /** Refresh the statistics used to print per-second averages. */
717 
718 /** Assert that all file pages in the buffer are in a replaceable state. */
719 void buf_must_be_all_freed(void);
720 
721 /** Checks that there currently are no pending i/o-operations for the buffer
722 pool.
723 @return number of pending i/o */
724 ulint buf_pool_check_no_pending_io(void);
725 
726 /** Invalidates the file pages in the buffer pool when an archive recovery is
727  completed. All the file pages buffered must be in a replaceable state when
728  this function is called: not latched and not modified. */
729 void buf_pool_invalidate(void);
730 #endif /* !UNIV_HOTBACKUP */
731 
732 /*========================================================================
733 --------------------------- LOWER LEVEL ROUTINES -------------------------
734 =========================================================================*/
735 
736 #ifdef UNIV_DEBUG
737 /** Adds latch level info for the rw-lock protecting the buffer frame. This
738 should be called in the debug version after a successful latching of a page if
739 we know the latching order level of the acquired latch.
740 @param[in] block buffer page where we have acquired latch
741 @param[in] level latching order level */
742 UNIV_INLINE
744 #else /* UNIV_DEBUG */
745 #define buf_block_dbg_add_level(block, level) /* nothing */
746 #endif /* UNIV_DEBUG */
747 
748 /** Gets the state of a block.
749  @return state */
750 UNIV_INLINE
752  const buf_page_t *bpage); /*!< in: pointer to the control block */
753 /** Gets the state of a block.
754  @return state */
755 UNIV_INLINE
757  const buf_block_t *block) /*!< in: pointer to the control block */
758  MY_ATTRIBUTE((warn_unused_result));
759 
760 /** Sets the state of a block.
761 @param[in,out] bpage pointer to control block
762 @param[in] state state */
763 UNIV_INLINE
764 void buf_page_set_state(buf_page_t *bpage, enum buf_page_state state);
765 
766 /** Sets the state of a block.
767 @param[in,out] block pointer to control block
768 @param[in] state state */
769 UNIV_INLINE
770 void buf_block_set_state(buf_block_t *block, enum buf_page_state state);
771 
772 /** Determines if a block is mapped to a tablespace.
773  @return true if mapped */
774 UNIV_INLINE
775 ibool buf_page_in_file(
776  const buf_page_t *bpage) /*!< in: pointer to control block */
777  MY_ATTRIBUTE((warn_unused_result));
778 #ifndef UNIV_HOTBACKUP
779 /** Determines if a block should be on unzip_LRU list.
780  @return true if block belongs to unzip_LRU */
781 UNIV_INLINE
783  const buf_page_t *bpage) /*!< in: pointer to control block */
784  MY_ATTRIBUTE((warn_unused_result));
785 
786 /** Gets the mutex of a block.
787  @return pointer to mutex protecting bpage */
788 UNIV_INLINE
790  const buf_page_t *bpage) /*!< in: pointer to control block */
791  MY_ATTRIBUTE((warn_unused_result));
792 
793 /** Get the flush type of a page.
794  @return flush type */
795 UNIV_INLINE
797  const buf_page_t *bpage) /*!< in: buffer page */
798  MY_ATTRIBUTE((warn_unused_result));
799 
800 /** Set the flush type of a page.
801 @param[in] bpage buffer page
802 @param[in] flush_type flush type */
803 UNIV_INLINE
805 
806 /** Map a block to a file page.
807 @param[in,out] block pointer to control block
808 @param[in] page_id page id */
809 UNIV_INLINE
810 void buf_block_set_file_page(buf_block_t *block, const page_id_t &page_id);
811 
812 /** Gets the io_fix state of a block.
813  @return io_fix state */
814 UNIV_INLINE
816  const buf_page_t *bpage) /*!< in: pointer to the control block */
817  MY_ATTRIBUTE((warn_unused_result));
818 /** Gets the io_fix state of a block.
819  @return io_fix state */
820 UNIV_INLINE
822  const buf_block_t *block) /*!< in: pointer to the control block */
823  MY_ATTRIBUTE((warn_unused_result));
824 
825 /** Sets the io_fix state of a block.
826 @param[in,out] bpage control block
827 @param[in] io_fix io_fix state */
828 UNIV_INLINE
829 void buf_page_set_io_fix(buf_page_t *bpage, enum buf_io_fix io_fix);
830 
831 /** Sets the io_fix state of a block.
832 @param[in,out] block control block
833 @param[in] io_fix io_fix state */
834 UNIV_INLINE
835 void buf_block_set_io_fix(buf_block_t *block, enum buf_io_fix io_fix);
836 
837 /** Makes a block sticky. A sticky block implies that even after we release
838 the buf_pool->LRU_list_mutex and the block->mutex:
839 * it cannot be removed from the flush_list
840 * the block descriptor cannot be relocated
841 * it cannot be removed from the LRU list
842 Note that:
843 * the block can still change its position in the LRU list
844 * the next and previous pointers can change.
845 @param[in,out] bpage control block */
846 UNIV_INLINE
847 void buf_page_set_sticky(buf_page_t *bpage);
848 
849 /** Removes stickiness of a block. */
850 UNIV_INLINE
851 void buf_page_unset_sticky(buf_page_t *bpage); /*!< in/out: control block */
852 /** Determine if a buffer block can be relocated in memory. The block
853  can be dirty, but it must not be I/O-fixed or bufferfixed. */
854 UNIV_INLINE
856  const buf_page_t *bpage) /*!< control block being relocated */
857  MY_ATTRIBUTE((warn_unused_result));
858 
859 /** Determine if a block has been flagged old.
860 @param[in] bpage control block
861 @return true if old */
862 UNIV_INLINE
863 ibool buf_page_is_old(const buf_page_t *bpage)
864  MY_ATTRIBUTE((warn_unused_result));
865 
866 /** Flag a block old.
867 @param[in,out] bpage control block
868 @param[in] old old */
869 UNIV_INLINE
870 void buf_page_set_old(buf_page_t *bpage, ibool old);
871 
872 /** Determine the time of first access of a block in the buffer pool.
873  @return ut_time_monotonic_ms() at the time of first access, 0 if not accessed
874  */
875 UNIV_INLINE
876 unsigned buf_page_is_accessed(const buf_page_t *bpage) /*!< in: control block */
877  MY_ATTRIBUTE((warn_unused_result));
878 /** Flag a block accessed. */
879 UNIV_INLINE
880 void buf_page_set_accessed(buf_page_t *bpage); /*!< in/out: control block */
881 
882 /** Gets the buf_block_t handle of a buffered file block if an uncompressed
883 page frame exists, or NULL. page frame exists, or NULL. The caller must hold
884 either the appropriate hash lock in any mode, either the LRU list mutex. Note:
885 even though bpage is not declared a const we don't update its value. It is safe
886 to make this pure.
887 @param[in] bpage control block, or NULL
888 @return control block, or NULL */
889 UNIV_INLINE
891  MY_ATTRIBUTE((warn_unused_result));
892 #ifdef UNIV_DEBUG
893 /** Gets a pointer to the memory frame of a block.
894  @return pointer to the frame */
895 UNIV_INLINE
897  const buf_block_t *block) /*!< in: pointer to the control block */
898  MY_ATTRIBUTE((warn_unused_result));
899 #else /* UNIV_DEBUG */
900 #define buf_block_get_frame(block) (block)->frame
901 #endif /* UNIV_DEBUG */
902 #else /* !UNIV_HOTBACKUP */
903 #define buf_block_get_frame(block) (block)->frame
904 #endif /* !UNIV_HOTBACKUP */
905 /** Gets the compressed page descriptor corresponding to an uncompressed page
906  if applicable. */
907 #define buf_block_get_page_zip(block) \
908  ((block)->page.zip.data ? &(block)->page.zip : NULL)
909 
910 /** Get a buffer block from an adaptive hash index pointer.
911 This function does not return if the block is not identified.
912 @param[in] ptr pointer to within a page frame
913 @return pointer to block, never NULL */
914 buf_block_t *buf_block_from_ahi(const byte *ptr);
915 
916 #ifndef UNIV_HOTBACKUP
917 /** Find out if a pointer belongs to a buf_block_t. It can be a pointer to
918  the buf_block_t itself or a member of it
919  @return true if ptr belongs to a buf_block_t struct */
920 ibool buf_pointer_is_block_field(const void *ptr); /*!< in: pointer not
921  dereferenced */
922 /** Find out if a pointer corresponds to a buf_block_t::mutex.
923 @param m in: mutex candidate
924 @return true if m is a buf_block_t::mutex */
925 #define buf_pool_is_block_mutex(m) buf_pointer_is_block_field((const void *)(m))
926 /** Find out if a pointer corresponds to a buf_block_t::lock.
927 @param l in: rw-lock candidate
928 @return true if l is a buf_block_t::lock */
929 #define buf_pool_is_block_lock(l) buf_pointer_is_block_field((const void *)(l))
930 
931 /** Inits a page for read to the buffer buf_pool. If the page is
932 (1) already in buf_pool, or
933 (2) if we specify to read only ibuf pages and the page is not an ibuf page, or
934 (3) if the space is deleted or being deleted,
935 then this function does nothing.
936 Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
937 on the buffer frame. The io-handler must take care that the flag is cleared
938 and the lock released later.
939 @param[out] err DB_SUCCESS or DB_TABLESPACE_DELETED
940 @param[in] mode BUF_READ_IBUF_PAGES_ONLY, ...
941 @param[in] page_id page id
942 @param[in] page_size page size
943 @param[in] unzip TRUE=request uncompressed page
944 @return pointer to the block or NULL */
946  const page_id_t &page_id,
947  const page_size_t &page_size, ibool unzip);
948 
949 /** Completes an asynchronous read or write request of a file page to or from
950 the buffer pool.
951 @param[in] bpage pointer to the block in question
952 @param[in] evict whether or not to evict the page from LRU list
953 @return true if successful */
954 bool buf_page_io_complete(buf_page_t *bpage, bool evict = false);
955 
956 /** Calculates the index of a buffer pool to the buf_pool[] array.
957  @return the position of the buffer pool in buf_pool[] */
958 UNIV_INLINE
959 ulint buf_pool_index(const buf_pool_t *buf_pool) /*!< in: buffer pool */
960  MY_ATTRIBUTE((warn_unused_result));
961 /** Returns the buffer pool instance given a page instance
962  @return buf_pool */
963 UNIV_INLINE
965  const buf_page_t *bpage); /*!< in: buffer pool page */
966 /** Returns the buffer pool instance given a block instance
967  @return buf_pool */
968 UNIV_INLINE
969 buf_pool_t *buf_pool_from_block(const buf_block_t *block); /*!< in: block */
970 
971 /** Returns the buffer pool instance given a page id.
972 @param[in] page_id page id
973 @return buffer pool */
974 UNIV_INLINE
975 buf_pool_t *buf_pool_get(const page_id_t &page_id);
976 
977 /** Returns the buffer pool instance given its array index
978  @return buffer pool */
979 UNIV_INLINE
980 buf_pool_t *buf_pool_from_array(ulint index); /*!< in: array index to get
981  buffer pool instance from */
982 
983 /** Returns the control block of a file page, NULL if not found.
984 @param[in] buf_pool buffer pool instance
985 @param[in] page_id page id
986 @return block, NULL if not found */
987 UNIV_INLINE
989  const page_id_t &page_id);
990 
991 /** Returns the control block of a file page, NULL if not found.
992 If the block is found and lock is not NULL then the appropriate
993 page_hash lock is acquired in the specified lock mode. Otherwise,
994 mode value is ignored. It is up to the caller to release the
995 lock. If the block is found and the lock is NULL then the page_hash
996 lock is released by this function.
997 @param[in] buf_pool buffer pool instance
998 @param[in] page_id page id
999 @param[in,out] lock lock of the page hash acquired if bpage is
1000 found, NULL otherwise. If NULL is passed then the hash_lock is released by
1001 this function.
1002 @param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
1003 lock == NULL
1004 @param[in] watch if true, return watch sentinel also.
1005 @return pointer to the bpage or NULL; if NULL, lock is also NULL or
1006 a watch sentinel. */
1007 UNIV_INLINE
1009  const page_id_t &page_id, rw_lock_t **lock,
1010  ulint lock_mode, bool watch = false);
1011 
1012 /** Returns the control block of a file page, NULL if not found.
1013 If the block is found and lock is not NULL then the appropriate
1014 page_hash lock is acquired in the specified lock mode. Otherwise,
1015 mode value is ignored. It is up to the caller to release the
1016 lock. If the block is found and the lock is NULL then the page_hash
1017 lock is released by this function.
1018 @param[in] buf_pool buffer pool instance
1019 @param[in] page_id page id
1020 @param[in,out] lock lock of the page hash acquired if bpage is
1021 found, NULL otherwise. If NULL is passed then the hash_lock is released by
1022 this function.
1023 @param[in] lock_mode RW_LOCK_X or RW_LOCK_S. Ignored if
1024 lock == NULL
1025 @return pointer to the block or NULL; if NULL, lock is also NULL. */
1026 UNIV_INLINE
1028  const page_id_t &page_id,
1029  rw_lock_t **lock, ulint lock_mode);
1030 
1031 /* There are four different ways we can try to get a bpage or block
1032 from the page hash:
1033 1) Caller already holds the appropriate page hash lock: in the case call
1034 buf_page_hash_get_low() function.
1035 2) Caller wants to hold page hash lock in x-mode
1036 3) Caller wants to hold page hash lock in s-mode
1037 4) Caller doesn't want to hold page hash lock */
1038 #define buf_page_hash_get_s_locked(b, page_id, l) \
1039  buf_page_hash_get_locked(b, page_id, l, RW_LOCK_S)
1040 #define buf_page_hash_get_x_locked(b, page_id, l) \
1041  buf_page_hash_get_locked(b, page_id, l, RW_LOCK_X)
1042 #define buf_page_hash_get(b, page_id) \
1043  buf_page_hash_get_locked(b, page_id, NULL, 0)
1044 #define buf_page_get_also_watch(b, page_id) \
1045  buf_page_hash_get_locked(b, page_id, NULL, 0, true)
1046 
1047 #define buf_block_hash_get_s_locked(b, page_id, l) \
1048  buf_block_hash_get_locked(b, page_id, l, RW_LOCK_S)
1049 #define buf_block_hash_get_x_locked(b, page_id, l) \
1050  buf_block_hash_get_locked(b, page_id, l, RW_LOCK_X)
1051 #define buf_block_hash_get(b, page_id) \
1052  buf_block_hash_get_locked(b, page_id, NULL, 0)
1053 
1054 /** Gets the current length of the free list of buffer blocks.
1055  @return length of the free list */
1056 ulint buf_get_free_list_len(void);
1057 
1058 /** Determine if a block is a sentinel for a buffer pool watch.
1059  @return true if a sentinel for a buffer pool watch, false if not */
1061  const buf_pool_t *buf_pool, /*!< buffer pool instance */
1062  const buf_page_t *bpage) /*!< in: block */
1063  MY_ATTRIBUTE((warn_unused_result));
1064 
1065 /** Stop watching if the page has been read in.
1066 buf_pool_watch_set(space,offset) must have returned NULL before.
1067 @param[in] page_id page id */
1068 void buf_pool_watch_unset(const page_id_t &page_id);
1069 
1070 /** Check if the page has been read in.
1071 This may only be called after buf_pool_watch_set(space,offset)
1072 has returned NULL and before invoking buf_pool_watch_unset(space,offset).
1073 @param[in] page_id page id
1074 @return false if the given page was not read in, true if it was */
1075 ibool buf_pool_watch_occurred(const page_id_t &page_id)
1076  MY_ATTRIBUTE((warn_unused_result));
1077 
1078 /** Get total buffer pool statistics. */
1080  ulint *LRU_len, /*!< out: length of all LRU lists */
1081  ulint *free_len, /*!< out: length of all free lists */
1082  ulint *flush_list_len); /*!< out: length of all flush lists */
1083 /** Get total list size in bytes from all buffer pools. */
1085  buf_pools_list_size_t *buf_pools_list_size); /*!< out: list sizes
1086  in all buffer pools */
1087 /** Get total buffer pool statistics. */
1088 void buf_get_total_stat(
1089  buf_pool_stat_t *tot_stat); /*!< out: buffer pool stats */
1090 
1091 /** Get the nth chunk's buffer block in the specified buffer pool.
1092 @param[in] buf_pool buffer pool instance
1093 @param[in] n nth chunk in the buffer pool
1094 @param[in] chunk_size chunk_size
1095 @return the nth chunk's buffer block. */
1096 UNIV_INLINE
1097 buf_block_t *buf_get_nth_chunk_block(const buf_pool_t *buf_pool, ulint n,
1098  ulint *chunk_size);
1099 
1100 /** Verify the possibility that a stored page is not in buffer pool.
1101 @param[in] withdraw_clock withdraw clock when stored the page
1102 @retval true if the page might be relocated */
1103 UNIV_INLINE
1104 bool buf_pool_is_obsolete(ulint withdraw_clock);
1105 
1106 /** Calculate aligned buffer pool size based on srv_buf_pool_chunk_unit,
1107 if needed.
1108 @param[in] size size in bytes
1109 @return aligned size */
1110 UNIV_INLINE
1111 ulint buf_pool_size_align(ulint size);
1112 
1113 /** Adjust the proposed chunk unit size so that it satisfies all invariants
1114 @param[in] size proposed size of buffer pool chunk unit in bytes
1115 @return adjusted size which meets invariants */
1117 
1118 /** Calculate the checksum of a page from compressed table and update the
1119 page.
1120 @param[in,out] page page to update
1121 @param[in] size compressed page size
1122 @param[in] lsn LSN to stamp on the page
1123 @param[in] skip_lsn_check true to skip check for lsn (in DEBUG) */
1125  bool skip_lsn_check);
1126 
1127 #endif /* !UNIV_HOTBACKUP */
1128 
1129 /** Return how many more pages must be added to the withdraw list to reach the
1130 withdraw target of the currently ongoing buffer pool resize.
1131 @param[in] buf_pool buffer pool instance
1132 @return page count to be withdrawn or zero if the target is already achieved or
1133 if the buffer pool is not currently being resized. */
1134 UNIV_INLINE
1135 ulint buf_get_withdraw_depth(buf_pool_t *buf_pool);
1136 
1137 /** Gets the io_fix state of a buffer block. Does not assert that the
1138 buf_page_get_mutex() mutex is held, to be used in the cases where it is safe
1139 not to hold it.
1140 @param[in] block pointer to the buffer block
1141 @return page io_fix state */
1142 UNIV_INLINE
1144  MY_ATTRIBUTE((warn_unused_result));
1145 
1146 /** Gets the io_fix state of a buffer page. Does not assert that the
1147 buf_page_get_mutex() mutex is held, to be used in the cases where it is safe
1148 not to hold it.
1149 @param[in] bpage pointer to the buffer page
1150 @return page io_fix state */
1151 UNIV_INLINE
1153  MY_ATTRIBUTE((warn_unused_result));
1154 
1155 /** The common buffer control block structure
1156 for compressed and uncompressed frames */
1157 
1158 /** Number of bits used for buffer page states. */
1159 #define BUF_PAGE_STATE_BITS 3
1160 
1161 class buf_page_t {
1162  public:
1163  /** @name General fields
1164  None of these bit-fields must be modified without holding
1165  buf_page_get_mutex() [buf_block_t::mutex or
1166  buf_pool->zip_mutex], since they can be stored in the same
1167  machine word. */
1168  /* @{ */
1169 
1170  /** Page id. */
1172 
1173  /** Page size. */
1175 
1176  /** Count of how manyfold this block is currently bufferfixed. */
1177  uint32_t buf_fix_count;
1178 
1179  /** type of pending I/O operation. */
1181 
1182  /** Block state. @see buf_page_in_file */
1184 
1185  /** if this block is currently being flushed to disk, this tells
1186  the flush_type. @see buf_flush_t */
1187  unsigned flush_type : 2;
1188 
1189  /** index number of the buffer pool that this block belongs to */
1190  unsigned buf_pool_index : 6;
1191 
1192  static_assert(MAX_BUFFER_POOLS <= 64,
1193  "MAX_BUFFER_POOLS > 64; redefine buf_pool_index");
1194 
1195  /* @} */
1196  page_zip_des_t zip; /*!< compressed page; zip.data
1197  (but not the data it points to) is
1198  protected by buf_pool->zip_mutex;
1199  state == BUF_BLOCK_ZIP_PAGE and
1200  zip.data == NULL means an active
1201  buf_pool->watch */
1202 #ifndef UNIV_HOTBACKUP
1203  buf_page_t *hash; /*!< node used in chaining to
1204  buf_pool->page_hash or
1205  buf_pool->zip_hash */
1206 #endif /* !UNIV_HOTBACKUP */
1207 #ifdef UNIV_DEBUG
1208  ibool in_page_hash; /*!< TRUE if in buf_pool->page_hash */
1209  ibool in_zip_hash; /*!< TRUE if in buf_pool->zip_hash */
1210 #endif /* UNIV_DEBUG */
1211 
1212  /** @name Page flushing fields
1213  All these are protected by buf_pool->mutex. */
1214  /* @{ */
1215 
1217  /*!< based on state, this is a
1218  list node, protected by the
1219  corresponding list mutex, in one of the
1220  following lists in buf_pool:
1221 
1222  - BUF_BLOCK_NOT_USED: free, withdraw
1223  - BUF_BLOCK_FILE_PAGE: flush_list
1224  - BUF_BLOCK_ZIP_DIRTY: flush_list
1225  - BUF_BLOCK_ZIP_PAGE: zip_clean
1226 
1227  The node pointers are protected by the
1228  corresponding list mutex.
1229 
1230  The contents of the list node
1231  is undefined if !in_flush_list
1232  && state == BUF_BLOCK_FILE_PAGE,
1233  or if state is one of
1234  BUF_BLOCK_MEMORY,
1235  BUF_BLOCK_REMOVE_HASH or
1236  BUF_BLOCK_READY_IN_USE. */
1237 
1238 #ifdef UNIV_DEBUG
1239  ibool in_flush_list; /*!< TRUE if in buf_pool->flush_list;
1240  when buf_pool->flush_list_mutex is
1241  free, the following should hold:
1242  in_flush_list
1243  == (state == BUF_BLOCK_FILE_PAGE
1244  || state == BUF_BLOCK_ZIP_DIRTY)
1245  Writes to this field must be
1246  covered by both block->mutex
1247  and buf_pool->flush_list_mutex. Hence
1248  reads can happen while holding
1249  any one of the two mutexes */
1250  ibool in_free_list; /*!< TRUE if in buf_pool->free; when
1251  buf_pool->free_list_mutex is free, the
1252  following should hold: in_free_list
1253  == (state == BUF_BLOCK_NOT_USED) */
1254 #endif /* UNIV_DEBUG */
1255 
1256  FlushObserver *flush_observer; /*!< flush observer */
1257 
1259  /*!< log sequence number of
1260  the youngest modification to
1261  this block, zero if not
1262  modified. Protected by block
1263  mutex */
1265  /*!< log sequence number of
1266  the START of the log entry
1267  written of the oldest
1268  modification to this block
1269  which has not yet been flushed
1270  on disk; zero if all
1271  modifications are on disk.
1272  Writes to this field must be
1273  covered by both block->mutex
1274  and buf_pool->flush_list_mutex. Hence
1275  reads can happen while holding
1276  any one of the two mutexes */
1277  /* @} */
1278  /** @name LRU replacement algorithm fields
1279  These fields are protected by both buf_pool->LRU_list_mutex and the
1280  block mutex. */
1281  /* @{ */
1282 
1284  /*!< node of the LRU list */
1285 #ifdef UNIV_DEBUG
1286  ibool in_LRU_list; /*!< TRUE if the page is in
1287  the LRU list; used in
1288  debugging */
1289 #endif /* UNIV_DEBUG */
1290 #ifndef UNIV_HOTBACKUP
1291  unsigned old : 1; /*!< TRUE if the block is in the old
1292  blocks in buf_pool->LRU_old */
1293  unsigned freed_page_clock : 31; /*!< the value of
1294  buf_pool->freed_page_clock
1295  when this block was the last
1296  time put to the head of the
1297  LRU list; a thread is allowed
1298  to read this for heuristic
1299  purposes without holding any
1300  mutex or latch */
1301  /* @} */
1302  unsigned access_time; /*!< time of first access, or
1303  0 if the block was never accessed
1304  in the buffer pool. Protected by
1305  block mutex */
1306 #ifdef UNIV_DEBUG
1308  /*!< this is set to TRUE when
1309  fsp frees a page in buffer pool;
1310  protected by buf_pool->zip_mutex
1311  or buf_block_t::mutex. */
1312 #endif /* UNIV_DEBUG */
1313 #endif /* !UNIV_HOTBACKUP */
1314 };
1315 
1316 /** The buffer control block structure */
1317 
1318 struct buf_block_t {
1319  /** @name General fields */
1320  /* @{ */
1321 
1322  buf_page_t page; /*!< page information; this must
1323  be the first field, so that
1324  buf_pool->page_hash can point
1325  to buf_page_t or buf_block_t */
1326  byte *frame; /*!< pointer to buffer frame which
1327  is of size UNIV_PAGE_SIZE, and
1328  aligned to an address divisible by
1329  UNIV_PAGE_SIZE */
1330 #ifndef UNIV_HOTBACKUP
1331  BPageLock lock; /*!< read-write lock of the buffer
1332  frame */
1333 #endif /* UNIV_HOTBACKUP */
1334  UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1335  /*!< node of the decompressed LRU list;
1336  a block is in the unzip_LRU list
1337  if page.state == BUF_BLOCK_FILE_PAGE
1338  and page.zip.data != NULL. Protected by
1339  both LRU_list_mutex and the block
1340  mutex. */
1341 #ifdef UNIV_DEBUG
1342  ibool in_unzip_LRU_list; /*!< TRUE if the page is in the
1343  decompressed LRU list;
1344  used in debugging */
1346 #endif /* UNIV_DEBUG */
1347  unsigned lock_hash_val : 32; /*!< hashed value of the page address
1348  in the record lock hash table;
1349  protected by buf_block_t::lock
1350  (or buf_block_t::mutex in
1351  buf_page_get_gen(),
1352  buf_page_init_for_read()
1353  and buf_page_create()) */
1354  /* @} */
1355  /** @name Optimistic search field */
1356  /* @{ */
1357 
1358  uint64_t modify_clock; /*!< this clock is incremented every
1359  time a pointer to a record on the
1360  page may become obsolete; this is
1361  used in the optimistic cursor
1362  positioning: if the modify clock has
1363  not changed, we know that the pointer
1364  is still valid; this field may be
1365  changed if the thread (1) owns the LRU
1366  list mutex and the page is not
1367  bufferfixed, or (2) the thread has an
1368  x-latch on the block, or (3) the block
1369  must belong to an intrinsic table */
1370  /* @} */
1371  /** @name Hash search fields (unprotected)
1372  NOTE that these fields are NOT protected by any semaphore! */
1373  /* @{ */
1374 
1375  ulint n_hash_helps; /*!< counter which controls building
1376  of a new hash index for the page */
1377  volatile ulint n_bytes; /*!< recommended prefix length for hash
1378  search: number of bytes in
1379  an incomplete last field */
1380  volatile ulint n_fields; /*!< recommended prefix length for hash
1381  search: number of full fields */
1382  volatile bool left_side; /*!< true or false, depending on
1383  whether the leftmost record of several
1384  records with the same prefix should be
1385  indexed in the hash index */
1386  /* @} */
1387 
1388  /** @name Hash search fields
1389  These 5 fields may only be modified when:
1390  we are holding the appropriate x-latch in btr_search_latches[], and
1391  one of the following holds:
1392  (1) the block state is BUF_BLOCK_FILE_PAGE, and
1393  we are holding an s-latch or x-latch on buf_block_t::lock, or
1394  (2) buf_block_t::buf_fix_count == 0, or
1395  (3) the block state is BUF_BLOCK_REMOVE_HASH.
1396 
1397  An exception to this is when we init or create a page
1398  in the buffer pool in buf0buf.cc.
1399 
1400  Another exception for buf_pool_clear_hash_index() is that
1401  assigning block->index = NULL (and block->n_pointers = 0)
1402  is allowed whenever btr_search_own_all(RW_LOCK_X).
1403 
1404  Another exception is that ha_insert_for_fold_func() may
1405  decrement n_pointers without holding the appropriate latch
1406  in btr_search_latches[]. Thus, n_pointers must be
1407  protected by atomic memory access.
1408 
1409  This implies that the fields may be read without race
1410  condition whenever any of the following hold:
1411  - the btr_search_latches[] s-latch or x-latch is being held, or
1412  - the block state is not BUF_BLOCK_FILE_PAGE or BUF_BLOCK_REMOVE_HASH,
1413  and holding some latch prevents the state from changing to that.
1414 
1415  Some use of assert_block_ahi_empty() or assert_block_ahi_valid()
1416  is prone to race conditions while buf_pool_clear_hash_index() is
1417  executing (the adaptive hash index is being disabled). Such use
1418  is explicitly commented. */
1419 
1420  /* @{ */
1421 
1422 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1423  ulint n_pointers; /*!< used in debugging: the number of
1424  pointers in the adaptive hash index
1425  pointing to this frame;
1426  protected by atomic memory access
1427  or btr_search_own_all(). */
1428 #define assert_block_ahi_empty(block) \
1429  ut_a(os_atomic_increment_ulint(&(block)->n_pointers, 0) == 0)
1430 #define assert_block_ahi_empty_on_init(block) \
1431  do { \
1432  UNIV_MEM_VALID(&(block)->n_pointers, sizeof(block)->n_pointers); \
1433  assert_block_ahi_empty(block); \
1434  } while (0)
1435 #define assert_block_ahi_valid(block) \
1436  ut_a((block)->index || \
1437  os_atomic_increment_ulint(&(block)->n_pointers, 0) == 0)
1438 #else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1439 #define assert_block_ahi_empty(block) /* nothing */
1440 #define assert_block_ahi_empty_on_init(block) /* nothing */
1441 #define assert_block_ahi_valid(block) /* nothing */
1442 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1443  unsigned curr_n_fields : 10; /*!< prefix length for hash indexing:
1444  number of full fields */
1445  unsigned curr_n_bytes : 15; /*!< number of bytes in hash
1446  indexing */
1447  unsigned curr_left_side : 1; /*!< TRUE or FALSE in hash indexing */
1448  dict_index_t *index; /*!< Index for which the
1449  adaptive hash index has been
1450  created, or NULL if the page
1451  does not exist in the
1452  index. Note that it does not
1453  guarantee that the index is
1454  complete, though: there may
1455  have been hash collisions,
1456  record deletions, etc. */
1457  /* @} */
1459  /*!< true if block has been made dirty
1460  without acquiring X/SX latch as the
1461  block belongs to temporary tablespace
1462  and block is always accessed by a
1463  single thread. */
1464 #ifndef UNIV_HOTBACKUP
1465 #ifdef UNIV_DEBUG
1466  /** @name Debug fields */
1467  /* @{ */
1468  rw_lock_t debug_latch; /*!< in the debug version, each thread
1469  which bufferfixes the block acquires
1470  an s-latch here; so we can use the
1471  debug utilities in sync0rw */
1472  /* @} */
1473 #endif /* UNIV_DEBUG */
1474 #endif /* !UNIV_HOTBACKUP */
1475  BPageMutex mutex; /*!< mutex protecting this block:
1476  state (also protected by the buffer
1477  pool mutex), io_fix, buf_fix_count,
1478  and accessed; we introduce this new
1479  mutex in InnoDB-5.1 to relieve
1480  contention on the buffer pool mutex */
1481 
1482  /** Get the page number of the current buffer block.
1483  @return page number of the current buffer block. */
1484  page_no_t get_page_no() const { return (page.id.page_no()); }
1485 
1486  /** Get the next page number of the current buffer block.
1487  @return next page number of the current buffer block. */
1489  return (mach_read_from_4(frame + FIL_PAGE_NEXT));
1490  }
1491 
1492  /** Get the prev page number of the current buffer block.
1493  @return prev page number of the current buffer block. */
1495  return (mach_read_from_4(frame + FIL_PAGE_PREV));
1496  }
1497 
1498  /** Get the page type of the current buffer block.
1499  @return page type of the current buffer block. */
1501  return (mach_read_from_2(frame + FIL_PAGE_TYPE));
1502  }
1503 
1504  /** Get the page type of the current buffer block as string.
1505  @return page type of the current buffer block as string. */
1506  const char *get_page_type_str() const;
1507 };
1508 
1509 /** Check if a buf_block_t object is in a valid state
1510 @param block buffer block
1511 @return true if valid */
1512 #define buf_block_state_valid(block) \
1513  (buf_block_get_state(block) >= BUF_BLOCK_NOT_USED && \
1514  (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1515 
1516 /** Compute the hash fold value for blocks in buf_pool->zip_hash. */
1517 /* @{ */
1518 #define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint)(ptr) / UNIV_PAGE_SIZE)
1519 #define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1520 #define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t *)(b))
1521 /* @} */
1522 
1523 /** A "Hazard Pointer" class used to iterate over page lists
1524 inside the buffer pool. A hazard pointer is a buf_page_t pointer
1525 which we intend to iterate over next and we want it remain valid
1526 even after we release the buffer pool mutex. */
1528  public:
1529  /** Constructor
1530  @param buf_pool buffer pool instance
1531  @param mutex mutex that is protecting the hp. */
1532  HazardPointer(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1533  : m_buf_pool(buf_pool)
1534 #ifdef UNIV_DEBUG
1535  ,
1536  m_mutex(mutex)
1537 #endif /* UNIV_DEBUG */
1538  ,
1539  m_hp() {
1540  }
1541 
1542  /** Destructor */
1543  virtual ~HazardPointer() {}
1544 
1545  /** Get current value */
1546  buf_page_t *get() const {
1548  return (m_hp);
1549  }
1550 
1551  /** Set current value
1552  @param bpage buffer block to be set as hp */
1553  void set(buf_page_t *bpage);
1554 
1555  /** Checks if a bpage is the hp
1556  @param bpage buffer block to be compared
1557  @return true if it is hp */
1558  bool is_hp(const buf_page_t *bpage);
1559 
1560  /** Adjust the value of hp. This happens when some
1561  other thread working on the same list attempts to
1562  remove the hp from the list. Must be implemented
1563  by the derived classes.
1564  @param bpage buffer block to be compared */
1565  virtual void adjust(const buf_page_t *bpage) = 0;
1566 
1567  protected:
1568  /** Disable copying */
1569  HazardPointer(const HazardPointer &);
1571 
1572  /** Buffer pool instance */
1574 
1575 #ifdef UNIV_DEBUG
1576  /** mutex that protects access to the m_hp. */
1577  const ib_mutex_t *m_mutex;
1578 #endif /* UNIV_DEBUG */
1579 
1580  /** hazard pointer. */
1582 };
1583 
1584 /** Class implementing buf_pool->flush_list hazard pointer */
1585 class FlushHp : public HazardPointer {
1586  public:
1587  /** Constructor
1588  @param buf_pool buffer pool instance
1589  @param mutex mutex that is protecting the hp. */
1590  FlushHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1591  : HazardPointer(buf_pool, mutex) {}
1592 
1593  /** Destructor */
1594  virtual ~FlushHp() {}
1595 
1596  /** Adjust the value of hp. This happens when some
1597  other thread working on the same list attempts to
1598  remove the hp from the list.
1599  @param bpage buffer block to be compared */
1600  void adjust(const buf_page_t *bpage);
1601 };
1602 
1603 /** Class implementing buf_pool->LRU hazard pointer */
1604 class LRUHp : public HazardPointer {
1605  public:
1606  /** Constructor
1607  @param buf_pool buffer pool instance
1608  @param mutex mutex that is protecting the hp. */
1609  LRUHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1610  : HazardPointer(buf_pool, mutex) {}
1611 
1612  /** Destructor */
1613  virtual ~LRUHp() {}
1614 
1615  /** Adjust the value of hp. This happens when some
1616  other thread working on the same list attempts to
1617  remove the hp from the list.
1618  @param bpage buffer block to be compared */
1619  void adjust(const buf_page_t *bpage);
1620 };
1621 
1622 /** Special purpose iterators to be used when scanning the LRU list.
1623 The idea is that when one thread finishes the scan it leaves the
1624 itr in that position and the other thread can start scan from
1625 there */
1626 class LRUItr : public LRUHp {
1627  public:
1628  /** Constructor
1629  @param buf_pool buffer pool instance
1630  @param mutex mutex that is protecting the hp. */
1631  LRUItr(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
1632  : LRUHp(buf_pool, mutex) {}
1633 
1634  /** Destructor */
1635  virtual ~LRUItr() {}
1636 
1637  /** Selects from where to start a scan. If we have scanned
1638  too deep into the LRU list it resets the value to the tail
1639  of the LRU list.
1640  @return buf_page_t from where to start scan. */
1641  buf_page_t *start();
1642 };
1643 
1644 /** Struct that is embedded in the free zip blocks */
1646  union {
1647  ulint size; /*!< size of the block */
1649  /*!< stamp[FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID]
1650  == BUF_BUDDY_FREE_STAMP denotes a free
1651  block. If the space_id field of buddy
1652  block != BUF_BUDDY_FREE_STAMP, the block
1653  is not in any zip_free list. If the
1654  space_id is BUF_BUDDY_FREE_STAMP then
1655  stamp[0] will contain the
1656  buddy block size. */
1657  } stamp;
1658 
1659  buf_page_t bpage; /*!< Embedded bpage descriptor */
1661  /*!< Node of zip_free list */
1662 };
1663 
1664 /** @brief The buffer pool statistics structure. */
1666  ulint n_page_gets; /*!< number of page gets performed;
1667  also successful searches through
1668  the adaptive hash index are
1669  counted as page gets; this field
1670  is NOT protected by the buffer
1671  pool mutex */
1672  ulint n_pages_read; /*!< number of read operations. Accessed
1673  atomically. */
1674  ulint n_pages_written; /*!< number of write operations. Accessed
1675  atomically. */
1676  ulint n_pages_created; /*!< number of pages created
1677  in the pool with no read. Accessed
1678  atomically. */
1679  ulint n_ra_pages_read_rnd; /*!< number of pages read in
1680  as part of random read ahead. Not protected. */
1681  ulint n_ra_pages_read; /*!< number of pages read in
1682  as part of read ahead. Not protected. */
1683  ulint n_ra_pages_evicted; /*!< number of read ahead
1684  pages that are evicted without
1685  being accessed. Protected by LRU_list_mutex. */
1686  ulint n_pages_made_young; /*!< number of pages made young, in
1687  calls to buf_LRU_make_block_young(). Protected
1688  by LRU_list_mutex. */
1689  ulint n_pages_not_made_young; /*!< number of pages not made
1690  young because the first access
1691  was not long enough ago, in
1692  buf_page_peek_if_too_old(). Not protected. */
1693  ulint LRU_bytes; /*!< LRU size in bytes. Protected by
1694  LRU_list_mutex. */
1695  ulint flush_list_bytes; /*!< flush_list size in bytes.
1696  Protected by flush_list_mutex */
1697 };
1698 
1699 /** Statistics of buddy blocks of a given size. */
1701  /** Number of blocks allocated from the buddy system. */
1702  ulint used;
1703  /** Number of blocks relocated by the buddy system. */
1704  uint64_t relocated;
1705  /** Total duration of block relocations, in microseconds. */
1706  uint64_t relocated_usec;
1707 };
1708 
1709 /** @brief The buffer pool structure.
1710 
1711 NOTE! The definition appears here only for other modules of this
1712 directory (buf) to see it. Do not use from outside! */
1713 
1714 struct buf_pool_t {
1715  /** @name General fields */
1716  /* @{ */
1717  BufListMutex chunks_mutex; /*!< protects (de)allocation of chunks:
1718  - changes to chunks, n_chunks are performed
1719  while holding this latch,
1720  - reading buf_pool_should_madvise requires
1721  holding this latch for any buf_pool_t
1722  - writing to buf_pool_should_madvise requires
1723  holding these latches for all buf_pool_t-s
1724  */
1725  BufListMutex LRU_list_mutex; /*!< LRU list mutex */
1726  BufListMutex free_list_mutex; /*!< free and withdraw list mutex */
1727  BufListMutex zip_free_mutex; /*!< buddy allocator mutex */
1728  BufListMutex zip_hash_mutex; /*!< zip_hash mutex */
1729  ib_mutex_t flush_state_mutex; /*!< Flush state protection
1730  mutex */
1731  BufPoolZipMutex zip_mutex; /*!< Zip mutex of this buffer
1732  pool instance, protects compressed
1733  only pages (of type buf_page_t, not
1734  buf_block_t */
1735  ulint instance_no; /*!< Array index of this buffer
1736  pool instance */
1737  ulint curr_pool_size; /*!< Current pool size in bytes */
1738  ulint LRU_old_ratio; /*!< Reserve this much of the buffer
1739  pool for "old" blocks */
1740 #ifdef UNIV_DEBUG
1741  ulint buddy_n_frames; /*!< Number of frames allocated from
1742  the buffer pool to the buddy system.
1743  Protected by zip_hash_mutex. */
1744 #endif
1745  ut_allocator<unsigned char> allocator; /*!< Allocator used for
1746  allocating memory for the the "chunks"
1747  member. */
1748  volatile ulint n_chunks; /*!< number of buffer pool chunks */
1749  volatile ulint n_chunks_new; /*!< new number of buffer pool chunks */
1750  buf_chunk_t *chunks; /*!< buffer pool chunks */
1751  buf_chunk_t *chunks_old; /*!< old buffer pool chunks to be freed
1752  after resizing buffer pool */
1753  ulint curr_size; /*!< current pool size in pages */
1754  ulint old_size; /*!< previous pool size in pages */
1755  page_no_t read_ahead_area; /*!< size in pages of the area which
1756  the read-ahead algorithms read if
1757  invoked */
1758  hash_table_t *page_hash; /*!< hash table of buf_page_t or
1759  buf_block_t file pages,
1760  buf_page_in_file() == TRUE,
1761  indexed by (space_id, offset).
1762  page_hash is protected by an
1763  array of mutexes. */
1764  hash_table_t *page_hash_old; /*!< old pointer to page_hash to be
1765  freed after resizing buffer pool */
1766  hash_table_t *zip_hash; /*!< hash table of buf_block_t blocks
1767  whose frames are allocated to the
1768  zip buddy system,
1769  indexed by block->frame */
1770  ulint n_pend_reads; /*!< number of pending read
1771  operations. Accessed atomically */
1772  ulint n_pend_unzip; /*!< number of pending decompressions.
1773  Accessed atomically. */
1774 
1776  /*!< when buf_print_io was last time
1777  called. Accesses not protected. */
1779  /*!< Statistics of buddy system,
1780  indexed by block size. Protected by
1781  zip_free mutex, except for the used
1782  field, which is also accessed
1783  atomically */
1784  buf_pool_stat_t stat; /*!< current statistics */
1785  buf_pool_stat_t old_stat; /*!< old statistics */
1786 
1787  /* @} */
1788 
1789  /** @name Page flushing algorithm fields */
1790 
1791  /* @{ */
1792 
1793  BufListMutex flush_list_mutex; /*!< mutex protecting the
1794  flush list access. This mutex
1795  protects flush_list, flush_rbt
1796  and bpage::list pointers when
1797  the bpage is on flush_list. It
1798  also protects writes to
1799  bpage::oldest_modification and
1800  flush_list_hp */
1801  FlushHp flush_hp; /*!< "hazard pointer"
1802  used during scan of flush_list
1803  while doing flush list batch.
1804  Protected by flush_list_mutex */
1805  UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1806  /*!< base node of the modified block
1807  list */
1809  /*!< this is TRUE when a flush of the
1810  given type is being initialized.
1811  Protected by flush_state_mutex. */
1813  /*!< this is the number of pending
1814  writes in the given flush type.
1815  Protected by flush_state_mutex. */
1817  /*!< this is in the set state
1818  when there is no flush batch
1819  of the given type running. Protected by
1820  flush_state_mutex. */
1821  ib_rbt_t *flush_rbt; /*!< a red-black tree is used
1822  exclusively during recovery to
1823  speed up insertions in the
1824  flush_list. This tree contains
1825  blocks in order of
1826  oldest_modification LSN and is
1827  kept in sync with the
1828  flush_list.
1829  Each member of the tree MUST
1830  also be on the flush_list.
1831  This tree is relevant only in
1832  recovery and is set to NULL
1833  once the recovery is over.
1834  Protected by flush_list_mutex */
1835  ulint freed_page_clock; /*!< a sequence number used
1836  to count the number of buffer
1837  blocks removed from the end of
1838  the LRU list; NOTE that this
1839  counter may wrap around at 4
1840  billion! A thread is allowed
1841  to read this for heuristic
1842  purposes without holding any
1843  mutex or latch. For non-heuristic
1844  purposes protected by LRU_list_mutex */
1845  ibool try_LRU_scan; /*!< Set to FALSE when an LRU
1846  scan for free block fails. This
1847  flag is used to avoid repeated
1848  scans of LRU list when we know
1849  that there is no free block
1850  available in the scan depth for
1851  eviction. Set to TRUE whenever
1852  we flush a batch from the
1853  buffer pool. Accessed protected by
1854  memory barriers. */
1855 
1856  lsn_t track_page_lsn; /* Pagge Tracking start LSN. */
1857 
1858  lsn_t max_lsn_io; /* Maximum LSN for which write io
1859  has already started. */
1860 
1861  /* @} */
1862 
1863  /** @name LRU replacement algorithm fields */
1864  /* @{ */
1865 
1867  /*!< base node of the free
1868  block list */
1869 
1870  UT_LIST_BASE_NODE_T(buf_page_t) withdraw;
1871  /*!< base node of the withdraw
1872  block list. It is only used during
1873  shrinking buffer pool size, not to
1874  reuse the blocks will be removed.
1875  Protected by free_list_mutex */
1876 
1877  ulint withdraw_target; /*!< target length of withdraw
1878  block list, when withdrawing */
1879 
1880  /** "hazard pointer" used during scan of LRU while doing
1881  LRU list batch. Protected by buf_pool::LRU_list_mutex */
1883 
1884  /** Iterator used to scan the LRU list when searching for
1885  replacable victim. Protected by buf_pool::LRU_list_mutex. */
1887 
1888  /** Iterator used to scan the LRU list when searching for
1889  single page flushing victim. Protected by buf_pool::LRU_list_mutex. */
1891 
1893  /*!< base node of the LRU list */
1894 
1895  buf_page_t *LRU_old; /*!< pointer to the about
1896  LRU_old_ratio/BUF_LRU_OLD_RATIO_DIV
1897  oldest blocks in the LRU list;
1898  NULL if LRU length less than
1899  BUF_LRU_OLD_MIN_LEN;
1900  NOTE: when LRU_old != NULL, its length
1901  should always equal LRU_old_len */
1902  ulint LRU_old_len; /*!< length of the LRU list from
1903  the block to which LRU_old points
1904  onward, including that block;
1905  see buf0lru.cc for the restrictions
1906  on this value; 0 if LRU_old == NULL;
1907  NOTE: LRU_old_len must be adjusted
1908  whenever LRU_old shrinks or grows! */
1909 
1910  UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1911  /*!< base node of the
1912  unzip_LRU list. The list is protected
1913  by LRU_list_mutex. */
1914 
1915  /* @} */
1916  /** @name Buddy allocator fields
1917  The buddy allocator is used for allocating compressed page
1918  frames and buf_page_t descriptors of blocks that exist
1919  in the buffer pool only in compressed form. */
1920  /* @{ */
1921 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1922  UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1923  /*!< unmodified compressed pages */
1924 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
1926  /*!< buddy free lists */
1927 
1929  /*!< Sentinel records for buffer
1930  pool watches. Scanning the array is
1931  protected by taking all page_hash
1932  latches in X. Updating or reading an
1933  individual watch page is protected by
1934  a corresponding individual page_hash
1935  latch. */
1936 
1937  /** A wrapper for buf_pool_t::allocator.alocate_large which also advices the
1938  OS that this chunk should not be dumped to a core file if that was requested.
1939  Emits a warning to the log and disables @@global.core_file if advising was
1940  requested but could not be performed, but still return true as the allocation
1941  itself succeeded.
1942  @param[in] mem_size number of bytes to allocate
1943  @param[in,out] chunk mem and mem_pfx fields of this chunk will be updated
1944  to contain information about allocated memory region
1945  @return true iff allocated successfully */
1946  bool allocate_chunk(ulonglong mem_size, buf_chunk_t *chunk);
1947 
1948  /** A wrapper for buf_pool_t::allocator.deallocate_large which also advices
1949  the OS that this chunk can be dumped to a core file.
1950  Emits a warning to the log and disables @@global.core_file if advising was
1951  requested but could not be performed.
1952  @param[in] chunk mem and mem_pfx fields of this chunk will be used to
1953  locate the memory region to free */
1954  void deallocate_chunk(buf_chunk_t *chunk);
1955 
1956  /** Advices the OS that all chunks in this buffer pool instance can be dumped
1957  to a core file.
1958  Emits a warning to the log if could not succeed.
1959  @return true iff succeeded, false if no OS support or failed */
1960  bool madvise_dump();
1961 
1962  /** Advices the OS that all chunks in this buffer pool instance should not
1963  be dumped to a core file.
1964  Emits a warning to the log if could not succeed.
1965  @return true iff succeeded, false if no OS support or failed */
1966  bool madvise_dont_dump();
1967 
1968 #if BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN
1969 #error "BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN"
1970 #endif
1971  /* @} */
1972 };
1973 
1974 /** Print the given buf_pool_t object.
1975 @param[in,out] out the output stream
1976 @param[in] buf_pool the buf_pool_t object to be printed
1977 @return the output stream */
1978 std::ostream &operator<<(std::ostream &out, const buf_pool_t &buf_pool);
1979 
1980 /** @name Accessors for buffer pool mutexes
1981 Use these instead of accessing buffer pool mutexes directly. */
1982 /* @{ */
1983 
1984 #ifndef UNIV_HOTBACKUP
1985 /** Test if flush list mutex is owned. */
1986 #define buf_flush_list_mutex_own(b) mutex_own(&(b)->flush_list_mutex)
1987 
1988 /** Acquire the flush list mutex. */
1989 #define buf_flush_list_mutex_enter(b) \
1990  do { \
1991  mutex_enter(&(b)->flush_list_mutex); \
1992  } while (0)
1993 /** Release the flush list mutex. */
1994 #define buf_flush_list_mutex_exit(b) \
1995  do { \
1996  mutex_exit(&(b)->flush_list_mutex); \
1997  } while (0)
1998 
1999 /** Test if block->mutex is owned. */
2000 #define buf_page_mutex_own(b) (b)->mutex.is_owned()
2001 
2002 /** Acquire the block->mutex. */
2003 #define buf_page_mutex_enter(b) \
2004  do { \
2005  mutex_enter(&(b)->mutex); \
2006  } while (0)
2007 
2008 /** Release the block->mutex. */
2009 #define buf_page_mutex_exit(b) \
2010  do { \
2011  (b)->mutex.exit(); \
2012  } while (0)
2013 
2014 /** Get appropriate page_hash_lock. */
2015 #define buf_page_hash_lock_get(buf_pool, page_id) \
2016  hash_get_lock((buf_pool)->page_hash, (page_id).fold())
2017 
2018 /** If not appropriate page_hash_lock, relock until appropriate. */
2019 #define buf_page_hash_lock_s_confirm(hash_lock, buf_pool, page_id) \
2020  hash_lock_s_confirm(hash_lock, (buf_pool)->page_hash, (page_id).fold())
2021 
2022 #define buf_page_hash_lock_x_confirm(hash_lock, buf_pool, page_id) \
2023  hash_lock_x_confirm(hash_lock, (buf_pool)->page_hash, (page_id).fold())
2024 #endif /* !UNIV_HOTBACKUP */
2025 
2026 #if defined(UNIV_DEBUG) && !defined(UNIV_HOTBACKUP)
2027 /** Test if page_hash lock is held in s-mode. */
2028 #define buf_page_hash_lock_held_s(buf_pool, bpage) \
2029  rw_lock_own(buf_page_hash_lock_get((buf_pool), (bpage)->id), RW_LOCK_S)
2030 
2031 /** Test if page_hash lock is held in x-mode. */
2032 #define buf_page_hash_lock_held_x(buf_pool, bpage) \
2033  rw_lock_own(buf_page_hash_lock_get((buf_pool), (bpage)->id), RW_LOCK_X)
2034 
2035 /** Test if page_hash lock is held in x or s-mode. */
2036 #define buf_page_hash_lock_held_s_or_x(buf_pool, bpage) \
2037  (buf_page_hash_lock_held_s((buf_pool), (bpage)) || \
2038  buf_page_hash_lock_held_x((buf_pool), (bpage)))
2039 
2040 #define buf_block_hash_lock_held_s(buf_pool, block) \
2041  buf_page_hash_lock_held_s((buf_pool), &(block)->page)
2042 
2043 #define buf_block_hash_lock_held_x(buf_pool, block) \
2044  buf_page_hash_lock_held_x((buf_pool), &(block)->page)
2045 
2046 #define buf_block_hash_lock_held_s_or_x(buf_pool, block) \
2047  buf_page_hash_lock_held_s_or_x((buf_pool), &(block)->page)
2048 #else /* UNIV_DEBUG && !UNIV_HOTBACKUP */
2049 #define buf_page_hash_lock_held_s(b, p) (TRUE)
2050 #define buf_page_hash_lock_held_x(b, p) (TRUE)
2051 #define buf_page_hash_lock_held_s_or_x(b, p) (TRUE)
2052 #define buf_block_hash_lock_held_s(b, p) (TRUE)
2053 #define buf_block_hash_lock_held_x(b, p) (TRUE)
2054 #define buf_block_hash_lock_held_s_or_x(b, p) (TRUE)
2055 #endif /* UNIV_DEBUG && !UNIV_HOTBACKUP */
2056 
2057 /* @} */
2058 
2059 /**********************************************************************
2060 Let us list the consistency conditions for different control block states.
2061 
2062 NOT_USED: is in free list, not in LRU list, not in flush list, nor
2063  page hash table
2064 READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
2065  hash table
2066 MEMORY: is not in free list, LRU list, or flush list, nor page
2067  hash table
2068 FILE_PAGE: space and offset are defined, is in page hash table
2069  if io_fix == BUF_IO_WRITE,
2070  pool: no_flush[flush_type] is in reset state,
2071  pool: n_flush[flush_type] > 0
2072 
2073  (1) if buf_fix_count == 0, then
2074  is in LRU list, not in free list
2075  is in flush list,
2076  if and only if oldest_modification > 0
2077  is x-locked,
2078  if and only if io_fix == BUF_IO_READ
2079  is s-locked,
2080  if and only if io_fix == BUF_IO_WRITE
2081 
2082  (2) if buf_fix_count > 0, then
2083  is not in LRU list, not in free list
2084  is in flush list,
2085  if and only if oldest_modification > 0
2086  if io_fix == BUF_IO_READ,
2087  is x-locked
2088  if io_fix == BUF_IO_WRITE,
2089  is s-locked
2090 
2091 State transitions:
2092 
2093 NOT_USED => READY_FOR_USE
2094 READY_FOR_USE => MEMORY
2095 READY_FOR_USE => FILE_PAGE
2096 MEMORY => NOT_USED
2097 FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
2098  (1) buf_fix_count == 0,
2099  (2) oldest_modification == 0, and
2100  (3) io_fix == 0.
2101 */
2102 
2103 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2104 #ifndef UNIV_HOTBACKUP
2105 /** Functor to validate the LRU list. */
2107  void operator()(const buf_page_t *elem) const { ut_a(elem->in_LRU_list); }
2108 
2109  static void validate(const buf_pool_t *buf_pool) {
2110  CheckInLRUList check;
2111  ut_list_validate(buf_pool->LRU, check);
2112  }
2113 };
2114 
2115 /** Functor to validate the LRU list. */
2117  void operator()(const buf_page_t *elem) const { ut_a(elem->in_free_list); }
2118 
2119  static void validate(const buf_pool_t *buf_pool) {
2120  CheckInFreeList check;
2121  ut_list_validate(buf_pool->free, check);
2122  }
2123 };
2124 
2126  void operator()(const buf_block_t *elem) const {
2127  ut_a(elem->page.in_LRU_list);
2128  ut_a(elem->in_unzip_LRU_list);
2129  }
2130 
2131  static void validate(const buf_pool_t *buf_pool) {
2133  ut_list_validate(buf_pool->unzip_LRU, check);
2134  }
2135 };
2136 #endif /* !UNIV_HOTBACKUP */
2137 #endif /* UNIV_DEBUG || defined UNIV_BUF_DEBUG */
2138 
2139 #include "buf0buf.ic"
2140 
2141 #endif /* !buf0buf_h */
lsn
static uint64_t lsn
Definition: xcom_base.c:406
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:4807
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:938
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:1890
lsn_t
uint64_t lsn_t
Type used for all log sequence number storage and arithmetics.
Definition: log0types.h:59
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:1902
mutex
pthread_mutex_t mutex
Definition: memcached.c:384
buf_page_print_flags
buf_page_print_flags
Definition: buf0buf.h:673
Page_fetch::POSSIBLY_FREED
@ POSSIBLY_FREED
Like Page_fetch::NORMAL, but do not mind if the file page has been freed.
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...
buf_pool_t::chunks_old
buf_chunk_t * chunks_old
old buffer pool chunks to be freed after resizing buffer pool
Definition: buf0buf.h:1751
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:2890
buf_pools_list_size_t::LRU_bytes
ulint LRU_bytes
LRU size in bytes.
Definition: buf0buf.h:231
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:406
BUF_PAGE_PRINT_NO_FULL
@ BUF_PAGE_PRINT_NO_FULL
Do not print the full page dump.
Definition: buf0buf.h:677
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:1725
CheckUnzipLRUAndLRUList::operator()
void operator()(const buf_block_t *elem) const
Definition: buf0buf.h:2126
buf_pool_info_t::unzip_sum
ulint unzip_sum
buf_LRU_stat_sum.unzip
Definition: buf0buf.h:223
CheckInLRUList::operator()
void operator()(const buf_page_t *elem) const
Definition: buf0buf.h:2149
BUF_BUDDY_SIZES_MAX
#define BUF_BUDDY_SIZES_MAX
Maximum number of buddy sizes based on the max page size.
Definition: buf0types.h:136
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...
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::file_page_was_freed
ibool 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:1307
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:209
buf_pool_info_t::pool_size
ulint pool_size
Buffer Pool size in pages.
Definition: buf0buf.h:161
buf_pool_t::last_printout_time
ib_time_monotonic_t last_printout_time
when buf_print_io was last time called.
Definition: buf0buf.h:1775
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_pool_t::n_pend_unzip
ulint n_pend_unzip
number of pending decompressions.
Definition: buf0buf.h:1772
buf_pool_t::track_page_lsn
lsn_t track_page_lsn
Definition: buf0buf.h:1856
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:2976
buf_pool_t::allocator
ut_allocator< unsigned char > allocator
Allocator used for allocating memory for the the "chunks" member.
Definition: buf0buf.h:1745
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:434
buf_pool_t::chunks
buf_chunk_t * chunks
buffer pool chunks
Definition: buf0buf.h:1750
buf_page_t::oldest_modification
lsn_t oldest_modification
log sequence number of the START of the log entry written of the oldest modification to this block wh...
Definition: buf0buf.h:1264
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:1604
ut_a
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:53
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:65
buf_pool_info_t::free_list_len
ulint free_list_len
Length of buf_pool->free list.
Definition: buf0buf.h:164
buf_block_t::curr_n_fields
unsigned curr_n_fields
prefix length for hash indexing: number of full fields
Definition: buf0buf.h:1443
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:5443
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:1835
buf_pool_info_t::n_pages_created
ulint n_pages_created
buf_pool->n_pages_created
Definition: buf0buf.h:180
buf_page_t::in_zip_hash
ibool in_zip_hash
TRUE if in buf_pool->zip_hash.
Definition: buf0buf.h:1209
dict_index_t
Data structure for an index.
Definition: dict0mem.h:869
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:1690
buf_block_t::lock
BPageLock lock
read-write lock of the buffer frame
Definition: buf0buf.h:1331
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:5893
buf_pool_stat_t::n_pages_made_young
ulint n_pages_made_young
number of pages made young, in calls to buf_LRU_make_block_young().
Definition: buf0buf.h:1686
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:1488
MAX_PAGE_HASH_LOCKS
constexpr ulint MAX_PAGE_HASH_LOCKS
The maximum number of page_hash locks.
Definition: buf0buf.h:111
HazardPointer::HazardPointer
HazardPointer(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1532
CheckInFreeList::operator()
void operator()(const buf_page_t *elem) const
Definition: buf0buf.h:2117
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_pool_info_t::n_page_get_delta
ulint n_page_get_delta
num of buffer pool page gets since last printout
Definition: buf0buf.h:190
buf_pool_free_all
void buf_pool_free_all()
Frees the buffer pool at shutdown.
Definition: buf0buf.cc:6393
buf_pool_withdrawing
volatile bool buf_pool_withdrawing
true when withdrawing buffer pool pages might cause page relocation
Definition: buf0buf.cc:299
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:4220
buf_pool_stat_t::n_pages_written
ulint n_pages_written
number of write operations.
Definition: buf0buf.h:1674
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:1458
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:1741
BPageMutex
ib_bpmutex_t BPageMutex
Definition: buf0types.h:144
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:4320
buf_pool_info_t::io_sum
ulint io_sum
buf_LRU_stat_sum.io
Definition: buf0buf.h:220
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:4606
buf_resize_thread
void buf_resize_thread()
This is the thread for resizing buffer pool.
Definition: buf0buf.cc:2499
LRUHp::adjust
void adjust(const buf_page_t *bpage)
Adjust the value of hp.
Definition: buf0buf.cc:2707
buf_block_t::curr_n_bytes
unsigned curr_n_bytes
number of bytes in hash indexing
Definition: buf0buf.h:1445
buf_pool_t::lru_scan_itr
LRUItr lru_scan_itr
Iterator used to scan the LRU list when searching for replacable victim.
Definition: buf0buf.h:1886
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:1882
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:4155
buf_pool_info_t::page_made_young_rate
double page_made_young_rate
page made young rate in pages per second
Definition: buf0buf.h:194
buf_pool_t::old_size
ulint old_size
previous pool size in pages
Definition: buf0buf.h:1754
buf_pool_t::madvise_dont_dump
bool madvise_dont_dump()
Advices the OS that all chunks in this buffer pool instance should not be dumped to a core file.
Definition: buf0buf.cc:922
buf_buddy_stat_t::relocated
uint64_t relocated
Number of blocks relocated by the buddy system.
Definition: buf0buf.h:1704
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:3275
dberr_t
dberr_t
Definition: db0err.h:38
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:2131
BufListMutex
ib_mutex_t BufListMutex
Definition: buf0types.h:145
buf_page_set_old
UNIV_INLINE void buf_page_set_old(buf_page_t *bpage, ibool old)
Flag a block old.
buf_pool_t::instance_no
ulint instance_no
Array index of this buffer pool instance.
Definition: buf0buf.h:1735
buf_buddy_free_t
Struct that is embedded in the free zip blocks.
Definition: buf0buf.h:1645
buf_block_t
The buffer control block structure.
Definition: buf0buf.h:1318
buf_pool_t::curr_size
ulint curr_size
current pool size in pages
Definition: buf0buf.h:1753
buf_page_t::newest_modification
lsn_t newest_modification
log sequence number of the youngest modification to this block, zero if not modified.
Definition: buf0buf.h:1258
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:6244
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:5062
buf_pool_info_t::page_read_delta
ulint page_read_delta
num of pages read since last printout
Definition: buf0buf.h:201
buf_pool_info_t::unzip_cur
ulint unzip_cur
buf_LRU_stat_cur.unzip, num pages decompressed in current interval
Definition: buf0buf.h:224
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:1468
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.
LRUItr::~LRUItr
virtual ~LRUItr()
Destructor.
Definition: buf0buf.h:1635
mutex_own
#define mutex_own(M)
Checks that the current thread owns the mutex.
Definition: ut0mutex.h:156
buf_pool_init
dberr_t buf_pool_init(ulint total_size, ulint n_instances)
Creates the buffer pool.
Definition: buf0buf.cc:1434
buf_page_t::flush_type
unsigned flush_type
if this block is currently being flushed to disk, this tells the flush_type.
Definition: buf0buf.h:1187
buf_pool_info_t::unzip_lru_len
ulint unzip_lru_len
length of buf_pool->unzip_LRU list
Definition: buf0buf.h:217
FlushHp::FlushHp
FlushHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1590
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:1105
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:1382
HazardPointer::m_mutex
const ib_mutex_t * m_mutex
mutex that protects access to the m_hp.
Definition: buf0buf.h:1577
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:363
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:5860
buf_pool_t::deallocate_chunk
void deallocate_chunk(buf_chunk_t *chunk)
A wrapper for buf_pool_t::allocator.deallocate_large which also advices the OS that this chunk can be...
Definition: buf0buf.cc:893
lock_mode
lock_mode
Definition: lock0types.h:51
FlushHp::~FlushHp
virtual ~FlushHp()
Destructor.
Definition: buf0buf.h:1594
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:1203
page_zip_des_t
Compressed page descriptor.
Definition: page0types.h:182
BUF_BLOCK_POOL_WATCH
@ BUF_BLOCK_POOL_WATCH
a sentinel for the buffer pool watch, element of buf_pool->watch[]
Definition: buf0buf.h:135
buf_block_t::n_hash_helps
ulint n_hash_helps
counter which controls building of a new hash index for the page
Definition: buf0buf.h:1375
buf_pool_stat_t::flush_list_bytes
ulint flush_list_bytes
flush_list size in bytes.
Definition: buf0buf.h:1695
buf_pool_info_t::young_making_delta
ulint young_making_delta
num of pages made young since last printout
Definition: buf0buf.h:203
buf_pool_info_t::n_page_gets
ulint n_page_gets
buf_pool->n_page_gets
Definition: buf0buf.h:182
buf_pool_t::LRU_old_ratio
ulint LRU_old_ratio
Reserve this much of the buffer pool for "old" blocks.
Definition: buf0buf.h:1738
LRUItr::LRUItr
LRUItr(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1631
buf_withdraw_clock
volatile ulint buf_withdraw_clock
the clock is incremented every time a pointer to a page may become obsolete
Definition: buf0buf.cc:304
buf_page_free_descriptor
UNIV_INLINE void buf_page_free_descriptor(buf_page_t *bpage)
Free a buf_page_t descriptor.
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:1193
malloc
#define malloc(A)
Definition: fts0ast.h:41
buf_pool_t::curr_pool_size
ulint curr_pool_size
Current pool size in bytes.
Definition: buf0buf.h:1737
buf_page_t::in_free_list
ibool 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:1250
Page_fetch
Page_fetch
Definition: buf0buf.h:57
buf_page_t::access_time
unsigned access_time
time of first access, or 0 if the block was never accessed in the buffer pool.
Definition: buf0buf.h:1302
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:1494
buf_pool_t::watch
buf_page_t * watch
Sentinel records for buffer pool watches.
Definition: buf0buf.h:1928
buf_pool_info_t::pages_read_rate
double pages_read_rate
num of pages read per second
Definition: buf0buf.h:198
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_page_t::size
page_size_t size
Page size.
Definition: buf0buf.h:1174
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:1161
buf_frame_t
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:59
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:185
buf_page_belongs_to_unzip_LRU
UNIV_INLINE ibool buf_page_belongs_to_unzip_LRU(const buf_page_t *bpage)
Determines if a block should be on unzip_LRU list.
buf_pool_stat_t::n_page_gets
ulint n_page_gets
number of page gets performed; also successful searches through the adaptive hash index are counted a...
Definition: buf0buf.h:1666
buf_pool_t::free_list_mutex
BufListMutex free_list_mutex
free and withdraw list mutex
Definition: buf0buf.h:1726
buf.h
buf_pool_info_t::io_cur
ulint io_cur
buf_LRU_stat_cur.io, num of IO for current interval
Definition: buf0buf.h:221
buf_pool_get_n_pages
UNIV_INLINE ulint buf_pool_get_n_pages(void)
Gets the current size of buffer buf_pool in frames.
LRUHp::~LRUHp
virtual ~LRUHp()
Destructor.
Definition: buf0buf.h:1613
buf_pool_info_t::n_pend_reads
ulint n_pend_reads
buf_pool->n_pend_reads, pages pending read
Definition: buf0buf.h:168
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:399
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:1448
buf_pool_info_t::n_pages_read
ulint n_pages_read
buf_pool->n_pages_read
Definition: buf0buf.h:179
buf_pool_stat_t::n_ra_pages_read_rnd
ulint n_ra_pages_read_rnd
number of pages read in as part of random read ahead.
Definition: buf0buf.h:1679
page_size_t
Page size descriptor.
Definition: page0size.h:50
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:1711
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:1986
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:1322
HazardPointer::m_hp
buf_page_t * m_hp
hazard pointer.
Definition: buf0buf.h:1581
buf_pool_t::n_pend_reads
ulint n_pend_reads
number of pending read operations.
Definition: buf0buf.h:1770
buf_pool_info_t::n_pending_flush_lru
ulint n_pending_flush_lru
Pages pending flush in LRU.
Definition: buf0buf.h:170
BufPoolZipMutex
BPageMutex BufPoolZipMutex
Definition: buf0types.h:147
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:1358
buf_block_t::in_withdraw_list
ibool in_withdraw_list
Definition: buf0buf.h:1345
buf_pool_info_t
This structure defines information we will fetch from each buffer pool.
Definition: buf0buf.h:158
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_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:3002
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:1758
buf_pool_t::chunks_mutex
BufListMutex chunks_mutex
protects (de)allocation of chunks:
Definition: buf0buf.h:1717
buf_flush_t
buf_flush_t
Flags for flush types.
Definition: buf0types.h:65
CheckInFreeList
Functor to validate the LRU list.
Definition: buf0buf.h:2116
HazardPointer::~HazardPointer
virtual ~HazardPointer()
Destructor.
Definition: buf0buf.h:1543
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:147
buf_page_t::buf_fix_count
uint32_t buf_fix_count
Count of how manyfold this block is currently bufferfixed.
Definition: buf0buf.h:1177
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.
HazardPointer
A "Hazard Pointer" class used to iterate over page lists inside the buffer pool.
Definition: buf0buf.h:1527
buf_page_t::flush_observer
FlushObserver * flush_observer
flush observer
Definition: buf0buf.h:1256
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:1232
buf_pool_info_t::n_pages_not_made_young
ulint n_pages_not_made_young
number of pages not made young
Definition: buf0buf.h:178
log0log.h
buf_pool_t::n_flush
ulint n_flush[BUF_FLUSH_N_TYPES]
this is the number of pending writes in the given flush type.
Definition: buf0buf.h:1812
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:171
buf_page_t::in_LRU_list
ibool in_LRU_list
TRUE if the page is in the LRU list; used in debugging.
Definition: buf0buf.h:1286
buf_pool_info_t::n_pending_flush_list
ulint n_pending_flush_list
Pages pending flush in FLUSH LIST.
Definition: buf0buf.h:175
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:1573
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:1895
buf_pool_ptr
buf_pool_t * buf_pool_ptr
The buffer pools of the database.
Definition: buf0buf.cc:293
buf_page_state
buf_page_state
States of a control block.
Definition: buf0buf.h:134
buf_print_io
void buf_print_io(FILE *file)
Prints info of the buffer i/o.
Definition: buf0buf.cc:6159
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:183
HazardPointer::operator=
HazardPointer & operator=(const HazardPointer &)
list
class udf_list * list
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_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:143
buf_pool_info_t::lru_len
ulint lru_len
Length of buf_pool->LRU.
Definition: buf0buf.h:162
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:1766
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:1755
buf_pool_stat_t::LRU_bytes
ulint LRU_bytes
LRU size in bytes.
Definition: buf0buf.h:1693
buf_pool_t::withdraw_target
ulint withdraw_target
target length of withdraw block list, when withdrawing
Definition: buf0buf.h:1877
buf_pool_t::old_stat
buf_pool_stat_t old_stat
old statistics
Definition: buf0buf.h:1785
FIL_PAGE_TYPE
#define FIL_PAGE_TYPE
file page type: FIL_PAGE_INDEX,..., 2 bytes.
Definition: fil0types.h:75
BUF_BLOCK_ZIP_DIRTY
@ BUF_BLOCK_ZIP_DIRTY
contains a compressed page that is in the buf_pool->flush_list
Definition: buf0buf.h:139
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:4422
buf_page_t::in_page_hash
ibool in_page_hash
TRUE if in buf_pool->page_hash.
Definition: buf0buf.h:1208
buf_pointer_is_block_field
ibool buf_pointer_is_block_field(const void *ptr)
Find out if a pointer belongs to a buf_block_t.
buf_pool_t::try_LRU_scan
ibool try_LRU_scan
Set to FALSE when an LRU scan for free block fails.
Definition: buf0buf.h:1845
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:213
buf_block_t::in_unzip_LRU_list
ibool in_unzip_LRU_list
TRUE if the page is in the decompressed LRU list; used in debugging.
Definition: buf0buf.h:1342
buf_pool_stat_t::n_pages_read
ulint n_pages_read
number of read operations.
Definition: buf0buf.h:1672
flush_type
flush_type
Definition: my_sys.h:289
consts::FILE
const std::string FILE("FILE")
buf_pools_list_size_t
The occupied bytes of lists in all buffer pools.
Definition: buf0buf.h:230
buf_pool_is_obsolete
UNIV_INLINE bool buf_pool_is_obsolete(ulint withdraw_clock)
Verify the possibility that a stored page is not in buffer pool.
buf0types.h
rw_lock_type_t
rw_lock_type_t
Definition: sync0rw.h:134
buf_block_unfix
UNIV_INLINE ulint buf_block_unfix(buf_page_t *bpage)
Decrements the bufferfix count.
HazardPointer::is_hp
bool is_hp(const buf_page_t *bpage)
Checks if a bpage is the hp.
Definition: buf0buf.cc:2680
BUF_PAGE_PRINT_NO_CRASH
@ BUF_PAGE_PRINT_NO_CRASH
Do not crash at the end of buf_page_print().
Definition: buf0buf.h:675
buf_buddy_free_t::size
ulint size
size of the block
Definition: buf0buf.h:1647
buf_pool_stat_t
The buffer pool statistics structure.
Definition: buf0buf.h:1665
buf_pool_t::init_flush
ibool init_flush[BUF_FLUSH_N_TYPES]
this is TRUE when a flush of the given type is being initialized.
Definition: buf0buf.h:1808
buf_block_t::n_pointers
ulint n_pointers
used in debugging: the number of pointers in the adaptive hash index pointing to this frame; protecte...
Definition: buf0buf.h:1423
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_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:102
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.
FIL_PAGE_NEXT
#define FIL_PAGE_NEXT
if there is a 'natural' successor of the page, its offset.
Definition: fil0types.h:60
buf_pool_stat_t::n_pages_not_made_young
ulint 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:1689
page_id_t
Page identifier.
Definition: buf0types.h:153
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:1731
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:2736
Page_fetch::SCAN
@ SCAN
Same as NORMAL, but hint that the fetch is part of a large scan.
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_PAGE
@ BUF_BLOCK_ZIP_PAGE
contains a clean compressed page
Definition: buf0buf.h:137
buf_pool_info_t::n_pages_made_young
ulint n_pages_made_young
number of pages made young
Definition: buf0buf.h:177
buf_pool_info_t::pages_created_rate
double pages_created_rate
num of pages create per second
Definition: buf0buf.h:199
buf_block_t::n_bytes
volatile ulint n_bytes
recommended prefix length for hash search: number of bytes in an incomplete last field
Definition: buf0buf.h:1377
buf_page_get_mutex
UNIV_INLINE BPageMutex * buf_page_get_mutex(const buf_page_t *bpage)
Gets the mutex of a block.
buf_pool_stat_t::n_pages_created
ulint n_pages_created
number of pages created in the pool with no read.
Definition: buf0buf.h:1676
buf_block_t::n_fields
volatile ulint n_fields
recommended prefix length for hash search: number of full fields
Definition: buf0buf.h:1380
buf_block_t::mutex
BPageMutex mutex
mutex protecting this block: state (also protected by the buffer pool mutex), io_fix,...
Definition: buf0buf.h:1475
buf_frame_align
UNIV_INLINE buf_frame_t * buf_frame_align(byte *ptr)
page_type_t
uint16_t page_type_t
Definition: fil0fil.h:946
HazardPointer::set
void set(buf_page_t *bpage)
Set current value.
Definition: buf0buf.cc:2667
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:2917
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_page_t::old
unsigned old
TRUE if the block is in the old blocks in buf_pool->LRU_old.
Definition: buf0buf.h:1291
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:105
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_t::curr_left_side
unsigned curr_left_side
TRUE or FALSE in hash indexing.
Definition: buf0buf.h:1447
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:163
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:1821
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:5879
BUF_BLOCK_FILE_PAGE
@ BUF_BLOCK_FILE_PAGE
contains a buffered file page
Definition: buf0buf.h:149
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:2942
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_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:3206
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:457
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.
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:165
buf_pool_t::flush_state_mutex
ib_mutex_t flush_state_mutex
Flush state protection mutex.
Definition: buf0buf.h:1729
buf_page_t::state
buf_page_state state
Block state.
Definition: buf0buf.h:1183
CheckInFreeList::validate
static void validate(const buf_pool_t *buf_pool)
Definition: buf0buf.h:2119
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.
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.
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_page_io_complete
bool buf_page_io_complete(buf_page_t *bpage, bool evict=false)
Completes an asynchronous read or write request of a file page to or from the buffer pool.
Definition: buf0buf.cc:5102
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_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.
LRUItr::start
buf_page_t * start()
Selects from where to start a scan.
Definition: buf0buf.cc:2722
buf_get_total_stat
void buf_get_total_stat(buf_pool_stat_t *tot_stat)
Get total buffer pool statistics.
Definition: buf0buf.cc:478
buf_pool_stat_t::n_ra_pages_read
ulint n_ra_pages_read
number of pages read in as part of read ahead.
Definition: buf0buf.h:1681
HazardPointer::get
buf_page_t * get() const
Get current value.
Definition: buf0buf.h:1546
BUF_BLOCK_MEMORY
@ BUF_BLOCK_MEMORY
contains some main memory object
Definition: buf0buf.h:150
buf_page_t::buf_pool_index
unsigned buf_pool_index
index number of the buffer pool that this block belongs to
Definition: buf0buf.h:1190
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:6231
buf_pool_info_t::pages_written_rate
double pages_written_rate
num of pages written per second
Definition: buf0buf.h:200
fil0fil.h
buf_io_fix
buf_io_fix
Flags for io_fix types.
Definition: buf0types.h:86
buf_page_t::in_flush_list
ibool 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:1239
Cache_hint
Cache_hint
Definition: buf0buf.h:90
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:5763
BUF_FLUSH_N_TYPES
@ BUF_FLUSH_N_TYPES
index of last element + 1
Definition: buf0types.h:71
buf_pool_t::allocate_chunk
bool allocate_chunk(ulonglong mem_size, buf_chunk_t *chunk)
A wrapper for buf_pool_t::allocator.alocate_large which also advices the OS that this chunk should no...
Definition: buf0buf.cc:872
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:205
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:1180
rw_lock_t
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:555
buf_pools_list_size_t::flush_list_bytes
ulint flush_list_bytes
flush_list size in bytes
Definition: buf0buf.h:233
FlushHp
Class implementing buf_pool->flush_list hazard pointer.
Definition: buf0buf.h:1585
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:196
buf_buddy_stat_t
Statistics of buddy blocks of a given size.
Definition: buf0buf.h:1700
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:2524
buf_buddy_free_t::stamp
union buf_buddy_free_t::@127 stamp
buf_pool_t::buddy_stat
buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES_MAX+1]
Statistics of buddy system, indexed by block size.
Definition: buf0buf.h:1778
buf_block_t::get_page_type_str
const char * get_page_type_str() const
Get the page type of the current buffer block as string.
Definition: buf0buf.cc:6348
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
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:3063
buf_pool_t::n_chunks
volatile ulint n_chunks
number of buffer pool chunks
Definition: buf0buf.h:1748
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:1326
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:536
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_buddy_stat_t::used
ulint used
Number of blocks allocated from the buddy system.
Definition: buf0buf.h:1702
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:2125
buf_pool_t::n_chunks_new
volatile ulint n_chunks_new
new number of buffer pool chunks
Definition: buf0buf.h:1749
buf_pool_t::madvise_dump
bool madvise_dump()
Advices the OS that all chunks in this buffer pool instance can be dumped to a core file.
Definition: buf0buf.cc:908
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:166
buf_refresh_io_stats_all
void buf_refresh_io_stats_all()
Refresh the statistics used to print per-second averages.
Definition: buf0buf.cc:6220
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().
FlushHp::adjust
void adjust(const buf_page_t *bpage)
Adjust the value of hp.
Definition: buf0buf.cc:2692
buf_pool_t::flush_hp
FlushHp flush_hp
"hazard pointer" used during scan of flush_list while doing flush list batch.
Definition: buf0buf.h:1801
n
int n
Definition: xcom_base.c:425
latch_level_t
latch_level_t
Latching order levels.
Definition: sync0types.h:209
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:5962
buf_validate
ibool buf_validate(void)
Validates the buffer pool data structure.
Definition: buf0buf.cc:5663
buf_pools_list_size_t::unzip_LRU_bytes
ulint unzip_LRU_bytes
unzip_LRU size in bytes
Definition: buf0buf.h:232
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:1484
buf_pool_t::max_lsn_io
lsn_t max_lsn_io
Definition: buf0buf.h:1858
buf_pool_info_t::n_pages_written
ulint n_pages_written
buf_pool->n_pages_written
Definition: buf0buf.h:181
buf_buddy_stat_t::relocated_usec
uint64_t relocated_usec
Total duration of block relocations, in microseconds.
Definition: buf0buf.h:1706
LRUHp::LRUHp
LRUHp(const buf_pool_t *buf_pool, const ib_mutex_t *mutex)
Constructor.
Definition: buf0buf.h:1609
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:187
buf_page_t::freed_page_clock
unsigned 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:1293
FlushObserver
We use FlushObserver to track flushing of non-redo logged pages in bulk create index(BtrBulk....
Definition: buf0flu.h:269
buf_pool_t::no_flush
os_event_t no_flush[BUF_FLUSH_N_TYPES]
this is in the set state when there is no flush batch of the given type running.
Definition: buf0buf.h:1816
buf_pool_t
The buffer pool structure.
Definition: buf0buf.h:1714
buf_pool_t::stat
buf_pool_stat_t stat
current statistics
Definition: buf0buf.h:1784
CheckInLRUList::validate
static void validate(const buf_pool_t *buf_pool)
Definition: buf0buf.h:2151
fil_addr_t
File space address.
Definition: fil0fil.h:901
LRUItr
Special purpose iterators to be used when scanning the LRU list.
Definition: buf0buf.h:1626
buf_block_alloc
buf_block_t * buf_block_alloc(buf_pool_t *buf_pool)
Allocates a buffer block.
Definition: buf0buf.cc:507
page_id_t::page_no
page_no_t page_no() const
Retrieve the page number.
Definition: buf0types.h:172
buf_buddy_free_t::bytes
byte bytes[FIL_PAGE_DATA]
stamp[FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID] == BUF_BUDDY_FREE_STAMP denotes a free block.
Definition: buf0buf.h:1648
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:890
operator<<
std::ostream & operator<<(std::ostream &out, const buf_pool_t &buf_pool)
Print the given buf_pool_t object.
Definition: buf0buf.cc:6319
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.
buf_pool_stat_t::n_ra_pages_evicted
ulint n_ra_pages_evicted
number of read ahead pages that are evicted without being accessed.
Definition: buf0buf.h:1683
ut_allocator< unsigned char >
buf_pool_t::zip_hash_mutex
BufListMutex zip_hash_mutex
zip_hash mutex
Definition: buf0buf.h:1728
ut0rbt.h
buf_pool_t::flush_list_mutex
BufListMutex flush_list_mutex
mutex protecting the flush list access.
Definition: buf0buf.h:1793
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:1764
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:160
CheckInLRUList
Functor to validate the LRU list.
Definition: buf0buf.h:2106
buf_pool_t::zip_free_mutex
BufListMutex zip_free_mutex
buddy allocator mutex
Definition: buf0buf.h:1727
index
char * index(const char *, int c)
Definition: mysql.cc:2875
BUF_BLOCK_REMOVE_HASH
@ BUF_BLOCK_REMOVE_HASH
hash index should be removed before putting to the free list
Definition: buf0buf.h:152
buf_pool_info_t::pages_readahead_rate
double pages_readahead_rate
readahead rate in pages per second
Definition: buf0buf.h:211
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:1659
buf_block_t::lock_hash_val
unsigned 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:1347
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:1500
buf_page_t::id
page_id_t id
Page id.
Definition: buf0buf.h:1171
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
ut0byte.h