You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
8.2 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  11. Place, Suite 330, Boston, MA 02111-1307 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/buf0flu.h
  15. The database buffer pool flush algorithm
  16. Created 11/5/1995 Heikki Tuuri
  17. *******************************************************/
  18. #ifndef buf0flu_h
  19. #define buf0flu_h
  20. #include "univ.i"
  21. #include "ut0byte.h"
  22. #ifndef UNIV_HOTBACKUP
  23. #include "mtr0types.h"
  24. #include "buf0types.h"
  25. /********************************************************************//**
  26. Remove a block from the flush list of modified blocks. */
  27. UNIV_INTERN
  28. void
  29. buf_flush_remove(
  30. /*=============*/
  31. buf_page_t* bpage); /*!< in: pointer to the block in question */
  32. /********************************************************************//**
  33. Relocates a buffer control block on the flush_list.
  34. Note that it is assumed that the contents of bpage has already been
  35. copied to dpage. */
  36. UNIV_INTERN
  37. void
  38. buf_flush_relocate_on_flush_list(
  39. /*=============================*/
  40. buf_page_t* bpage, /*!< in/out: control block being moved */
  41. buf_page_t* dpage); /*!< in/out: destination block */
  42. /********************************************************************//**
  43. Updates the flush system data structures when a write is completed. */
  44. UNIV_INTERN
  45. void
  46. buf_flush_write_complete(
  47. /*=====================*/
  48. buf_page_t* bpage); /*!< in: pointer to the block in question */
  49. /*********************************************************************//**
  50. Flushes pages from the end of the LRU list if there is too small
  51. a margin of replaceable pages there. */
  52. UNIV_INTERN
  53. void
  54. buf_flush_free_margin(void);
  55. /*=======================*/
  56. #endif /* !UNIV_HOTBACKUP */
  57. /********************************************************************//**
  58. Initializes a page for writing to the tablespace. */
  59. UNIV_INTERN
  60. void
  61. buf_flush_init_for_writing(
  62. /*=======================*/
  63. byte* page, /*!< in/out: page */
  64. void* page_zip_, /*!< in/out: compressed page, or NULL */
  65. ib_uint64_t newest_lsn); /*!< in: newest modification lsn
  66. to the page */
  67. #ifndef UNIV_HOTBACKUP
  68. /*******************************************************************//**
  69. This utility flushes dirty blocks from the end of the LRU list or flush_list.
  70. NOTE 1: in the case of an LRU flush the calling thread may own latches to
  71. pages: to avoid deadlocks, this function must be written so that it cannot
  72. end up waiting for these latches! NOTE 2: in the case of a flush list flush,
  73. the calling thread is not allowed to own any latches on pages!
  74. @return number of blocks for which the write request was queued;
  75. ULINT_UNDEFINED if there was a flush of the same type already running */
  76. UNIV_INTERN
  77. ulint
  78. buf_flush_batch(
  79. /*============*/
  80. enum buf_flush flush_type, /*!< in: BUF_FLUSH_LRU or
  81. BUF_FLUSH_LIST; if BUF_FLUSH_LIST,
  82. then the caller must not own any
  83. latches on pages */
  84. ulint min_n, /*!< in: wished minimum mumber of blocks
  85. flushed (it is not guaranteed that the
  86. actual number is that big, though) */
  87. ib_uint64_t lsn_limit); /*!< in the case BUF_FLUSH_LIST all
  88. blocks whose oldest_modification is
  89. smaller than this should be flushed
  90. (if their number does not exceed
  91. min_n), otherwise ignored */
  92. /******************************************************************//**
  93. Waits until a flush batch of the given type ends */
  94. UNIV_INTERN
  95. void
  96. buf_flush_wait_batch_end(
  97. /*=====================*/
  98. enum buf_flush type); /*!< in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
  99. /********************************************************************//**
  100. This function should be called at a mini-transaction commit, if a page was
  101. modified in it. Puts the block to the list of modified blocks, if it not
  102. already in it. */
  103. UNIV_INLINE
  104. void
  105. buf_flush_note_modification(
  106. /*========================*/
  107. buf_block_t* block, /*!< in: block which is modified */
  108. mtr_t* mtr); /*!< in: mtr */
  109. /********************************************************************//**
  110. This function should be called when recovery has modified a buffer page. */
  111. UNIV_INLINE
  112. void
  113. buf_flush_recv_note_modification(
  114. /*=============================*/
  115. buf_block_t* block, /*!< in: block which is modified */
  116. ib_uint64_t start_lsn, /*!< in: start lsn of the first mtr in a
  117. set of mtr's */
  118. ib_uint64_t end_lsn); /*!< in: end lsn of the last mtr in the
  119. set of mtr's */
  120. /********************************************************************//**
  121. Returns TRUE if the file page block is immediately suitable for replacement,
  122. i.e., transition FILE_PAGE => NOT_USED allowed.
  123. @return TRUE if can replace immediately */
  124. UNIV_INTERN
  125. ibool
  126. buf_flush_ready_for_replace(
  127. /*========================*/
  128. buf_page_t* bpage); /*!< in: buffer control block, must be
  129. buf_page_in_file(bpage) and in the LRU list */
  130. /** @brief Statistics for selecting flush rate based on redo log
  131. generation speed.
  132. These statistics are generated for heuristics used in estimating the
  133. rate at which we should flush the dirty blocks to avoid bursty IO
  134. activity. Note that the rate of flushing not only depends on how many
  135. dirty pages we have in the buffer pool but it is also a fucntion of
  136. how much redo the workload is generating and at what rate. */
  137. struct buf_flush_stat_struct
  138. {
  139. ib_uint64_t redo; /*!< amount of redo generated. */
  140. ulint n_flushed; /*!< number of pages flushed. */
  141. };
  142. /** Statistics for selecting flush rate of dirty pages. */
  143. typedef struct buf_flush_stat_struct buf_flush_stat_t;
  144. /*********************************************************************
  145. Update the historical stats that we are collecting for flush rate
  146. heuristics at the end of each interval. */
  147. UNIV_INTERN
  148. void
  149. buf_flush_stat_update(void);
  150. /*=======================*/
  151. /*********************************************************************
  152. Determines the fraction of dirty pages that need to be flushed based
  153. on the speed at which we generate redo log. Note that if redo log
  154. is generated at significant rate without a corresponding increase
  155. in the number of dirty pages (for example, an in-memory workload)
  156. it can cause IO bursts of flushing. This function implements heuristics
  157. to avoid this burstiness.
  158. @return number of dirty pages to be flushed / second */
  159. UNIV_INTERN
  160. ulint
  161. buf_flush_get_desired_flush_rate(void);
  162. /*==================================*/
  163. #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
  164. /******************************************************************//**
  165. Validates the flush list.
  166. @return TRUE if ok */
  167. UNIV_INTERN
  168. ibool
  169. buf_flush_validate(void);
  170. /*====================*/
  171. #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
  172. /******************************************************************//**
  173. Initialize the red-black tree to speed up insertions into the flush_list
  174. during recovery process. Should be called at the start of recovery
  175. process before any page has been read/written. */
  176. UNIV_INTERN
  177. void
  178. buf_flush_init_flush_rbt(void);
  179. /*==========================*/
  180. /******************************************************************//**
  181. Frees up the red-black tree. */
  182. UNIV_INTERN
  183. void
  184. buf_flush_free_flush_rbt(void);
  185. /*==========================*/
  186. /** When buf_flush_free_margin is called, it tries to make this many blocks
  187. available to replacement in the free list and at the end of the LRU list (to
  188. make sure that a read-ahead batch can be read efficiently in a single
  189. sweep). */
  190. #define BUF_FLUSH_FREE_BLOCK_MARGIN (5 + BUF_READ_AHEAD_AREA)
  191. /** Extra margin to apply above BUF_FLUSH_FREE_BLOCK_MARGIN */
  192. #define BUF_FLUSH_EXTRA_MARGIN (BUF_FLUSH_FREE_BLOCK_MARGIN / 4 + 100)
  193. #endif /* !UNIV_HOTBACKUP */
  194. #ifndef UNIV_NONINL
  195. #include "buf0flu.ic"
  196. #endif
  197. #endif