1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 2006, 2016, 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 as published by the Free Software |
7 | Foundation; version 2 of the License. |
8 | |
9 | This program is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License along with |
14 | this program; if not, write to the Free Software Foundation, Inc., |
15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
16 | |
17 | *****************************************************************************/ |
18 | |
19 | /**************************************************//** |
20 | @file include/buf0buddy.h |
21 | Binary buddy allocator for compressed pages |
22 | |
23 | Created December 2006 by Marko Makela |
24 | *******************************************************/ |
25 | |
26 | #ifndef buf0buddy_h |
27 | #define buf0buddy_h |
28 | |
29 | #ifdef UNIV_MATERIALIZE |
30 | # undef UNIV_INLINE |
31 | # define UNIV_INLINE |
32 | #endif |
33 | |
34 | #include "univ.i" |
35 | #include "buf0types.h" |
36 | |
37 | /**********************************************************************//** |
38 | Allocate a block. The thread calling this function must hold |
39 | buf_pool->mutex and must not hold buf_pool->zip_mutex or any |
40 | block->mutex. The buf_pool->mutex may be released and reacquired. |
41 | This function should only be used for allocating compressed page frames. |
42 | @return allocated block, never NULL */ |
43 | UNIV_INLINE |
44 | byte* |
45 | buf_buddy_alloc( |
46 | /*============*/ |
47 | buf_pool_t* buf_pool, /*!< in/out: buffer pool in which |
48 | the page resides */ |
49 | ulint size, /*!< in: compressed page size |
50 | (between UNIV_ZIP_SIZE_MIN and |
51 | srv_page_size) */ |
52 | bool* lru) /*!< in: pointer to a variable |
53 | that will be assigned true if |
54 | storage was allocated from the |
55 | LRU list and buf_pool->mutex was |
56 | temporarily released */ |
57 | MY_ATTRIBUTE((malloc, nonnull)); |
58 | |
59 | /**********************************************************************//** |
60 | Deallocate a block. */ |
61 | UNIV_INLINE |
62 | void |
63 | buf_buddy_free( |
64 | /*===========*/ |
65 | buf_pool_t* buf_pool, /*!< in/out: buffer pool in which |
66 | the block resides */ |
67 | void* buf, /*!< in: block to be freed, must not |
68 | be pointed to by the buffer pool */ |
69 | ulint size) /*!< in: block size, |
70 | up to srv_page_size */ |
71 | MY_ATTRIBUTE((nonnull)); |
72 | |
73 | /** Reallocate a block. |
74 | @param[in] buf_pool buffer pool instance |
75 | @param[in] buf block to be reallocated, must be pointed |
76 | to by the buffer pool |
77 | @param[in] size block size, up to srv_page_size |
78 | @retval false if failed because of no free blocks. */ |
79 | bool |
80 | buf_buddy_realloc( |
81 | buf_pool_t* buf_pool, |
82 | void* buf, |
83 | ulint size); |
84 | |
85 | /** Combine all pairs of free buddies. |
86 | @param[in] buf_pool buffer pool instance */ |
87 | void |
88 | buf_buddy_condense_free( |
89 | buf_pool_t* buf_pool); |
90 | |
91 | #include "buf0buddy.ic" |
92 | |
93 | #endif /* buf0buddy_h */ |
94 | |