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.

191 lines
7.3 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1995, 2009, 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. Updates the flush system data structures when a write is completed. */
  34. UNIV_INTERN
  35. void
  36. buf_flush_write_complete(
  37. /*=====================*/
  38. buf_page_t* bpage); /*!< in: pointer to the block in question */
  39. /*********************************************************************//**
  40. Flushes pages from the end of the LRU list if there is too small
  41. a margin of replaceable pages there. */
  42. UNIV_INTERN
  43. void
  44. buf_flush_free_margin(void);
  45. /*=======================*/
  46. #endif /* !UNIV_HOTBACKUP */
  47. /********************************************************************//**
  48. Initializes a page for writing to the tablespace. */
  49. UNIV_INTERN
  50. void
  51. buf_flush_init_for_writing(
  52. /*=======================*/
  53. byte* page, /*!< in/out: page */
  54. void* page_zip_, /*!< in/out: compressed page, or NULL */
  55. ib_uint64_t newest_lsn); /*!< in: newest modification lsn
  56. to the page */
  57. #ifndef UNIV_HOTBACKUP
  58. /*******************************************************************//**
  59. This utility flushes dirty blocks from the end of the LRU list or flush_list.
  60. NOTE 1: in the case of an LRU flush the calling thread may own latches to
  61. pages: to avoid deadlocks, this function must be written so that it cannot
  62. end up waiting for these latches! NOTE 2: in the case of a flush list flush,
  63. the calling thread is not allowed to own any latches on pages!
  64. @return number of blocks for which the write request was queued;
  65. ULINT_UNDEFINED if there was a flush of the same type already running */
  66. UNIV_INTERN
  67. ulint
  68. buf_flush_batch(
  69. /*============*/
  70. enum buf_flush flush_type, /*!< in: BUF_FLUSH_LRU or
  71. BUF_FLUSH_LIST; if BUF_FLUSH_LIST,
  72. then the caller must not own any
  73. latches on pages */
  74. ulint min_n, /*!< in: wished minimum mumber of blocks
  75. flushed (it is not guaranteed that the
  76. actual number is that big, though) */
  77. ib_uint64_t lsn_limit); /*!< in the case BUF_FLUSH_LIST all
  78. blocks whose oldest_modification is
  79. smaller than this should be flushed
  80. (if their number does not exceed
  81. min_n), otherwise ignored */
  82. /******************************************************************//**
  83. Waits until a flush batch of the given type ends */
  84. UNIV_INTERN
  85. void
  86. buf_flush_wait_batch_end(
  87. /*=====================*/
  88. enum buf_flush type); /*!< in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
  89. /********************************************************************//**
  90. This function should be called at a mini-transaction commit, if a page was
  91. modified in it. Puts the block to the list of modified blocks, if it not
  92. already in it. */
  93. UNIV_INLINE
  94. void
  95. buf_flush_note_modification(
  96. /*========================*/
  97. buf_block_t* block, /*!< in: block which is modified */
  98. mtr_t* mtr); /*!< in: mtr */
  99. /********************************************************************//**
  100. This function should be called when recovery has modified a buffer page. */
  101. UNIV_INLINE
  102. void
  103. buf_flush_recv_note_modification(
  104. /*=============================*/
  105. buf_block_t* block, /*!< in: block which is modified */
  106. ib_uint64_t start_lsn, /*!< in: start lsn of the first mtr in a
  107. set of mtr's */
  108. ib_uint64_t end_lsn); /*!< in: end lsn of the last mtr in the
  109. set of mtr's */
  110. /********************************************************************//**
  111. Returns TRUE if the file page block is immediately suitable for replacement,
  112. i.e., transition FILE_PAGE => NOT_USED allowed.
  113. @return TRUE if can replace immediately */
  114. UNIV_INTERN
  115. ibool
  116. buf_flush_ready_for_replace(
  117. /*========================*/
  118. buf_page_t* bpage); /*!< in: buffer control block, must be
  119. buf_page_in_file(bpage) and in the LRU list */
  120. /** @brief Statistics for selecting flush rate based on redo log
  121. generation speed.
  122. These statistics are generated for heuristics used in estimating the
  123. rate at which we should flush the dirty blocks to avoid bursty IO
  124. activity. Note that the rate of flushing not only depends on how many
  125. dirty pages we have in the buffer pool but it is also a fucntion of
  126. how much redo the workload is generating and at what rate. */
  127. struct buf_flush_stat_struct
  128. {
  129. ib_uint64_t redo; /**< amount of redo generated. */
  130. ulint n_flushed; /**< number of pages flushed. */
  131. };
  132. /** Statistics for selecting flush rate of dirty pages. */
  133. typedef struct buf_flush_stat_struct buf_flush_stat_t;
  134. /*********************************************************************
  135. Update the historical stats that we are collecting for flush rate
  136. heuristics at the end of each interval. */
  137. UNIV_INTERN
  138. void
  139. buf_flush_stat_update(void);
  140. /*=======================*/
  141. /*********************************************************************
  142. Determines the fraction of dirty pages that need to be flushed based
  143. on the speed at which we generate redo log. Note that if redo log
  144. is generated at significant rate without a corresponding increase
  145. in the number of dirty pages (for example, an in-memory workload)
  146. it can cause IO bursts of flushing. This function implements heuristics
  147. to avoid this burstiness.
  148. @return number of dirty pages to be flushed / second */
  149. UNIV_INTERN
  150. ulint
  151. buf_flush_get_desired_flush_rate(void);
  152. /*==================================*/
  153. #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
  154. /******************************************************************//**
  155. Validates the flush list.
  156. @return TRUE if ok */
  157. UNIV_INTERN
  158. ibool
  159. buf_flush_validate(void);
  160. /*====================*/
  161. #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
  162. /** When buf_flush_free_margin is called, it tries to make this many blocks
  163. available to replacement in the free list and at the end of the LRU list (to
  164. make sure that a read-ahead batch can be read efficiently in a single
  165. sweep). */
  166. #define BUF_FLUSH_FREE_BLOCK_MARGIN (5 + BUF_READ_AHEAD_AREA)
  167. /** Extra margin to apply above BUF_FLUSH_FREE_BLOCK_MARGIN */
  168. #define BUF_FLUSH_EXTRA_MARGIN (BUF_FLUSH_FREE_BLOCK_MARGIN / 4 + 100)
  169. #endif /* !UNIV_HOTBACKUP */
  170. #ifndef UNIV_NONINL
  171. #include "buf0flu.ic"
  172. #endif
  173. #endif