buf0buddy.h 1.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/******************************************************
Binary buddy allocator for compressed pages

(c) 2006 Innobase Oy

Created December 2006 by Marko Makela
*******************************************************/

#ifndef buf0buddy_h
#define buf0buddy_h

#ifdef UNIV_MATERIALIZE
# undef UNIV_INLINE
# define UNIV_INLINE
#endif

#include "univ.i"
#include "buf0types.h"

/**************************************************************************
Get the offset of the buddy of a compressed page frame. */
UNIV_INLINE
lint
buf_buddy_get_offset(
/*=================*/
				/* out: offset of the buddy relative to page */
	const void*	page,	/* in: compressed page */
	ulint		size)	/* in: page size in bytes */
	__attribute__((nonnull));

/**************************************************************************
32 33
Get the buddy of a compressed page frame.
Note: "page" should be a pointer to byte or char. */
34 35 36 37 38 39 40 41 42 43 44 45
#define buf_buddy_get(page,size) ((page) + buf_buddy_get_offset((page),(size)))

/**************************************************************************
Get the index of buf_pool->zip_free[] for a given block size. */
UNIV_INLINE
ulint
buf_buddy_get_slot(
/*===============*/
			/* out: index of buf_pool->zip_free[] */
	ulint	size);	/* in: block size */

/**************************************************************************
46
Allocate a block. */
47 48
UNIV_INLINE
void*
49 50
buf_buddy_alloc(
/*============*/
51
			/* out: pointer to the start of the block */
52 53
	ulint	size,	/* in: block size, up to UNIV_PAGE_SIZE / 2 */
	ibool	lru)	/* in: TRUE=allocate from the LRU list if needed */
54 55
	__attribute__((malloc));

56
/**************************************************************************
57
Release a block. */
58
UNIV_INLINE
59
void
60 61
buf_buddy_free(
/*===========*/
62 63
	void*	buf,	/* in: block to be freed, must not be
			pointed to by the buffer pool */
64 65 66
	ulint	size)	/* in: block size, up to UNIV_PAGE_SIZE / 2 */
	__attribute__((nonnull));

67 68 69 70 71
#ifndef UNIV_NONINL
# include "buf0buddy.ic"
#endif

#endif /* buf0buddy_h */