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.

142 lines
4.5 KiB

17 years ago
9 years ago
17 years ago
17 years ago
16 years ago
16 years ago
9 years ago
16 years ago
15 years ago
15 years ago
9 years ago
16 years ago
16 years ago
17 years ago
16 years ago
15 years ago
15 years ago
16 years ago
  1. /*****************************************************************************
  2. Copyright (c) 2006, 2016, Oracle and/or its affiliates. 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.,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/buf0buddy.ic
  15. Binary buddy allocator for compressed pages
  16. Created December 2006 by Marko Makela
  17. *******************************************************/
  18. #ifdef UNIV_MATERIALIZE
  19. # undef UNIV_INLINE
  20. # define UNIV_INLINE
  21. #endif
  22. #include "buf0buf.h"
  23. #include "buf0buddy.h"
  24. #include "ut0ut.h"
  25. #include "sync0sync.h"
  26. /**********************************************************************//**
  27. Allocate a block. The thread calling this function must hold
  28. buf_pool->LRU_list_mutex and must not hold buf_pool->zip_mutex or any
  29. block->mutex. The buf_pool->LRU_list_mutex may be released and reacquired.
  30. @return allocated block, never NULL */
  31. UNIV_INTERN
  32. void*
  33. buf_buddy_alloc_low(
  34. /*================*/
  35. buf_pool_t* buf_pool, /*!< in/out: buffer pool instance */
  36. ulint i, /*!< in: index of buf_pool->zip_free[],
  37. or BUF_BUDDY_SIZES */
  38. ibool* lru) /*!< in: pointer to a variable that
  39. will be assigned TRUE if storage was
  40. allocated from the LRU list and
  41. buf_pool->LRU_list_mutex was
  42. temporarily released */
  43. MY_ATTRIBUTE((malloc));
  44. /**********************************************************************//**
  45. Deallocate a block. */
  46. UNIV_INTERN
  47. void
  48. buf_buddy_free_low(
  49. /*===============*/
  50. buf_pool_t* buf_pool, /*!< in: buffer pool instance */
  51. void* buf, /*!< in: block to be freed, must not be
  52. pointed to by the buffer pool */
  53. ulint i) /*!< in: index of buf_pool->zip_free[],
  54. or BUF_BUDDY_SIZES */
  55. MY_ATTRIBUTE((nonnull));
  56. /**********************************************************************//**
  57. Get the index of buf_pool->zip_free[] for a given block size.
  58. @return index of buf_pool->zip_free[], or BUF_BUDDY_SIZES */
  59. UNIV_INLINE
  60. ulint
  61. buf_buddy_get_slot(
  62. /*===============*/
  63. ulint size) /*!< in: block size */
  64. {
  65. ulint i;
  66. ulint s;
  67. ut_ad(size >= UNIV_ZIP_SIZE_MIN);
  68. for (i = 0, s = BUF_BUDDY_LOW; s < size; i++, s <<= 1) {
  69. }
  70. ut_ad(i <= BUF_BUDDY_SIZES);
  71. return(i);
  72. }
  73. /**********************************************************************//**
  74. Allocate a block. The thread calling this function must hold
  75. buf_pool->LRU_list_mutex and must not hold buf_pool->zip_mutex or any
  76. block->mutex. The buf_pool->LRU_list_mutex may be released and reacquired.
  77. This function should only be used for allocating compressed page frames.
  78. @return allocated block, never NULL */
  79. UNIV_INLINE
  80. byte*
  81. buf_buddy_alloc(
  82. /*============*/
  83. buf_pool_t* buf_pool, /*!< in/out: buffer pool in which
  84. the page resides */
  85. ulint size, /*!< in: compressed page size
  86. (between UNIV_ZIP_SIZE_MIN and
  87. UNIV_PAGE_SIZE) */
  88. ibool* lru) /*!< in: pointer to a variable
  89. that will be assigned TRUE if
  90. storage was allocated from the
  91. LRU list and buf_pool->LRU_list_mutex
  92. was temporarily released */
  93. {
  94. ut_ad(mutex_own(&buf_pool->LRU_list_mutex));
  95. ut_ad(ut_is_2pow(size));
  96. ut_ad(size >= UNIV_ZIP_SIZE_MIN);
  97. ut_ad(size <= UNIV_PAGE_SIZE);
  98. return((byte*) buf_buddy_alloc_low(buf_pool, buf_buddy_get_slot(size),
  99. lru));
  100. }
  101. /**********************************************************************//**
  102. Deallocate a block. */
  103. UNIV_INLINE
  104. void
  105. buf_buddy_free(
  106. /*===========*/
  107. buf_pool_t* buf_pool, /*!< in/out: buffer pool in which
  108. the block resides */
  109. void* buf, /*!< in: block to be freed, must not
  110. be pointed to by the buffer pool */
  111. ulint size) /*!< in: block size,
  112. up to UNIV_PAGE_SIZE */
  113. {
  114. ut_ad(ut_is_2pow(size));
  115. ut_ad(size >= UNIV_ZIP_SIZE_MIN);
  116. ut_ad(size <= UNIV_PAGE_SIZE);
  117. buf_buddy_free_low(buf_pool, buf, buf_buddy_get_slot(size));
  118. }
  119. #ifdef UNIV_MATERIALIZE
  120. # undef UNIV_INLINE
  121. # define UNIV_INLINE UNIV_INLINE_ORIGINAL
  122. #endif