Commit 67dc4d5e authored by Rich Prohaska's avatar Rich Prohaska

addresses #8

git-svn-id: file:///svn/tokudb@807 c7de825b-a66e-492c-adef-691d508d4ae1
parent 64dbec8b
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <assert.h> #include <assert.h>
#include "mempool.h" #include "mempool.h"
void mempool_init(struct mempool *mp, void *base, int size) { void toku_mempool_init(struct mempool *mp, void *base, int size) {
// printf("mempool_init %p %p %d\n", mp, base, size); // printf("mempool_init %p %p %d\n", mp, base, size);
assert(base != 0 && size >= 0); assert(base != 0 && size >= 0);
mp->base = base; mp->base = base;
...@@ -13,32 +13,32 @@ void mempool_init(struct mempool *mp, void *base, int size) { ...@@ -13,32 +13,32 @@ void mempool_init(struct mempool *mp, void *base, int size) {
mp->compress_arg = 0; mp->compress_arg = 0;
} }
void mempool_fini(struct mempool *mp __attribute__((unused))) { void toku_mempool_fini(struct mempool *mp __attribute__((unused))) {
// printf("mempool_fini %p %p %d %d\n", mp, mp->base, mp->size, mp->frag_size); // printf("mempool_fini %p %p %d %d\n", mp, mp->base, mp->size, mp->frag_size);
} }
void mempool_set_compress_func(struct mempool *mp, mempool_compress_func compress_func, void *compress_arg) { void toku_mempool_set_compress_func(struct mempool *mp, mempool_compress_func compress_func, void *compress_arg) {
mp->compress_func = compress_func; mp->compress_func = compress_func;
mp->compress_arg = compress_arg; mp->compress_arg = compress_arg;
} }
void mempool_call_compress_func(struct mempool *mp) { void toku_mempool_call_compress_func(struct mempool *mp) {
mp->compress_func(mp, mp->compress_arg); mp->compress_func(mp, mp->compress_arg);
} }
void *mempool_get_base(struct mempool *mp) { void *toku_mempool_get_base(struct mempool *mp) {
return mp->base; return mp->base;
} }
int mempool_get_size(struct mempool *mp) { int toku_mempool_get_size(struct mempool *mp) {
return mp->size; return mp->size;
} }
int mempool_get_frag_size(struct mempool *mp) { int toku_mempool_get_frag_size(struct mempool *mp) {
return mp->frag_size; return mp->frag_size;
} }
void *mempool_malloc(struct mempool *mp, int size, int alignment) { void *toku_mempool_malloc(struct mempool *mp, int size, int alignment) {
assert(mp->free_offset <= mp->size); assert(mp->free_offset <= mp->size);
void *vp; void *vp;
int offset = (mp->free_offset + (alignment-1)) & ~(alignment-1); int offset = (mp->free_offset + (alignment-1)) & ~(alignment-1);
...@@ -54,7 +54,7 @@ void *mempool_malloc(struct mempool *mp, int size, int alignment) { ...@@ -54,7 +54,7 @@ void *mempool_malloc(struct mempool *mp, int size, int alignment) {
return vp; return vp;
} }
void mempool_mfree(struct mempool *mp, void *vp, int size) { void toku_mempool_mfree(struct mempool *mp, void *vp, int size) {
assert(size >= 0 && mp->base <= vp && vp + size <= mp->base + mp->size); assert(size >= 0 && mp->base <= vp && vp + size <= mp->base + mp->size);
mp->frag_size += size; mp->frag_size += size;
assert(mp->frag_size <= mp->size); assert(mp->frag_size <= mp->size);
......
...@@ -21,33 +21,33 @@ struct mempool { ...@@ -21,33 +21,33 @@ struct mempool {
/* initialize the memory pool with the base address and size of a /* initialize the memory pool with the base address and size of a
contiguous chunk of memory */ contiguous chunk of memory */
void mempool_init(struct mempool *mp, void *base, int size); void toku_mempool_init(struct mempool *mp, void *base, int size);
/* finalize the memory pool */ /* finalize the memory pool */
void mempool_fini(struct mempool *mp); void toku_mempool_fini(struct mempool *mp);
void mempool_set_compress_func(struct mempool *mp, mempool_compress_func compress_func, void *compress_arg); void toku_mempool_set_compress_func(struct mempool *mp, mempool_compress_func compress_func, void *compress_arg);
void mempool_call_compress_func(struct mempool *mp); void toku_mempool_call_compress_func(struct mempool *mp);
/* get the base address of the memory pool */ /* get the base address of the memory pool */
void *mempool_get_base(struct mempool *mp); void *toku_mempool_get_base(struct mempool *mp);
/* get the size of the memory pool */ /* get the size of the memory pool */
int mempool_get_size(struct mempool *mp); int toku_mempool_get_size(struct mempool *mp);
/* get the amount of fragmented space in the memory pool */ /* get the amount of fragmented space in the memory pool */
int mempool_get_frag_size(struct mempool *mp); int toku_mempool_get_frag_size(struct mempool *mp);
/* allocate a chunk of memory from the memory pool suitably aligned */ /* allocate a chunk of memory from the memory pool suitably aligned */
void *mempool_malloc(struct mempool *mp, int size, int alignment); void *toku_mempool_malloc(struct mempool *mp, int size, int alignment);
/* free a previously allocated chunk of memory. the free only updates /* free a previously allocated chunk of memory. the free only updates
a count of the amount of free space in the memory pool. the memory a count of the amount of free space in the memory pool. the memory
pool does not keep track of the locations of the free chunks */ pool does not keep track of the locations of the free chunks */
void mempool_mfree(struct mempool *mp, void *vp, int size); void toku_mempool_mfree(struct mempool *mp, void *vp, int size);
static inline int mempool_inrange(struct mempool *mp, void *vp, int size) { static inline int toku_mempool_inrange(struct mempool *mp, void *vp, int size) {
return mp->base <= vp && vp + size <= mp->base + mp->size; return mp->base <= vp && vp + size <= mp->base + mp->size;
} }
......
...@@ -104,7 +104,7 @@ struct kv_pair_tag { ...@@ -104,7 +104,7 @@ struct kv_pair_tag {
/* allocate a kv pair from the pma kv memory pool */ /* allocate a kv pair from the pma kv memory pool */
static struct kv_pair *kv_pair_malloc_mempool(void *key, int keylen, void *val, int vallen, struct mempool *mp) { static struct kv_pair *kv_pair_malloc_mempool(void *key, int keylen, void *val, int vallen, struct mempool *mp) {
struct kv_pair *kv = mempool_malloc(mp, sizeof (struct kv_pair) + keylen + vallen, 4); struct kv_pair *kv = toku_mempool_malloc(mp, sizeof (struct kv_pair) + keylen + vallen, 4);
if (kv) if (kv)
kv_pair_init(kv, key, keylen, val, vallen); kv_pair_init(kv, key, keylen, val, vallen);
return kv; return kv;
...@@ -113,19 +113,19 @@ static struct kv_pair *kv_pair_malloc_mempool(void *key, int keylen, void *val, ...@@ -113,19 +113,19 @@ static struct kv_pair *kv_pair_malloc_mempool(void *key, int keylen, void *val,
/* compress all of the kv pairs to the left edge of the memory pool and /* compress all of the kv pairs to the left edge of the memory pool and
update the pma index with the new kv pair locations */ update the pma index with the new kv pair locations */
static int pma_compress_kvspace(PMA pma) { static int pma_compress_kvspace(PMA pma) {
if (mempool_get_frag_size(&pma->kvspace) == 0) if (toku_mempool_get_frag_size(&pma->kvspace) == 0)
return -1; return -1;
void *mp = toku_malloc(pma->kvspace.size); void *mp = toku_malloc(pma->kvspace.size);
if (mp == 0) if (mp == 0)
return -2; return -2;
struct mempool new_kvspace; struct mempool new_kvspace;
mempool_init(&new_kvspace, mp, pma->kvspace.size); toku_mempool_init(&new_kvspace, mp, pma->kvspace.size);
int i; int i;
for (i=0; i<pma->N; i++) { for (i=0; i<pma->N; i++) {
struct kv_pair *kv = pma->pairs[i]; struct kv_pair *kv = pma->pairs[i];
if (kv_pair_inuse(kv)) { if (kv_pair_inuse(kv)) {
kv = kv_pair_ptr(kv); kv = kv_pair_ptr(kv);
struct kv_pair *newkv = mempool_malloc(&new_kvspace, kv_pair_size(kv), 4); struct kv_pair *newkv = toku_mempool_malloc(&new_kvspace, kv_pair_size(kv), 4);
assert(newkv); assert(newkv);
memcpy(newkv, kv, kv_pair_size(kv)); memcpy(newkv, kv, kv_pair_size(kv));
if (kv_pair_deleted(pma->pairs[i])) if (kv_pair_deleted(pma->pairs[i]))
...@@ -158,7 +158,7 @@ static struct kv_pair *pma_malloc_kv_pair(PMA pma __attribute__((unused)), void ...@@ -158,7 +158,7 @@ static struct kv_pair *pma_malloc_kv_pair(PMA pma __attribute__((unused)), void
static void pma_mfree_kv_pair(PMA pma __attribute__((unused)), struct kv_pair *kv) { static void pma_mfree_kv_pair(PMA pma __attribute__((unused)), struct kv_pair *kv) {
kv = kv_pair_ptr(kv); kv = kv_pair_ptr(kv);
#if PMA_USE_MEMPOOL #if PMA_USE_MEMPOOL
mempool_mfree(&pma->kvspace, kv, kv_pair_size(kv)); toku_mempool_mfree(&pma->kvspace, kv, kv_pair_size(kv));
#else #else
kv_pair_free(kv); kv_pair_free(kv);
#endif #endif
...@@ -609,7 +609,7 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil ...@@ -609,7 +609,7 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil
maxsize = maxsize + maxsize/4; maxsize = maxsize + maxsize/4;
#if PMA_USE_MEMPOOL #if PMA_USE_MEMPOOL
void *mpbase = toku_malloc(maxsize); assert(mpbase); void *mpbase = toku_malloc(maxsize); assert(mpbase);
mempool_init(&result->kvspace, mpbase, maxsize); toku_mempool_init(&result->kvspace, mpbase, maxsize);
#endif #endif
*pma = result; *pma = result;
assert((unsigned long)result->pairs[result->N]==0xdeadbeefL); assert((unsigned long)result->pairs[result->N]==0xdeadbeefL);
...@@ -961,8 +961,8 @@ int toku_pma_free (PMA *pmap) { ...@@ -961,8 +961,8 @@ int toku_pma_free (PMA *pmap) {
} }
assert(pma->n_pairs_present == 0); assert(pma->n_pairs_present == 0);
#if PMA_USE_MEMPOOL #if PMA_USE_MEMPOOL
void *mpbase = mempool_get_base(&pma->kvspace); void *mpbase = toku_mempool_get_base(&pma->kvspace);
mempool_fini(&pma->kvspace); toku_mempool_fini(&pma->kvspace);
toku_free(mpbase); toku_free(mpbase);
#endif #endif
toku_free(pma->pairs); toku_free(pma->pairs);
...@@ -1582,7 +1582,7 @@ void toku_pma_verify(PMA pma) { ...@@ -1582,7 +1582,7 @@ void toku_pma_verify(PMA pma) {
kv = pma->pairs[i]; kv = pma->pairs[i];
if (kv_pair_inuse(kv)) { if (kv_pair_inuse(kv)) {
kv = kv_pair_ptr(kv); kv = kv_pair_ptr(kv);
assert(mempool_inrange(&pma->kvspace, kv, kv_pair_size(kv))); assert(toku_mempool_inrange(&pma->kvspace, kv, kv_pair_size(kv)));
} }
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment