2006-12-07 13:29:04 +00:00
|
|
|
/******************************************************
|
|
|
|
Binary buddy allocator for compressed pages
|
|
|
|
|
|
|
|
(c) 2006 Innobase Oy
|
|
|
|
|
|
|
|
Created December 2006 by Marko Makela
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
|
|
# undef UNIV_INLINE
|
|
|
|
# define UNIV_INLINE
|
|
|
|
#endif
|
|
|
|
|
2006-12-11 15:48:37 +00:00
|
|
|
#include "buf0buf.h"
|
2006-12-07 13:29:04 +00:00
|
|
|
#include "buf0buddy.h"
|
|
|
|
#include "ut0ut.h"
|
2006-12-11 15:48:37 +00:00
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
# include "sync0sync.h"
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
2006-12-07 13:29:04 +00:00
|
|
|
|
|
|
|
/**************************************************************************
|
2006-12-11 14:27:43 +00:00
|
|
|
Allocate a block. */
|
2006-12-07 13:29:04 +00:00
|
|
|
|
|
|
|
void*
|
2006-12-07 15:05:06 +00:00
|
|
|
buf_buddy_alloc_low(
|
|
|
|
/*================*/
|
2006-12-11 14:27:43 +00:00
|
|
|
/* out: pointer to the start of the block */
|
2006-12-12 12:14:58 +00:00
|
|
|
ulint i, /* in: index of buf_pool->zip_free[] */
|
|
|
|
ibool lru) /* in: TRUE=allocate from the LRU list if needed */
|
2006-12-07 13:29:04 +00:00
|
|
|
__attribute__((malloc));
|
|
|
|
|
2006-12-07 15:22:44 +00:00
|
|
|
/**************************************************************************
|
2006-12-11 09:54:13 +00:00
|
|
|
Deallocate a block. */
|
2006-12-07 15:22:44 +00:00
|
|
|
|
2006-12-11 09:54:13 +00:00
|
|
|
void
|
2006-12-07 15:22:44 +00:00
|
|
|
buf_buddy_free_low(
|
|
|
|
/*===============*/
|
|
|
|
void* buf, /* in: block to free */
|
|
|
|
ulint i) /* in: index of buf_pool->zip_free[] */
|
|
|
|
__attribute__((nonnull));
|
|
|
|
|
2006-12-07 13:29:04 +00:00
|
|
|
/**************************************************************************
|
|
|
|
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 */
|
|
|
|
{
|
|
|
|
ut_ad(ut_is_2pow(size));
|
|
|
|
ut_ad(size >= BUF_BUDDY_LOW);
|
2006-12-07 15:20:53 +00:00
|
|
|
ut_ad(size < BUF_BUDDY_HIGH);
|
2006-12-07 13:29:04 +00:00
|
|
|
|
|
|
|
if (((ulint) page) & size) {
|
|
|
|
return(-(lint) size);
|
|
|
|
} else {
|
|
|
|
return((lint) 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 */
|
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
ulint s;
|
|
|
|
|
|
|
|
for (i = 0, s = BUF_BUDDY_LOW; s < size; i++, s <<= 1);
|
|
|
|
|
|
|
|
ut_ad(i < BUF_BUDDY_SIZES);
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2006-12-11 14:27:43 +00:00
|
|
|
Allocate a block. */
|
2006-12-07 13:29:04 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
void*
|
2006-12-07 15:05:06 +00:00
|
|
|
buf_buddy_alloc(
|
|
|
|
/*============*/
|
2006-12-11 14:27:43 +00:00
|
|
|
/* out: pointer to the start of the block */
|
2006-12-12 12:14:58 +00:00
|
|
|
ulint size, /* in: block size, up to UNIV_PAGE_SIZE / 2 */
|
|
|
|
ibool lru) /* in: TRUE=allocate from the LRU list if needed */
|
2006-12-07 13:29:04 +00:00
|
|
|
{
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
ut_a(mutex_own(&buf_pool->mutex));
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
|
2006-12-12 12:14:58 +00:00
|
|
|
return(buf_buddy_alloc_low(buf_buddy_get_slot(size), lru));
|
2006-12-07 13:29:04 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 15:22:44 +00:00
|
|
|
/**************************************************************************
|
2006-12-11 09:54:13 +00:00
|
|
|
Deallocate a block. */
|
2006-12-07 15:22:44 +00:00
|
|
|
UNIV_INLINE
|
2006-12-11 09:54:13 +00:00
|
|
|
void
|
2006-12-07 15:22:44 +00:00
|
|
|
buf_buddy_free(
|
|
|
|
/*===========*/
|
|
|
|
void* buf, /* in: block to free */
|
|
|
|
ulint size) /* in: block size, up to UNIV_PAGE_SIZE / 2 */
|
|
|
|
{
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
|
|
ut_a(mutex_own(&buf_pool->mutex));
|
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
|
2006-12-11 09:54:13 +00:00
|
|
|
buf_buddy_free_low(buf, buf_buddy_get_slot(size));
|
2006-12-07 15:22:44 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 13:29:04 +00:00
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
|
|
# undef UNIV_INLINE
|
|
|
|
# define UNIV_INLINE UNIV_INLINE_ORIGINAL
|
|
|
|
#endif
|