aboutsummaryrefslogtreecommitdiffstats
path: root/arena.c
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 /arena.c
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.
Diffstat (limited to 'arena.c')
-rw-r--r--arena.c80
1 files changed, 40 insertions, 40 deletions
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);