Commit d66c2bae authored by John Esmet's avatar John Esmet

fixes #172 Moved memarena to util, made its public API more consistent with

the rest of the code
parent 86bcfa6c
......@@ -52,7 +52,6 @@ set(FT_SOURCES
logfilemgr
logger
log_upgrade
memarena
minicron
omt
pqueue
......
......@@ -2607,7 +2607,7 @@ serialize_rollback_log_size(ROLLBACK_LOG_NODE log) {
+8 //blocknum
+8 //previous (blocknum)
+8 //resident_bytecount
+8 //memarena_size_needed_to_load
+8 //memarena size
+log->rollentry_resident_bytecount;
return size;
}
......@@ -2628,7 +2628,7 @@ serialize_rollback_log_node_to_buf(ROLLBACK_LOG_NODE log, char *buf, size_t calc
wbuf_nocrc_BLOCKNUM(&wb, log->previous);
wbuf_nocrc_ulonglong(&wb, log->rollentry_resident_bytecount);
//Write down memarena size needed to restore
wbuf_nocrc_ulonglong(&wb, memarena_total_size_in_use(log->rollentry_arena));
wbuf_nocrc_ulonglong(&wb, toku_memarena_total_size_in_use(log->rollentry_arena));
{
//Store rollback logs
......@@ -2792,8 +2792,8 @@ deserialize_rollback_log_from_rbuf (BLOCKNUM blocknum, ROLLBACK_LOG_NODE *log_p,
result->rollentry_resident_bytecount = rbuf_ulonglong(rb);
size_t arena_initial_size = rbuf_ulonglong(rb);
result->rollentry_arena = memarena_create_presized(arena_initial_size);
if (0) { died1: memarena_close(&result->rollentry_arena); goto died0; }
result->rollentry_arena = toku_memarena_create_presized(arena_initial_size);
if (0) { died1: toku_memarena_destroy(&result->rollentry_arena); goto died0; }
//Load rollback entries
lazy_assert(rb->size > 4);
......
......@@ -99,15 +99,17 @@ PATENT RIGHTS GRANT:
#include "ft-internal.h"
#include "log.h"
#include "toku_list.h"
#include "memarena.h"
#include "logfilemgr.h"
#include "txn.h"
#include "txn_manager.h"
#include <portability/toku_pthread.h>
#include <util/omt.h>
#include "rollback_log_node_cache.h"
#include "txn_child_manager.h"
#include <portability/toku_pthread.h>
#include <util/memarena.h>
#include <util/omt.h>
using namespace toku;
// Locking for the logger
// For most purposes we use the big ydb lock.
......
......@@ -806,7 +806,7 @@ generate_rollbacks (void) {
DO_ROLLBACKS(lt, {
fprintf(cf, " case RT_%s:\n", lt->name);
fprintf(cf, " mem_needed = sizeof(item->u.%s) + __builtin_offsetof(struct roll_entry, u.%s);\n", lt->name, lt->name);
fprintf(cf, " CAST_FROM_VOIDP(item, malloc_in_memarena(ma, mem_needed));\n");
fprintf(cf, " CAST_FROM_VOIDP(item, toku_memarena_malloc(ma, mem_needed));\n");
fprintf(cf, " item->cmd = cmd;\n");
DO_FIELDS(field_type, lt, fprintf(cf, " rbuf_ma_%s(&rc, ma, &item->u.%s.%s);\n", field_type->type, lt->name, field_type->name));
fprintf(cf, " *itemp = item;\n");
......@@ -858,7 +858,7 @@ int main (int argc, const char *const argv[]) {
fprintf2(cf, pf, "#include <ft/fttypes.h>\n");
fprintf2(cf, pf, "#include <ft/log-internal.h>\n");
fprintf(hf, "#include <ft/ft-internal.h>\n");
fprintf(hf, "#include <ft/memarena.h>\n");
fprintf(hf, "#include <util/memarena.h>\n");
generate_enum();
generate_log_struct();
generate_dispatch();
......
......@@ -93,12 +93,12 @@ PATENT RIGHTS GRANT:
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <toku_portability.h>
#include "memarena.h"
#include "toku_assert.h"
#include "fttypes.h"
#include "memory.h"
#include <toku_htonl.h>
#include <util/memarena.h>
struct rbuf {
unsigned char *buf;
......@@ -250,7 +250,7 @@ static inline void rbuf_FILENUMS(struct rbuf *r, FILENUMS *filenums) {
// 2954
static inline void rbuf_ma_FILENUMS (struct rbuf *r, MEMARENA ma __attribute__((__unused__)), FILENUMS *filenums) {
rbuf_ma_uint32_t(r, ma, &(filenums->num));
filenums->filenums = (FILENUM *) malloc_in_memarena(ma, filenums->num * sizeof(FILENUM) );
filenums->filenums = (FILENUM *) toku_memarena_malloc(ma, filenums->num * sizeof(FILENUM) );
assert(filenums->filenums != NULL);
for (uint32_t i=0; i < filenums->num; i++) {
rbuf_ma_FILENUM(r, ma, &(filenums->filenums[i]));
......@@ -271,7 +271,7 @@ static inline void rbuf_ma_BYTESTRING (struct rbuf *r, MEMARENA ma, BYTESTRING
bs->len = rbuf_int(r);
uint32_t newndone = r->ndone + bs->len;
assert(newndone <= r->size);
bs->data = (char *) memarena_memdup(ma, &r->buf[r->ndone], (size_t)bs->len);
bs->data = (char *) toku_memarena_memdup(ma, &r->buf[r->ndone], (size_t)bs->len);
assert(bs->data);
r->ndone = newndone;
}
......
......@@ -258,9 +258,9 @@ int toku_rollback_commit(TOKUTXN txn, LSN lsn) {
}
child_log->newest_logentry = child_log->oldest_logentry = 0;
// Put all the memarena data into the parent.
if (memarena_total_size_in_use(child_log->rollentry_arena) > 0) {
if (toku_memarena_total_size_in_use(child_log->rollentry_arena) > 0) {
// If there are no bytes to move, then just leave things alone, and let the memory be reclaimed on txn is closed.
memarena_move_buffers(parent_log->rollentry_arena, child_log->rollentry_arena);
toku_memarena_move_buffers(parent_log->rollentry_arena, child_log->rollentry_arena);
}
// each txn tries to give back at most one rollback log node
// to the cache. All other rollback log nodes for this child
......
......@@ -89,15 +89,15 @@ PATENT RIGHTS GRANT:
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include "rollback-ct-callbacks.h"
#include <toku_portability.h>
#include <memory.h>
#include "ft-internal.h"
#include "fttypes.h"
#include "memarena.h"
#include "rollback.h"
#include "rollback-ct-callbacks.h"
#include <util/memarena.h>
// Address used as a sentinel. Otherwise unused.
static struct serialized_rollback_log_node cloned_rollback;
......
......@@ -121,7 +121,7 @@ toku_find_xid_by_xid (const TXNID &xid, const TXNID &xidfind) {
}
void *toku_malloc_in_rollback(ROLLBACK_LOG_NODE log, size_t size) {
return malloc_in_memarena(log->rollentry_arena, size);
return toku_memarena_malloc(log->rollentry_arena, size);
}
void *toku_memdup_in_rollback(ROLLBACK_LOG_NODE log, const void *v, size_t len) {
......@@ -146,7 +146,7 @@ PAIR_ATTR
rollback_memory_size(ROLLBACK_LOG_NODE log) {
size_t size = sizeof(*log);
if (log->rollentry_arena) {
size += memarena_total_footprint(log->rollentry_arena);
size += toku_memarena_total_footprint(log->rollentry_arena);
}
return make_rollback_pair_attr(size);
}
......@@ -192,13 +192,13 @@ static void rollback_initialize_for_txn(
log->previous = previous;
log->oldest_logentry = NULL;
log->newest_logentry = NULL;
log->rollentry_arena = memarena_create();
log->rollentry_arena = toku_memarena_create();
log->rollentry_resident_bytecount = 0;
log->dirty = true;
}
void make_rollback_log_empty(ROLLBACK_LOG_NODE log) {
memarena_close(&log->rollentry_arena);
toku_memarena_destroy(&log->rollentry_arena);
rollback_empty_log_init(log);
}
......
......@@ -2,6 +2,7 @@ set(util_srcs
context
frwlock
kibbutz
memarena
mempool
partitioned_counter
threadpool
......
......@@ -92,7 +92,7 @@ PATENT RIGHTS GRANT:
#include <string.h>
#include <memory.h>
#include "memarena.h"
#include <util/memarena.h>
struct memarena {
char *buf;
......@@ -103,7 +103,7 @@ struct memarena {
int n_other_bufs;
};
MEMARENA memarena_create_presized (size_t initial_size) {
MEMARENA toku_memarena_create_presized (size_t initial_size) {
MEMARENA XMALLOC(result);
result->buf_size = initial_size;
result->buf_used = 0;
......@@ -115,11 +115,11 @@ MEMARENA memarena_create_presized (size_t initial_size) {
return result;
}
MEMARENA memarena_create (void) {
return memarena_create_presized(1024);
MEMARENA toku_memarena_create (void) {
return toku_memarena_create_presized(1024);
}
void memarena_clear (MEMARENA ma) {
void toku_memarena_clear (MEMARENA ma) {
// Free the other bufs.
int i;
for (i=0; i<ma->n_other_bufs; i++) {
......@@ -143,7 +143,7 @@ round_to_page (size_t size) {
return result;
}
void* malloc_in_memarena (MEMARENA ma, size_t size) {
void* toku_memarena_malloc (MEMARENA ma, size_t size) {
if (ma->buf_size < ma->buf_used + size) {
// The existing block isn't big enough.
// Add the block to the vector of blocks.
......@@ -172,13 +172,13 @@ void* malloc_in_memarena (MEMARENA ma, size_t size) {
return result;
}
void *memarena_memdup (MEMARENA ma, const void *v, size_t len) {
void *r=malloc_in_memarena(ma, len);
void *toku_memarena_memdup (MEMARENA ma, const void *v, size_t len) {
void *r=toku_memarena_malloc(ma, len);
memcpy(r,v,len);
return r;
}
void memarena_close(MEMARENA *map) {
void toku_memarena_destroy(MEMARENA *map) {
MEMARENA ma=*map;
if (ma->buf) {
toku_free(ma->buf);
......@@ -200,7 +200,7 @@ void memarena_close(MEMARENA *map) {
#include <crtdbg.h>
#endif
void memarena_move_buffers(MEMARENA dest, MEMARENA source) {
void toku_memarena_move_buffers(MEMARENA dest, MEMARENA source) {
int i;
char **other_bufs = dest->other_bufs;
static int move_counter = 0;
......@@ -241,21 +241,21 @@ void memarena_move_buffers(MEMARENA dest, MEMARENA source) {
}
size_t
memarena_total_memory_size (MEMARENA m)
toku_memarena_total_memory_size (MEMARENA m)
{
return (memarena_total_size_in_use(m) +
return (toku_memarena_total_size_in_use(m) +
sizeof(*m) +
m->n_other_bufs * sizeof(*m->other_bufs));
}
size_t
memarena_total_size_in_use (MEMARENA m)
toku_memarena_total_size_in_use (MEMARENA m)
{
return m->size_of_other_bufs + m->buf_used;
}
size_t
memarena_total_footprint (MEMARENA m)
toku_memarena_total_footprint (MEMARENA m)
{
return m->footprint_of_other_bufs + toku_memory_footprint(m->buf, m->buf_used) +
sizeof(*m) +
......
......@@ -102,33 +102,35 @@ PATENT RIGHTS GRANT:
* A memarena (as currently implemented) is not suitable for interprocess memory sharing. No reason it couldn't be made to work though.
*/
#include "fttypes.h"
struct memarena;
MEMARENA memarena_create_presized (size_t initial_size);
typedef struct memarena *MEMARENA;
MEMARENA toku_memarena_create_presized (size_t initial_size);
// Effect: Create a memarena with initial size. In case of ENOMEM, aborts.
MEMARENA memarena_create (void);
MEMARENA toku_memarena_create (void);
// Effect: Create a memarena with default initial size. In case of ENOMEM, aborts.
void memarena_clear (MEMARENA ma);
void toku_memarena_clear (MEMARENA ma);
// Effect: Reset the internal state so that the allocated memory can be used again.
void* malloc_in_memarena (MEMARENA ma, size_t size);
void* toku_memarena_malloc (MEMARENA ma, size_t size);
// Effect: Allocate some memory. The returned value remains valid until the memarena is cleared or closed.
// In case of ENOMEM, aborts.
void *memarena_memdup (MEMARENA ma, const void *v, size_t len);
void *toku_memarena_memdup (MEMARENA ma, const void *v, size_t len);
void memarena_close(MEMARENA *ma);
void toku_memarena_destroy(MEMARENA *ma);
void memarena_move_buffers(MEMARENA dest, MEMARENA source);
void toku_memarena_move_buffers(MEMARENA dest, MEMARENA source);
// Effect: Move all the memory from SOURCE into DEST. When SOURCE is closed the memory won't be freed. When DEST is closed, the memory will be freed. (Unless DEST moves its memory to another memarena...)
size_t memarena_total_memory_size (MEMARENA);
size_t toku_memarena_total_memory_size (MEMARENA);
// Effect: Calculate the amount of memory used by a memory arena.
size_t memarena_total_size_in_use (MEMARENA);
size_t toku_memarena_total_size_in_use (MEMARENA);
size_t memarena_total_footprint (MEMARENA);
size_t toku_memarena_total_footprint (MEMARENA);
#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