1/*****************************************************************************
2
3Copyright (c) 2006, 2016, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/**************************************************//**
20@file include/buf0buddy.h
21Binary buddy allocator for compressed pages
22
23Created 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/**********************************************************************//**
38Allocate a block. The thread calling this function must hold
39buf_pool->mutex and must not hold buf_pool->zip_mutex or any
40block->mutex. The buf_pool->mutex may be released and reacquired.
41This function should only be used for allocating compressed page frames.
42@return allocated block, never NULL */
43UNIV_INLINE
44byte*
45buf_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/**********************************************************************//**
60Deallocate a block. */
61UNIV_INLINE
62void
63buf_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
76to 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. */
79bool
80buf_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 */
87void
88buf_buddy_condense_free(
89 buf_pool_t* buf_pool);
90
91#include "buf0buddy.ic"
92
93#endif /* buf0buddy_h */
94