aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2001-10-19 06:09:29 +0000
committerH. Peter Anvin <hpa@zytor.com>2001-10-19 06:09:29 +0000
commit7699ea1cbb2cbdc7a81279b23fd4eafe188d99dc (patch)
tree173e73ac01d7678be9f82bc5bfe74ce0dd5c938b
parent6f9d2dab5ff8d60ed805a821e9c7d2272c753e81 (diff)
downloadlpsm-7699ea1cbb2cbdc7a81279b23fd4eafe188d99dc.tar.gz
lpsm-7699ea1cbb2cbdc7a81279b23fd4eafe188d99dc.tar.xz
lpsm-7699ea1cbb2cbdc7a81279b23fd4eafe188d99dc.zip
Change names around to be more consistent; set the name of the system to
LPSM (Linux Persistent Memory); set the load address to 0x58000000 on i386 (in case we're on x86-64 in 32-bit mode, or using Andrea's 3.5G patches); change symbol names throughout. Add README file.
-rw-r--r--Makefile54
-rw-r--r--README203
-rw-r--r--alloc.c130
-rw-r--r--arena.c80
-rw-r--r--internals.h4
-rw-r--r--lpsm.h46
-rw-r--r--sysdep/i386.h5
-rw-r--r--testalloc.c20
-rw-r--r--testbuddy.c12
-rw-r--r--testrecovery.c30
-rw-r--r--teststore.c12
11 files changed, 402 insertions, 194 deletions
diff --git a/Makefile b/Makefile
index 405c629..1172916 100644
--- a/Makefile
+++ b/Makefile
@@ -1,29 +1,29 @@
TEST = teststore test_mmap ftrunctest testbuddy testalloc testrecovery
-SONAME = libobjstore.so.0
-VERSION = 0.0.1
-OBJSTORE = libobjstore.so libobjstore.a
+SONAME = libpsm.so.0
+VERSION = 0.1.0
+LIBPSM = libpsm.so libpsm.a
-OSOBJ = objstore.o alloc.o
+OSOBJ = arena.o alloc.o
OSPICOBJ = $(patsubst %.o,%.pic.o,$(OSOBJ))
CC = gcc
# This is a reasonable set of flags for production
-# CFLAGS = -I. -Wall -O3 -fomit-frame-pointer -DNDEBUG -D_FILE_OFFSET_BITS=64
-# LDFLAGS =
+CFLAGS = -I. -Wall -O3 -fomit-frame-pointer -DNDEBUG -D_FILE_OFFSET_BITS=64
+LDFLAGS =
# This is for debugging
-CFLAGS = -I. -Wall -O -g -D_FILE_OFFSET_BITS=64
-LDFLAGS = -g
+# CFLAGS = -I. -Wall -O -g -D_FILE_OFFSET_BITS=64
+# LDFLAGS = -g
PICFLAGS = $(CFLAGS) -fPIC
SOFLAGS = -shared
AR = ar cq
RANLIB = ranlib
-all: $(OBJSTORE) $(TEST)
+all: $(LIBPSM) $(TEST)
clean:
- rm -f *.o *~ core *.dat *.log $(OBJSTORE) $(TEST)
- rm -f libobjstore.so.*
+ rm -f *.o *~ core *.dat *.log $(LIBPSM) $(TEST)
+ rm -f libpsm.so.*
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
@@ -31,27 +31,27 @@ clean:
%.pic.o: %.c
$(CC) $(PICFLAGS) -o $@ -c $<
-libobjstore.so: $(OSPICOBJ)
- $(CC) $(SOFLAGS) -Wl,-soname,$(SONAME) -o libobjstore.so.$(VERSION) $(OSPICOBJ)
- ln -sf libobjstore.so.$(VERSION) $(SONAME)
- ln -sf libobjstore.so.$(VERSION) libobjstore.so
+libpsm.so: $(OSPICOBJ)
+ $(CC) $(SOFLAGS) -Wl,-soname,$(SONAME) -o libpsm.so.$(VERSION) $(OSPICOBJ)
+ ln -sf libpsm.so.$(VERSION) $(SONAME)
+ ln -sf libpsm.so.$(VERSION) libpsm.so
-libobjstore.a: $(OSOBJ)
- rm -f libobjstore.a
- $(AR) libobjstore.a $(OSOBJ)
- $(RANLIB) libobjstore.a
+libpsm.a: $(OSOBJ)
+ rm -f libpsm.a
+ $(AR) libpsm.a $(OSOBJ)
+ $(RANLIB) libpsm.a
-teststore: teststore.o libobjstore.a
- $(CC) $(LDFLAGS) -o $@ $< libobjstore.a
+teststore: teststore.o libpsm.a
+ $(CC) $(LDFLAGS) -o $@ $< libpsm.a
-testbuddy: testbuddy.o libobjstore.a
- $(CC) $(LDFLAGS) -o $@ $< libobjstore.a
+testbuddy: testbuddy.o libpsm.a
+ $(CC) $(LDFLAGS) -o $@ $< libpsm.a
-testalloc: testalloc.o libobjstore.a
- $(CC) $(LDFLAGS) -o $@ $< libobjstore.a
+testalloc: testalloc.o libpsm.a
+ $(CC) $(LDFLAGS) -o $@ $< libpsm.a
-testrecovery: testrecovery.o libobjstore.a
- $(CC) $(LDFLAGS) -o $@ $< libobjstore.a
+testrecovery: testrecovery.o libpsm.a
+ $(CC) $(LDFLAGS) -o $@ $< libpsm.a
test_mmap: test_mmap.o
$(CC) $(LDFLAGS) -o $@ $<
diff --git a/README b/README
new file mode 100644
index 0000000..74433b9
--- /dev/null
+++ b/README
@@ -0,0 +1,203 @@
+This is a test release of the Linux Persistent Memory system.
+
+Unless otherwise noted, all files in this distributions are:
+
+ Copyright 2001 H. Peter Anvin - All Rights Reserved
+
+See the file COPYING for licensing conditions.
+
+
+If this was a real release there would be some documentation and a
+much better information in this file.
+
+IMPORTANT: I cannot at this stage guarantee that future versions of
+the LPSM will be binary compatible. These are test releases. Use at
+your own risk.
+
+Currently the persistent memory database is not sharable nor
+thread-safe. I'm hoping to resolve at least the latter condition in
+due time.
+
+
+** Functionality description:
+
+The persistent memory store can be used in two modes: managed and
+unmanaged. Unmanaged provides a flat chunk (arena) of memory without
+any further management support; managed provides management via
+malloc/free/realloc.
+
+All of these use a pair of files as backing store: a datafile, which
+is equivalent in size to the managed memory, and a logfile, which is
+used for the commit log.
+
+The LPSM library installs a signal handler for SIGSEGV.
+
+
+* Functions to use in unmanaged mode:
+
+void *lpsm_arena_init(const char *datafile, const char *logfile, size_t *arena_size)
+
+ Open the persistent memory arena that consists of the two
+ files datafile and logfile. If these files don't exist, they
+ are created. The argument "arena_size" contains the minimum
+ size of the arena (if smaller, it will be resized to this
+ size.) On exit, it contains the actual size of the arena.
+
+ It returns a pointer to the arena, or NULL on error.
+
+
+pid_t lpsm_checkpoint(double ratio, enum psmsync wait)
+
+ Called to indicate that the memory arena is currently in a
+ consistent state and is safe to checkpoint. On a crash, the
+ memory arena is ALWAYS guaranteed to be returned to the state
+ as of one of the calls to lpsm_checkpoint(); which exact one
+ depends on the "wait" argument.
+
+ The "ratio" parameter indicates if a log flush should take
+ place; if the logfile is at least "ratio" times the size of
+ the datafile, a log flush (replay the log into the datafile
+ and truncate the logfile) will happen once the log has been
+ written. Specify 0.0 to do a log flush every time, HUGE_VAL
+ to specify that no log flush should happen.
+
+ The "wait" parameter controls the level of asynchronicity of
+ the checkpoint process:
+
+ PSMSYNC_NONE - A checkpoint is unconditionally forked, and
+ not waited for. The application is responsible for handing
+ or ignoring the resulting SIGCHLD. This provides no
+ guarantees that a checkpoint is complete until the SIGCHLD
+ comes back.
+
+ PSMSYNC_SKIP - wait() for the previous checkpoint process,
+ if it is still running, skip this checkpoint opportunity.
+ This provides no guarantees for which checkpoint opportunity
+ will be used in the event of a crash, but is useful if
+ checkpoint opportunities are very frequent, and continued
+ execution of the master process is important.
+
+ PSMSYNC_WAIT - wait() for the previous checkpoint process,
+ if it is still running, sleep until the previous checkpoint
+ process has finished. This guarantees that in the event of a
+ crash, the recovery point will be no later that one checkpoint
+ *before* the latest checkpoint executed.
+
+ PSMSYNC_SYNC - wait() for the previous *and* current
+ checkpoint processes. This guarantees that upon exit of
+ lpsm_checkpoint() the persistent memory is fully consistent on
+ disk. This guarantees that in the event of a crash, the
+ recovery point will be no later than the latest checkpoint
+ executed. This is typically used with a "ratio" argument of
+ 0.0 to perform a clean shutdown.
+
+ lpsm_checkpoint() returns (pid_t)-1 on error; on success, it returns
+ 0 if no asynchronous checkpoint process is pending, otherwise
+ the pid of the asynchronous checkpoint process.
+
+
+int lpsm_extend(size_t newsize)
+
+ Extends the size of the arena to "newsize". Returns 0 on
+ success, -1 on error.
+
+
+void lpsm_shutdown(void)
+
+ Shuts down the persistent memory system, frees all resources,
+ and restores the previous state of the SIGSEGV signal handler.
+ IT DOES NOT PERFORM A CHECKPOINT BEFORE DOING SO -- normally a
+ clean shutdown is performed as:
+
+ lpsm_checkpoint(0.0, PSMSYNC_SYNC);
+ lpsm_shutdown();
+
+ Calling lpsm_shutdown() followed by lpsm_arena_init() or
+ lpsm_init() can be used in exceptional events to reinitialize
+ the arena to the last checkpointed state. This is very slow,
+ however.
+
+
+* Functions to use in managed mode:
+
+void **lpsm_init(const char *datafile, const char *logfile)
+
+ Opens/creates the managed persistent memory store defined by
+ datafile and logfile. On success, returns a pointer to an
+ array of LPSM_ROOT_POINTERS (32) "root pointers" (void *),
+ which are available for the application to point to its
+ fundamental data structures. On failure, returns NULL.
+
+
+void *lpsm_malloc(size_t size)
+
+ Allocates "size" bytes of persistent memory. Returns a
+ pointer to the newly allocated memory, or NULL on failure.
+ The memory is uninitialized.
+
+
+void lpsm_free(void *ptr)
+
+ Frees the allocation pointed to by ptr.
+
+
+void *lpsm_realloc(void *ptr, size_t new_size)
+
+ Attempts to resize the allocation pointed to by ptr to size
+ "new_size". Returns a pointer to the new allocation on
+ success, NULL on failure. If the returned pointer is
+ different from ptr, the contents of the old allocation is
+ copied into the new allocation. If new_size is greater than
+ the old size, the bytes beyond the old allocation size are
+ uninitialized.
+
+ If ptr == NULL, this call is equivalent to lpsm_malloc().
+
+ If new_size is zero, this call is equivalent to:
+
+ lpsm_free(ptr);
+ return NULL;
+
+
+struct lpsm_alloc_stats {
+ size_t size;
+ size_t free;
+ size_t alloc;
+};
+struct lpsm_alloc_stats *lpsm_alloc_stats(void);
+
+ Returns an array, malloc()'d in conventional (transient)
+ memory, containing allocation statistics: for each block size,
+ the size in bytes, number of blocks free, and number of blocks
+ allocated (in use). The list terminates with an entry with
+ size == 0. It is the responsibility of the application to
+ free() the allocated list.
+
+ Returns NULL on failure.
+
+
+pid_t lpsm_checkpoint(double ratio, enum psmsync wait)
+
+ Identical function as in unmanaged mode.
+
+
+void lpsm_shutdown(void)
+
+ Identical function as in unmanaged mode.
+
+
+The memory allocator used is a hybrid buddy system/slab allocator,
+which has the following properties:
+
+* Allocation of large blocks are always page-aligned; allocation of
+ powers of 2 is very efficient;
+
+* Allocation of small blocks can be done efficiently down to single
+ bytes. Allocation of small blocks (2032 bytes or less in the
+ current implementation) are aligned to a 16-byte datum unless they
+ are 8 bytes or smaller in size (in which case they are aligned to
+ the nearest higher power of 2.)
+
+* The allocator is very sensitive to bogus pointers passed to
+ lpsm_free() or lpsm_realloc(). Passing bogus pointers to these
+ routines is very likely to result in arena corruption or crash.
diff --git a/alloc.c b/alloc.c
index 0fceeac..401552e 100644
--- a/alloc.c
+++ b/alloc.c
@@ -36,12 +36,12 @@
#define DPRINTF(X)
#endif
-#include "objstore.h"
+#include "lpsm.h"
#include "internals.h"
-static const unsigned char objstore_arena_magic[16] =
+static const unsigned char lpsm_arena_magic[16] =
"\x4f\xd4\x5a\x16\xa0\xaf\xd5\x52\x56\xf1\x1c\x9c\x1c\xed\xcc";
-static const unsigned char objstore_arena_zero[16] =
+static const unsigned char lpsm_arena_zero[16] =
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
#define SLAB_MAGIC 0xec2062ae
@@ -88,7 +88,7 @@ struct arena_header {
int arena_size_lg2; /* Current arena allocation size */
int header_size; /* Size of this header+padding */
struct slab_info slab[SLAB_INFO_COUNT];
- void *root_data_ptrs[ROOT_DATA_POINTERS]; /* Root data pointers - for the user */
+ void *root_data_ptrs[LPSM_ROOT_POINTERS]; /* Root data pointers - for the user */
};
/* This is the minimal order before going to SLAB allocation. */
@@ -297,9 +297,9 @@ void print_statistics(void)
* {block size, free blocks, allocated blocks} followed by an
* all-zero datum.
*/
-struct objstore_arena_stats *objstore_arena_stats(void)
+struct lpsm_alloc_stats *lpsm_alloc_stats(void)
{
- struct objstore_arena_stats *as, *asp;
+ struct lpsm_alloc_stats *as, *asp;
struct slab_info *si;
int nb, ns;
int i, o;
@@ -312,7 +312,7 @@ struct objstore_arena_stats *objstore_arena_stats(void)
if ( !ah->slab[ns].size )
break;
- as = malloc((nb+ns+1) * sizeof(struct objstore_arena_stats));
+ as = malloc((nb+ns+1) * sizeof(struct lpsm_alloc_stats));
if ( !as )
return NULL;
@@ -357,25 +357,25 @@ struct objstore_arena_stats *objstore_arena_stats(void)
* on failure, or a pointer to the "root data pointer" array if
* successful.
*/
-void **objstore_arena_init(const char *main_file, const char *log_file)
+void **lpsm_init(const char *main_file, const char *log_file)
{
size_t arena_len = sizeof(struct arena_header); /* Minimum initial size */
- if ( !objstore_init(main_file, log_file, &arena_len) )
+ if ( !lpsm_arena_init(main_file, log_file, &arena_len) )
return NULL; /* Failed to initialize arena */
- os = objstore_os_struct;
+ os = lpsm_os_struct;
ah = (struct arena_header *)os->arena;
- if ( memcmp(ah->arena_magic, objstore_arena_magic, 16) != 0 ) {
- if ( memcmp(ah->arena_magic, objstore_arena_zero, 16) == 0 ) {
+ if ( memcmp(ah->arena_magic, lpsm_arena_magic, 16) != 0 ) {
+ if ( memcmp(ah->arena_magic, lpsm_arena_zero, 16) == 0 ) {
size_t total_size, bitmap_size;
int i, header_pad;
memset(ah, 0, sizeof(*ah)); /* Just in case */
/* Uninitialized arena */
- memcpy(ah->arena_magic, objstore_arena_magic, 16);
+ memcpy(ah->arena_magic, lpsm_arena_magic, 16);
ah->arena_byteorder = 0x12345678;
ah->arena_bytesize = CHAR_BIT;
ah->arena_ptrsize = sizeof(void *);
@@ -397,7 +397,7 @@ void **objstore_arena_init(const char *main_file, const char *log_file)
ah->free_bitmap = (char *)ah->data_start + ARENA_START_SIZE;
ah->alloc_bitmap = (char *)ah->free_bitmap + bitmap_size;
- if ( objstore_extend(total_size) < 0 )
+ if ( lpsm_extend(total_size) < 0 )
return NULL; /* Failed to establish initial arena */
/* Compute SLAB definitions */
@@ -427,7 +427,7 @@ void **objstore_arena_init(const char *main_file, const char *log_file)
}
}
- if ( memcmp(ah->arena_magic, objstore_arena_magic, 16) != 0 ||
+ if ( memcmp(ah->arena_magic, lpsm_arena_magic, 16) != 0 ||
ah->arena_byteorder != 0x12345678 ||
ah->arena_bytesize != CHAR_BIT ||
ah->arena_ptrsize != sizeof(void *) ||
@@ -448,7 +448,7 @@ void **objstore_arena_init(const char *main_file, const char *log_file)
* Note that "orders" here refers to orders of bitmap, which is usually
* arena_size_lg2 - BUDDY_ORDER_MIN + 1.
*/
-static void objstore_expand_bitmap(void *nbitmap, const void *obitmap, int norder, int oorder)
+static void lpsm_expand_bitmap(void *nbitmap, const void *obitmap, int norder, int oorder)
{
int deltao, o, i, obit, nbit;
int obyte, nbyte;
@@ -479,7 +479,7 @@ static void objstore_expand_bitmap(void *nbitmap, const void *obitmap, int norde
/*
* This function expands the arena to the specified log size.
*/
-static int objstore_extend_arena(int logsize)
+static int lpsm_extend_arena(int logsize)
{
size_t new_arena_size = (size_t)1 << logsize;
size_t total_size;
@@ -497,15 +497,15 @@ static int objstore_extend_arena(int logsize)
newfreemap = (char *)ah->data_start + new_arena_size;
newallocmap = (char *)newfreemap + bitmap_size;
- if ( objstore_extend(total_size) < 0 ) {
+ if ( lpsm_extend(total_size) < 0 ) {
DPRINTF(("failed\n"));
return -1; /* Extension failed */
}
/* Otherwise, we just extended the area; reconstruct the bitmaps */
- objstore_expand_bitmap(newfreemap, ah->free_bitmap,
+ lpsm_expand_bitmap(newfreemap, ah->free_bitmap,
logsize-BUDDY_ORDER_MIN+1, ologsize-BUDDY_ORDER_MIN+1);
- objstore_expand_bitmap(newallocmap, ah->alloc_bitmap,
+ lpsm_expand_bitmap(newallocmap, ah->alloc_bitmap,
logsize-BUDDY_ORDER_MIN+1, ologsize-BUDDY_ORDER_MIN+1);
ah->free_bitmap = newfreemap;
ah->alloc_bitmap = newallocmap;
@@ -536,7 +536,7 @@ static int objstore_extend_arena(int logsize)
* but does not mark it as an "allocation" in the allocation bitmap (the latter
* is used to determine what size free() we need to do.
*/
-static int objstore_find_free_chunk(int rorder)
+static int lpsm_find_free_chunk(int rorder)
{
int obit, xbit;
@@ -546,7 +546,7 @@ static int objstore_find_free_chunk(int rorder)
if ( !xbit ) {
if ( rorder == 0 )
return 0; /* We're out */
- xbit = objstore_find_free_chunk(rorder-1);
+ xbit = lpsm_find_free_chunk(rorder-1);
if ( !xbit )
return 0; /* All out of those, sir */
DPRINTF(("buddy: splitting rorder %2d %8d -> %d %d\n", rorder-1, xbit, xbit << 1, (xbit << 1)+1));
@@ -560,7 +560,7 @@ static int objstore_find_free_chunk(int rorder)
return xbit;
}
-static void *objstore_malloc_buddy(size_t size)
+static void *lpsm_malloc_buddy(size_t size)
{
int order = BUDDY_ORDER_MIN;
int rorder;
@@ -572,7 +572,7 @@ static void *objstore_malloc_buddy(size_t size)
/* Now we know the order */
if ( order > ah->arena_size_lg2 ) {
- if ( objstore_extend_arena(order+1) )
+ if ( lpsm_extend_arena(order+1) )
return NULL; /* Unable to extend arena */
}
@@ -583,11 +583,11 @@ static void *objstore_malloc_buddy(size_t size)
DPRINTF(("buddy: trying to allocate %d bytes, rorder = %d\n", size, rorder));
- xbit = objstore_find_free_chunk(rorder);
+ xbit = lpsm_find_free_chunk(rorder);
if ( !xbit ) {
/* Need to extend */
print_statistics(); /* DEBUG */
- if ( objstore_extend_arena(ah->arena_size_lg2 + 1) )
+ if ( lpsm_extend_arena(ah->arena_size_lg2 + 1) )
return NULL; /* Failed to extend */
}
} while ( !xbit );
@@ -601,7 +601,7 @@ static void *objstore_malloc_buddy(size_t size)
return p;
}
-static struct slab_header *objstore_make_new_slab(struct slab_info *si, int index)
+static struct slab_header *lpsm_make_new_slab(struct slab_info *si, int index)
{
struct slab_header *sh;
unsigned char *slab_bitmap;
@@ -609,7 +609,7 @@ static struct slab_header *objstore_make_new_slab(struct slab_info *si, int inde
int bitmap_bits_left = si->count & 7;
/* Get a page from the buddy system allocator */
- sh = objstore_malloc_buddy(BUDDY_SIZE_MIN);
+ sh = lpsm_malloc_buddy(BUDDY_SIZE_MIN);
if ( !sh )
return NULL;
@@ -638,7 +638,7 @@ static struct slab_header *objstore_make_new_slab(struct slab_info *si, int inde
return (si->list = sh);
}
-static void *objstore_malloc_slab(size_t size)
+static void *lpsm_malloc_slab(size_t size)
{
int i, index;
int which;
@@ -667,7 +667,7 @@ static void *objstore_malloc_slab(size_t size)
sh = si->list;
if ( !sh ) {
/* Empty free list, need a new page */
- if ( !(sh = objstore_make_new_slab(si,index)) )
+ if ( !(sh = lpsm_make_new_slab(si,index)) )
return NULL; /* Unavailable to allocate new slab */
}
@@ -698,15 +698,15 @@ static void *objstore_malloc_slab(size_t size)
return p;
}
-void *objstore_malloc(size_t size)
+void *lpsm_malloc(size_t size)
{
if ( size > ah->slab[0].size )
- return objstore_malloc_buddy(size);
+ return lpsm_malloc_buddy(size);
else
- return objstore_malloc_slab(size);
+ return lpsm_malloc_slab(size);
}
-static void objstore_free_chunk(int xbit, int rorder)
+static void lpsm_free_chunk(int xbit, int rorder)
{
if ( rorder > 0 ) {
int bxbit = xbit^1; /* Buddy xbit */
@@ -715,7 +715,7 @@ static void objstore_free_chunk(int xbit, int rorder)
clr_bit(ah->free_bitmap, bxbit);
DPRINTF(("buddy: coalescing rorder %2d %d %d -> %2d %d\n",
rorder, xbit, bxbit, rorder-1, (xbit >> 1)));
- objstore_free_chunk((xbit >> 1), rorder-1);
+ lpsm_free_chunk((xbit >> 1), rorder-1);
return;
}
}
@@ -731,7 +731,7 @@ struct buddy_params {
int xbit;
int rorder;
};
-static struct buddy_params objstore_find_alloc_buddy(void *ptr)
+static struct buddy_params lpsm_find_alloc_buddy(void *ptr)
{
struct buddy_params bp;
uintptr_t offset = (uintptr_t)ptr - (uintptr_t)ah->data_start;
@@ -759,18 +759,18 @@ static struct buddy_params objstore_find_alloc_buddy(void *ptr)
abort(); /* Freeing bogus memory? */
}
-static void objstore_free_buddy(void *ptr)
+static void lpsm_free_buddy(void *ptr)
{
struct buddy_params bp;
DPRINTF(("buddy: freeing allocation at %p\n", ptr));
- bp = objstore_find_alloc_buddy(ptr);
+ bp = lpsm_find_alloc_buddy(ptr);
DPRINTF(("buddy: freeing rorder %2d %8d\n", bp.rorder, bp.xbit));
clr_bit(ah->alloc_bitmap, bp.xbit);
- objstore_free_chunk(bp.xbit, bp.rorder);
+ lpsm_free_chunk(bp.xbit, bp.rorder);
}
-static void objstore_free_slab(void *ptr)
+static void lpsm_free_slab(void *ptr)
{
struct slab_header *sh;
struct slab_info *si;
@@ -808,7 +808,7 @@ static void objstore_free_slab(void *ptr)
/* This unfortunately makes the page dirty */
memset(sh, 0, BUDDY_SIZE_MIN);
#endif
- objstore_free_buddy(sh);
+ lpsm_free_buddy(sh);
} else {
set_bit(slab_bitmap, which);
sh->free_count = free_count+1;
@@ -828,23 +828,23 @@ static void objstore_free_slab(void *ptr)
}
}
-void objstore_free(void *ptr)
+void lpsm_free(void *ptr)
{
/* Buddy allocations are ALWAYS page-aligned, SLAB allocations never */
if ( (uintptr_t)ptr & (BUDDY_SIZE_MIN-1) )
- objstore_free_slab(ptr);
+ lpsm_free_slab(ptr);
else
- objstore_free_buddy(ptr);
+ lpsm_free_buddy(ptr);
}
-static void *objstore_realloc_buddy(void *ptr, size_t new_size)
+static void *lpsm_realloc_buddy(void *ptr, size_t new_size)
{
struct buddy_params bp;
int order, rorder;
int xbit, obit, i;
void *nptr;
- bp = objstore_find_alloc_buddy(ptr);
+ bp = lpsm_find_alloc_buddy(ptr);
order = BUDDY_ORDER_MIN;
while ( new_size > ((size_t)1 << order) )
@@ -852,7 +852,7 @@ static void *objstore_realloc_buddy(void *ptr, size_t new_size)
if ( order > ah->arena_size_lg2 ) {
/* Need to extend the arena immediately... */
- if ( objstore_extend_arena(order+1) )
+ if ( lpsm_extend_arena(order+1) )
return NULL;
}
@@ -900,9 +900,9 @@ static void *objstore_realloc_buddy(void *ptr, size_t new_size)
/* A chunk we need is unavailable. Need to copy, sorry... */
DPRINTF(("buddy: unable to reallocate in place, rorder %2d %8d in use\n", i, xbit^1));
- /* Careful. If objstore_malloc_buddy resizes the arena we need to
+ /* Careful. If lpsm_malloc_buddy resizes the arena we need to
adjust the rorder and xbit values afterwards. */
- nptr = objstore_malloc_buddy(new_size);
+ nptr = lpsm_malloc_buddy(new_size);
if ( !nptr )
return NULL; /* realloc failed */
@@ -910,7 +910,7 @@ static void *objstore_realloc_buddy(void *ptr, size_t new_size)
/* Free the old area */
/* Consider later if we can optimize this given the resizing issue */
- objstore_free_buddy(ptr);
+ lpsm_free_buddy(ptr);
return nptr;
}
@@ -952,7 +952,7 @@ static void *objstore_realloc_buddy(void *ptr, size_t new_size)
}
}
-static void *objstore_realloc_slab(void *ptr, size_t new_size)
+static void *lpsm_realloc_slab(void *ptr, size_t new_size)
{
struct slab_header *sh;
struct slab_info *si;
@@ -970,18 +970,18 @@ static void *objstore_realloc_slab(void *ptr, size_t new_size)
factor of four... it's not worth copying then */
if ( new_size > si->size ) {
/* This also covers the possibility of new_size > slab_max */
- void *nptr = objstore_malloc(new_size);
+ void *nptr = lpsm_malloc(new_size);
if ( !nptr )
return NULL;
memcpy(nptr, ptr, si->size);
- objstore_free_slab(ptr);
+ lpsm_free_slab(ptr);
return nptr;
} else if ( new_size < (si->size >> 2) ) {
- void *nptr = objstore_malloc_slab(new_size);
+ void *nptr = lpsm_malloc_slab(new_size);
if ( !nptr )
return ptr; /* Old allocation still OK */
memcpy(nptr, ptr, new_size);
- objstore_free_slab(ptr);
+ lpsm_free_slab(ptr);
return nptr;
} else {
/* Nothing to do... */
@@ -989,36 +989,36 @@ static void *objstore_realloc_slab(void *ptr, size_t new_size)
}
}
-void *objstore_realloc(void *ptr, size_t new_size)
+void *lpsm_realloc(void *ptr, size_t new_size)
{
int is_slab = ((uintptr_t)ptr & (BUDDY_SIZE_MIN-1)) != 0;
int slab_max = ah->slab[0].size;
/* Special cases for "realloc everything" style programming */
- if ( new_size == 0 ) {
- objstore_free(ptr);
+ if ( !ptr )
+ return lpsm_malloc(new_size);
+ else if ( new_size == 0 ) {
+ lpsm_free(ptr);
return NULL;
- } else if ( !ptr ) {
- return objstore_malloc(new_size);
}
DPRINTF(("realloc: ptr = %p, new_size = %d, is_slab = %d\n",
ptr, new_size, is_slab));
if ( is_slab ) {
- /* objstore_realloc_slab() also handles the slab->buddy case */
- return objstore_realloc_slab(ptr, new_size);
+ /* lpsm_realloc_slab() also handles the slab->buddy case */
+ return lpsm_realloc_slab(ptr, new_size);
} else {
/* Currently buddy. */
if ( new_size > slab_max ) {
- return objstore_realloc_buddy(ptr, new_size);
+ return lpsm_realloc_buddy(ptr, new_size);
} else {
/* Buddy shrunk to slab size */
- void *nptr = objstore_malloc_slab(new_size);
+ void *nptr = lpsm_malloc_slab(new_size);
if ( !nptr )
return ptr; /* Old allocation still OK */
memcpy(nptr, ptr, new_size);
- objstore_free_buddy(ptr);
+ lpsm_free_buddy(ptr);
return nptr;
}
}
diff --git a/arena.c b/arena.c
index 3ebd885..6c77601 100644
--- a/arena.c
+++ b/arena.c
@@ -12,9 +12,9 @@
* ----------------------------------------------------------------------- */
/*
- * objstore.c
+ * arena.c
*
- * Persistent object store implemented using memory-mapping tricks
+ * Persistent memory arena implemented using memory-mapping tricks
*/
#include <assert.h>
@@ -36,7 +36,7 @@
#include <sys/resource.h>
#include <sys/wait.h>
-#include "objstore.h"
+#include "lpsm.h"
#include "internals.h"
/* This might end up being a bitmask eventually */
@@ -50,10 +50,10 @@ enum page_status {
* one active object store is supported, due to the need to trap
* SIGSEGV.
*/
-struct ObjStore *objstore_os_struct;
+struct ObjStore *lpsm_os_struct;
/* Wrappers for read() and write() which retries if incomplete */
-static ssize_t objstore_read(int fd, void *buf, size_t count)
+static ssize_t lpsm_read(int fd, void *buf, size_t count)
{
char *bufp = buf;
ssize_t total = 0;
@@ -77,7 +77,7 @@ static ssize_t objstore_read(int fd, void *buf, size_t count)
return total;
}
-static ssize_t objstore_write(int fd, void *buf, size_t count)
+static ssize_t lpsm_write(int fd, void *buf, size_t count)
{
char *bufp = buf;
ssize_t total = 0;
@@ -104,9 +104,9 @@ static ssize_t objstore_write(int fd, void *buf, size_t count)
/*
* SIGSEGV handler for persistent object store
*/
-static void objstore_sigsegv(int signal, siginfo_t *siginfo, void *ptr)
+static void lpsm_sigsegv(int signal, siginfo_t *siginfo, void *ptr)
{
- struct ObjStore *os = objstore_os_struct;
+ struct ObjStore *os = lpsm_os_struct;
void *page;
uintptr_t npage, offset;
char *pageinfo;
@@ -177,9 +177,9 @@ static void objstore_sigsegv(int signal, siginfo_t *siginfo, void *ptr)
* as well as during-execution garbage collect.
* THIS ROUTINE SHOULD BE INVOKED WITH LOCK HELD ON THE LOG FILE.
*/
-static int objstore_log_writeback(void)
+static int lpsm_log_writeback(void)
{
- struct ObjStore *os = objstore_os_struct;
+ struct ObjStore *os = lpsm_os_struct;
struct ObjStore_LogRecord record;
off_t position, last_commit;
struct flock lockmain;
@@ -187,7 +187,7 @@ static int objstore_log_writeback(void)
last_commit = 0; /* Last COMMIT record found */
position = lseek(os->log_fd, 0, SEEK_SET);
- while ( objstore_read(os->log_fd, &record, sizeof(record)) == sizeof(record) ) {
+ while ( lpsm_read(os->log_fd, &record, sizeof(record)) == sizeof(record) ) {
if ( record.magic != LOGRECORD_MAGIC )
break; /* Bad magic, assume rest of log corrupt */
if ( record.record_type == osrec_commit ) {
@@ -208,7 +208,7 @@ static int objstore_log_writeback(void)
position = lseek(os->log_fd, 0, SEEK_SET);
- while ( objstore_read(os->log_fd, &record, sizeof(record))
+ while ( lpsm_read(os->log_fd, &record, sizeof(record))
== sizeof(record) && position < last_commit ) {
if ( record.magic != LOGRECORD_MAGIC )
break; /* Bad magic, assume rest of log corrupt */
@@ -230,7 +230,7 @@ static int objstore_log_writeback(void)
os->main_fd, record.offset);
if ( data == MAP_FAILED )
return -1;
- if ( objstore_read(os->log_fd, data, record.size) != record.size )
+ if ( lpsm_read(os->log_fd, data, record.size) != record.size )
return -1; /* Badness */
if ( munmap(data, record.size) )
return -1;
@@ -251,7 +251,7 @@ static int objstore_log_writeback(void)
record.record_type = osrec_commit;
record.size = os->fork_seq;
record.offset = 0x54494d43; /* For debugging */
- if ( objstore_write(os->log_fd, &record, sizeof(record)) < sizeof(record) )
+ if ( lpsm_write(os->log_fd, &record, sizeof(record)) < sizeof(record) )
return -1;
fsync(os->log_fd); /* Indicate log recovery complete */
@@ -262,9 +262,9 @@ static int objstore_log_writeback(void)
/*
* Routine to do log recovery
*/
-static int objstore_recover_log(void)
+static int lpsm_recover_log(void)
{
- struct ObjStore *os = objstore_os_struct;
+ struct ObjStore *os = lpsm_os_struct;
struct flock lock;
int rv = 0;
@@ -276,7 +276,7 @@ static int objstore_recover_log(void)
while ( fcntl(os->log_fd, F_SETLKW, &lock) == -1 && errno == EINTR );
/* Do log recovery, and write initial commit record. */
- rv = objstore_log_writeback();
+ rv = lpsm_log_writeback();
/* Increase the sequence number, since we just wrote a commit. */
os->fork_seq++;
@@ -293,7 +293,7 @@ static int objstore_recover_log(void)
* playback (crash recovery) if the log file exists
* and is nonempty.
*/
-void *objstore_init(const char *main_file, const char *log_file, size_t *arena_len)
+void *lpsm_arena_init(const char *main_file, const char *log_file, size_t *arena_len)
{
struct ObjStore *os;
void *arena_ptr;
@@ -304,7 +304,7 @@ void *objstore_init(const char *main_file, const char *log_file, size_t *arena_l
arena_ptr = ARENA_ADDRESS;
- objstore_os_struct = os = malloc(sizeof(struct ObjStore));
+ lpsm_os_struct = os = malloc(sizeof(struct ObjStore));
if ( !os )
goto errx0;
@@ -331,7 +331,7 @@ void *objstore_init(const char *main_file, const char *log_file, size_t *arena_l
goto errx3;
/* Now, do log recovery if needed */
- if ( objstore_recover_log() )
+ if ( lpsm_recover_log() )
goto errx3;
/* Allocate arena memory space */
@@ -370,7 +370,7 @@ void *objstore_init(const char *main_file, const char *log_file, size_t *arena_l
/* All pages clean at this time */
memset(os->pageinfo, page_clean, len_pages);
- sigact.sa_sigaction = objstore_sigsegv;
+ sigact.sa_sigaction = lpsm_sigsegv;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = SA_RESTART|SA_SIGINFO;
if ( sigaction(SIGSEGV, &sigact, &os->oldact) )
@@ -408,14 +408,14 @@ void *objstore_init(const char *main_file, const char *log_file, size_t *arena_l
* Returns 0 on synchronous completion, 1 if the checkpoint was skipped,
* (pid_t)-1 on error, or the pid_t of the asynchronous process. Note:
* if an asynchronous process is launched, and the next call uses
- * OBJSYNC_NONE, then it is up to the parent process to wait for the
+ * PSMSYNC_NONE, then it is up to the parent process to wait for the
* launched processes; this process only remembers the last process launched.
* FIXME: perhaps we should double-fork these processes?
*/
-pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
+pid_t lpsm_checkpoint(double gc_factor, enum psmsync wait)
{
static pid_t last_sync = 0;
- struct ObjStore *os = objstore_os_struct;
+ struct ObjStore *os = lpsm_os_struct;
pid_t f, w;
char *pi, *epi;
void *page;
@@ -426,9 +426,9 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
if ( last_sync ) {
int status;
switch (wait) {
- case OBJSYNC_NONE:
+ case PSMSYNC_NONE:
break;
- case OBJSYNC_SKIP:
+ case PSMSYNC_SKIP:
w = waitpid(last_sync, &status, WNOHANG);
if ( w == 0 )
return 1; /* Skip */
@@ -439,8 +439,8 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
return (pid_t)-1; /* Badness */
}
break;
- case OBJSYNC_WAIT:
- case OBJSYNC_SYNC:
+ case PSMSYNC_WAIT:
+ case PSMSYNC_SYNC:
w = waitpid(last_sync, &status, 0);
if ( w == (pid_t)-1 ) {
if ( errno != ECHILD )
@@ -466,7 +466,7 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
os->dirty_count = 0; /* No pages dirty */
os->fork_seq++; /* Increase next sequence number */
- if ( wait == OBJSYNC_SYNC ) {
+ if ( wait == PSMSYNC_SYNC ) {
int status;
waitpid(f, &status, 0);
last_sync = 0;
@@ -498,7 +498,7 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
/* Make sure we were indeed next in turn */
lseek(os->log_fd, -(off_t)sizeof(last_rec), SEEK_END);
- if ( objstore_read(os->log_fd, &last_rec, sizeof(last_rec)) < sizeof(last_rec) ||
+ if ( lpsm_read(os->log_fd, &last_rec, sizeof(last_rec)) < sizeof(last_rec) ||
last_rec.magic != LOGRECORD_MAGIC ) {
/* Something bad happened... */
kill(getppid(), SIGABRT); /* Kill main process */
@@ -528,9 +528,9 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
record.size += os->pagesize;
}
- if ( objstore_write(os->log_fd, &record, sizeof(record))
+ if ( lpsm_write(os->log_fd, &record, sizeof(record))
< sizeof(record) ||
- objstore_write(os->log_fd, page, record.size) < record.size ) {
+ lpsm_write(os->log_fd, page, record.size) < record.size ) {
kill(getppid(), SIGABRT); /* Kill main process */
_exit(99);
}
@@ -544,7 +544,7 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
record.record_type = osrec_commit;
record.size = os->fork_seq;
record.offset = (off_t)0x54494d43;
- if ( objstore_write(os->log_fd, &record, sizeof(record)) < sizeof(record) ) {
+ if ( lpsm_write(os->log_fd, &record, sizeof(record)) < sizeof(record) ) {
kill(getppid(), SIGABRT);
_exit(99);
}
@@ -558,7 +558,7 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
them out of the shadow array. The biggest problem with that
is that it probably can't be done in the background, unlike
this method. Leave this as-is for now. */
- if ( objstore_log_writeback() ) {
+ if ( lpsm_log_writeback() ) {
kill(getppid(), SIGABRT);
_exit(99);
}
@@ -579,9 +579,9 @@ pid_t objstore_checkpoint(double gc_factor, enum objsync_enum wait)
* specifically mremap() and knowing that we probably can extend
* it without changing the virtual address.
*/
-int objstore_extend(size_t new_size)
+int lpsm_extend(size_t new_size)
{
- struct ObjStore *os = objstore_os_struct;
+ struct ObjStore *os = lpsm_os_struct;
struct flock lock;
void *newp, *infop;
off_t file_size;
@@ -667,14 +667,14 @@ int objstore_extend(size_t new_size)
/*
* Shut down the object store, free all resources.
- * THIS DOES NOT CHECKPOINT - call objstore_checkpoint() first
+ * THIS DOES NOT CHECKPOINT - call lpsm_checkpoint() first
* if you want that functionality. Calling this function without
- * first checkpointing and then calling objstore_init() can be used
+ * first checkpointing and then calling lpsm_arena_init() can be used
* to (very slowly) roll back to the last commit point.
*/
-void objstore_shutdown(void)
+void lpsm_shutdown(void)
{
- struct ObjStore *os = objstore_os_struct;
+ struct ObjStore *os = lpsm_os_struct;
munmap(os->arena, os->arena_len);
free(os->pageinfo);
diff --git a/internals.h b/internals.h
index 1ef7f35..a331e0f 100644
--- a/internals.h
+++ b/internals.h
@@ -20,7 +20,7 @@
#ifndef OBJSTORE_INTERNALS_H
#define OBJSTORE_INTERNALS_H
-#include "objstore.h" /* Main include file */
+#include "lpsm.h" /* Main include file */
#include "system.h" /* System-specific constants */
struct ObjStore {
@@ -51,6 +51,6 @@ struct ObjStore_LogRecord {
off_t offset; /* Offset of data */
};
-extern struct ObjStore *objstore_os_struct;
+extern struct ObjStore *lpsm_os_struct;
#endif
diff --git a/lpsm.h b/lpsm.h
index 4b96795..cfbab52 100644
--- a/lpsm.h
+++ b/lpsm.h
@@ -12,49 +12,51 @@
* ----------------------------------------------------------------------- */
/*
- * objstore.h
+ * lpsm.h
*
- * Public header file for the persistent object store
+ * Public header file for the Linux Persistent Memory
*/
-#ifndef OBJSTORE_H
-#define OBJSTORE_H
+#ifndef LPSM_H
+#define LPSM_H
#include <stdlib.h>
#include <signal.h>
#include <inttypes.h>
+#include <sys/types.h>
/* Low-level core routines */
/* When checkpointing, specify the level of synchronicity required */
-enum objsync_enum {
- OBJSYNC_NONE, /* No synchronicity */
- OBJSYNC_SKIP, /* Skip if previous writeback still running */
- OBJSYNC_WAIT, /* Wait if previous writeback still running */
- OBJSYNC_SYNC /* Wait until this writeback finishes */
+enum psmsync {
+ PSMSYNC_NONE, /* No synchronicity */
+ PSMSYNC_SKIP, /* Skip if previous writeback still running */
+ PSMSYNC_WAIT, /* Wait if previous writeback still running */
+ PSMSYNC_SYNC /* Wait until this writeback finishes */
};
-void *objstore_init(const char *, const char *, size_t *);
-int objstore_checkpoint(double, enum objsync_enum);
-int objstore_extend(size_t);
-void objstore_shutdown(void);
+void *lpsm_arena_init(const char *, const char *, size_t *);
+pid_t lpsm_checkpoint(double, enum psmsync);
+int lpsm_extend(size_t);
+void lpsm_shutdown(void);
/* Arena management routines */
/* The allocator gives us this many "root pointers" for our own use. They
are initialized to NULL when a new arena is created, and are intended
- to be used to find all the data structures. objstore_arena_init()
+ to be used to find all the data structures. lpsm_arena_init()
returns a pointer to this array (if successful). */
-#define ROOT_DATA_POINTERS 32
+#define LPSM_ROOT_POINTERS 32
-void **objstore_arena_init(const char *, const char *);
-void *objstore_malloc(size_t);
-void objstore_free(void *);
-void *objstore_realloc(void *, size_t);
-struct objstore_arena_stats {
+void **lpsm_init(const char *, const char *);
+void *lpsm_malloc(size_t);
+void lpsm_free(void *);
+void *lpsm_realloc(void *, size_t);
+struct lpsm_alloc_stats {
size_t size;
size_t free;
size_t alloc;
};
-struct objstore_arena_stats *objstore_arena_stats(void);
-#endif
+struct lpsm_alloc_stats *lpsm_alloc_stats(void);
+
+#endif /* LPSM_H */
diff --git a/sysdep/i386.h b/sysdep/i386.h
index b8ce38b..d838865 100644
--- a/sysdep/i386.h
+++ b/sysdep/i386.h
@@ -22,4 +22,7 @@
#include "sysdep/32bit.h"
/* This is where we map the database file - must be constant */
-#define ARENA_ADDRESS ((void *)0x5f000000UL)
+/* This is assigned so that if we run on x86-64 or with Andrea's
+ "3.5 GB userspace" patches we can fit a 2 GB database and still
+ have space for the stack... */
+#define ARENA_ADDRESS ((void *)0x58000000UL)
diff --git a/testalloc.c b/testalloc.c
index d93ceba..4d5655a 100644
--- a/testalloc.c
+++ b/testalloc.c
@@ -18,7 +18,7 @@
#include <math.h>
#include <unistd.h>
#include <limits.h>
-#include "objstore.h"
+#include "lpsm.h"
#define COUNT 32768
#define SLOTS 1024
@@ -62,15 +62,15 @@ int main(int argc, char *argv[])
memset(areas, 0, sizeof(areas));
memset(sizes, 0, sizeof(sizes));
- if ( !(root_ptr = objstore_arena_init("arena.dat", "arena.log")) ) {
- fprintf(stderr, "%s: objstore_arena_init() failed\n", argv[0]);
+ if ( !(root_ptr = lpsm_init("arena.dat", "arena.log")) ) {
+ fprintf(stderr, "%s: lpsm_arena_init() failed\n", argv[0]);
return 1;
}
printf("Arena: initialized, %d root pointers at %p\n",
- ROOT_DATA_POINTERS, root_ptr);
+ LPSM_ROOT_POINTERS, root_ptr);
- objstore_checkpoint(0.0, OBJSYNC_WAIT);
+ lpsm_checkpoint(0.0, PSMSYNC_WAIT);
for ( i = 0 ; i < COUNT ; i++ ) {
slot = rand() % SLOTS;
@@ -79,13 +79,13 @@ int main(int argc, char *argv[])
if ( rand() % 1 ) {
printf("Free: %d (0x%08x) bytes at %p\n",
sizes[slot], sizes[slot], areas[slot]);
- objstore_free(areas[slot]);
+ lpsm_free(areas[slot]);
areas[slot] = NULL;
occupied -= sizes[slot];
} else {
rnd = (double)rand()/RAND_MAX;
newsize = (int)pow(2.0, MAXLOG*pow(rnd,3.0));
- nptr = objstore_realloc(areas[slot], newsize);
+ nptr = lpsm_realloc(areas[slot], newsize);
if ( nptr ) {
printf("Realloc: %d bytes at %p -> %d bytes at %p\n",
sizes[slot], areas[slot], newsize, nptr);
@@ -102,7 +102,7 @@ int main(int argc, char *argv[])
} else {
rnd = (double)rand()/RAND_MAX;
sizes[slot] = (int)pow(2.0, MAXLOG*pow(rnd,5.0));
- areas[slot] = objstore_malloc(sizes[slot]);
+ areas[slot] = lpsm_malloc(sizes[slot]);
if ( areas[slot] ) {
printf("Alloc: %d (0x%08x) bytes at %p\n",
sizes[slot], sizes[slot], areas[slot]);
@@ -116,13 +116,13 @@ int main(int argc, char *argv[])
if ( (i & 255) == 0 ) {
printf("Arena: checkpointing...\n");
- objstore_checkpoint(0.1, OBJSYNC_SKIP);
+ lpsm_checkpoint(0.1, PSMSYNC_SKIP);
}
printf("Arena: %ld bytes officially occupied\n", occupied);
}
fprintf(stderr, "ready...\n");
- objstore_checkpoint(0.0, OBJSYNC_SYNC); /* Synchronous checkpoint */
+ lpsm_checkpoint(0.0, PSMSYNC_SYNC); /* Synchronous checkpoint */
return 0;
}
diff --git a/testbuddy.c b/testbuddy.c
index 3b8ea5e..5bb441a 100644
--- a/testbuddy.c
+++ b/testbuddy.c
@@ -15,7 +15,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include "objstore.h"
+#include "lpsm.h"
static int testsizes[] = {
265299,
@@ -92,20 +92,20 @@ int main(int argc, char *argv[])
unlink("buddy.dat");
unlink("buddy.log");
- if ( !objstore_arena_init("buddy.dat", "buddy.log") ) {
- fprintf(stderr, "%s: objstore_arena_init() failed\n", argv[0]);
+ if ( !lpsm_init("buddy.dat", "buddy.log") ) {
+ fprintf(stderr, "%s: lpsm_arena_init() failed\n", argv[0]);
return 1;
}
- objstore_checkpoint(0.0, OBJSYNC_WAIT);
+ lpsm_checkpoint(0.0, PSMSYNC_WAIT);
for ( i = 0 ; i < 64 ; i++ ) {
- areas[i] = objstore_malloc(testsizes[i]);
+ areas[i] = lpsm_malloc(testsizes[i]);
printf("Alloc: %8d (0x%08x) bytes at %p\n",
testsizes[i], testsizes[i], areas[i]);
}
- objstore_checkpoint(0.0, OBJSYNC_SYNC);
+ lpsm_checkpoint(0.0, PSMSYNC_SYNC);
return 0;
}
diff --git a/testrecovery.c b/testrecovery.c
index 0dbe66c..0ebf816 100644
--- a/testrecovery.c
+++ b/testrecovery.c
@@ -30,7 +30,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include "objstore.h"
+#include "lpsm.h"
#define COUNT 262144
#define SLOTS 4096
@@ -83,25 +83,25 @@ int main(int argc, char *argv[])
unlink("arena.dat");
unlink("arena.log");
- if ( !(root_ptr = objstore_arena_init("arena.dat", "arena.log")) ) {
- fprintf(stderr, "%s: objstore_arena_init() failed\n", argv[0]);
+ if ( !(root_ptr = lpsm_init("arena.dat", "arena.log")) ) {
+ fprintf(stderr, "%s: lpsm_arena_init() failed\n", argv[0]);
return 1;
}
printf("Arena: initialized, %d root pointers at %p\n",
- ROOT_DATA_POINTERS, root_ptr);
+ LPSM_ROOT_POINTERS, root_ptr);
- root_ptr[0] = misc_ptr = objstore_malloc(sizeof(struct misc_info));
- root_ptr[1] = areas = objstore_malloc(sizeof(void *) * SLOTS);
- root_ptr[2] = sizes = objstore_malloc(sizeof(int) * SLOTS);
+ root_ptr[0] = misc_ptr = lpsm_malloc(sizeof(struct misc_info));
+ root_ptr[1] = areas = lpsm_malloc(sizeof(void *) * SLOTS);
+ root_ptr[2] = sizes = lpsm_malloc(sizeof(int) * SLOTS);
misc_ptr->count = misc_ptr->occupied = 0;
memset(areas, 0, sizeof(areas));
memset(sizes, 0, sizeof(sizes));
- objstore_checkpoint(0.0, OBJSYNC_SYNC);
- objstore_shutdown();
+ lpsm_checkpoint(0.0, PSMSYNC_SYNC);
+ lpsm_shutdown();
/* Become our own process group and ignore SIGTERM to make it easier to
"kill everything". Become our own session to keep shell job control
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
gettimeofday(&start_time, NULL);
- root_ptr = objstore_arena_init("arena.dat", "arena.log");
+ root_ptr = lpsm_init("arena.dat", "arena.log");
gettimeofday(&init_time, NULL);
@@ -175,7 +175,7 @@ int main(int argc, char *argv[])
if ( areas[slot] ) {
if ( rand() % 1 ) {
- objstore_free(areas[slot]);
+ lpsm_free(areas[slot]);
printf("Free: %d (0x%08x) bytes at %p\n",
sizes[slot], sizes[slot], areas[slot]);
areas[slot] = NULL;
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
} else {
rnd = (double)rand()/RAND_MAX;
newsize = (int)pow(2.0, MAXLOG*pow(rnd,3.0));
- nptr = objstore_realloc(areas[slot], newsize);
+ nptr = lpsm_realloc(areas[slot], newsize);
if ( nptr ) {
printf("Realloc: %d bytes at %p -> %d bytes at %p\n",
sizes[slot], areas[slot], newsize, nptr);
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
} else {
rnd = (double)rand()/RAND_MAX;
sizes[slot] = (int)pow(2.0, MAXLOG*pow(rnd,5.0));
- areas[slot] = objstore_malloc(sizes[slot]);
+ areas[slot] = lpsm_malloc(sizes[slot]);
if (areas[slot]) {
printf("Alloc: %d (0x%08x) bytes at %p\n",
sizes[slot], sizes[slot], areas[slot]);
@@ -217,13 +217,13 @@ int main(int argc, char *argv[])
if ( (i & 255) == 0 ) {
printf("Arena: checkpointing, count = %d\n", i);
- objstore_checkpoint(0.1, OBJSYNC_SKIP);
+ lpsm_checkpoint(0.1, PSMSYNC_SKIP);
}
printf("Arena: %ld bytes officially occupied\n", misc_ptr->occupied);
}
/* If the loop finishes, exit... */
fprintf(stderr, "ready...\n");
- objstore_checkpoint(0.0, OBJSYNC_SYNC); /* Synchronous checkpoint */
+ lpsm_checkpoint(0.0, PSMSYNC_SYNC); /* Synchronous checkpoint */
exit(0);
}
}
diff --git a/teststore.c b/teststore.c
index 532e7aa..2aa6a4a 100644
--- a/teststore.c
+++ b/teststore.c
@@ -15,14 +15,14 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include "objstore.h"
+#include "lpsm.h"
int main(int argc, char *argv[])
{
void *buf;
int arena_len = 16384;
- buf = objstore_init("test.dat", "test.log", &arena_len);
+ buf = lpsm_arena_init("test.dat", "test.log", &arena_len);
printf("Read from first page: %s\n", (char *)buf);
@@ -30,16 +30,16 @@ int main(int argc, char *argv[])
strcpy((char *)buf + 8192, "This is the third page!");
printf("Read from third page: %s\n", (char *)buf + 8192);
- objstore_checkpoint(0.5, OBJSYNC_WAIT);
+ lpsm_checkpoint(0.5, PSMSYNC_WAIT);
strcpy((char *)buf + 8192, "This is also the third page!");
printf("Read from third page: %s\n", (char *)buf + 8192);
- objstore_checkpoint(0.0, OBJSYNC_WAIT);
+ lpsm_checkpoint(0.0, PSMSYNC_WAIT);
- objstore_extend(65536);
+ lpsm_extend(65536);
strcpy((char *)buf + 32768, "This is the ninth page!");
- objstore_checkpoint(0.0, OBJSYNC_SYNC);
+ lpsm_checkpoint(0.0, PSMSYNC_SYNC);
return 0;
}