[pypy-commit] stmgc c8-new-page-handling: setting up the initial configuration
Raemi
noreply at buildbot.pypy.org
Thu Sep 18 16:54:18 CEST 2014
Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: c8-new-page-handling
Changeset: r1391:085233d40f72
Date: 2014-09-18 15:16 +0200
http://bitbucket.org/pypy/stmgc/changeset/085233d40f72/
Log: setting up the initial configuration
diff --git a/c8/stm/core.h b/c8/stm/core.h
--- a/c8/stm/core.h
+++ b/c8/stm/core.h
@@ -25,6 +25,7 @@
#define FIRST_OBJECT_PAGE ((READMARKER_END + 4095) / 4096UL)
#define FIRST_NURSERY_PAGE FIRST_OBJECT_PAGE
#define END_NURSERY_PAGE (FIRST_NURSERY_PAGE + NB_NURSERY_PAGES)
+#define NB_SHARED_PAGES (NB_PAGES - END_NURSERY_PAGE)
#define READMARKER_START ((FIRST_OBJECT_PAGE * 4096UL) >> 4)
#define FIRST_READMARKER_PAGE (READMARKER_START / 4096UL)
@@ -97,6 +98,7 @@
static char *stm_object_pages;
+static char *stm_file_pages;
static int stm_object_pages_fd;
static stm_thread_local_t *stm_all_thread_locals = NULL;
diff --git a/c8/stm/setup.c b/c8/stm/setup.c
--- a/c8/stm/setup.c
+++ b/c8/stm/setup.c
@@ -4,32 +4,54 @@
#include <fcntl.h> /* For O_* constants */
-static char *setup_mmap(char *reason, int *map_fd)
+static void setup_mmap(char *reason)
{
- char name[128] = "/__stmgc_c8__";
+ char name[] = "/__stmgc_c8__";
/* Create the big shared memory object, and immediately unlink it.
There is a small window where if this process is killed the
object is left around. It doesn't seem possible to do anything
about it...
*/
- int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
+ stm_object_pages_fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
shm_unlink(name);
- if (fd == -1) {
+ if (stm_object_pages_fd == -1)
stm_fatalerror("%s failed (stm_open): %m", reason);
+
+ if (ftruncate(stm_object_pages_fd, NB_SHARED_PAGES) != 0)
+ stm_fatalerror("%s failed (ftruncate): %m", reason);
+
+ stm_file_pages = mmap(NULL, NB_SHARED_PAGES * 4096UL,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_NORESERVE,
+ stm_object_pages_fd, 0);
+
+ if (stm_file_pages == MAP_FAILED)
+ stm_fatalerror("%s failed (mmap): %m", reason);
+
+
+ /* reserve the whole virtual memory space of the program for
+ all segments: */
+ stm_object_pages = mmap(NULL, TOTAL_MEMORY,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS,
+ -1, 0);
+ if (stm_object_pages == MAP_FAILED)
+ stm_fatalerror("%s failed (mmap): %m", reason);
+
+ /* remap the shared part of the segments to the file pages */
+ long l;
+ for (l = 0; l < NB_SEGMENTS; l++) {
+ char *result = mmap(
+ stm_object_pages + (l * NB_PAGES + END_NURSERY_PAGE) * 4096UL, /* addr */
+ NB_SHARED_PAGES * 4096UL, /* len */
+ PROT_READ | PROT_WRITE,
+ MAP_FIXED | MAP_SHARED | MAP_NORESERVE,
+ stm_object_pages_fd, 0); /* file & offset */
+ if (result == MAP_FAILED)
+ stm_fatalerror("%s failed (mmap): %m", reason);
}
- if (ftruncate(fd, TOTAL_MEMORY) != 0) {
- stm_fatalerror("%s failed (ftruncate): %m", reason);
- }
- char *result = mmap(NULL, TOTAL_MEMORY,
- PROT_READ | PROT_WRITE,
- MAP_PAGES_FLAGS & ~MAP_ANONYMOUS, fd, 0);
- if (result == MAP_FAILED) {
- stm_fatalerror("%s failed (mmap): %m", reason);
- }
- *map_fd = fd;
- return result;
}
static void close_fd_mmap(int map_fd)
{
@@ -52,7 +74,7 @@
(FIRST_READMARKER_PAGE - 2) * 4096UL,
PROT_NONE);
- /* STM_SEGMENT is in page 1 */
+ /* STM_SEGMENT-TL is in page 1 */
}
}
@@ -74,8 +96,12 @@
(FIRST_READMARKER_PAGE * 4096UL));
assert(_STM_FAST_ALLOC <= NB_NURSERY_PAGES * 4096);
- stm_object_pages = setup_mmap("initial stm_object_pages mmap()",
- &stm_object_pages_fd);
+ setup_mmap("initial stm_object_pages mmap()");
+
+ assert(stm_object_pages_fd);
+ assert(stm_object_pages);
+ assert(stm_file_pages);
+
setup_protection_settings();
long i;
diff --git a/c8/stm/setup.h b/c8/stm/setup.h
--- a/c8/stm/setup.h
+++ b/c8/stm/setup.h
@@ -1,4 +1,4 @@
-static char *setup_mmap(char *reason, int *map_fd);
+static void setup_mmap(char *reason);
static void close_fd_mmap(int map_fd);
static void setup_protection_settings(void);
static pthread_t *_get_cpth(stm_thread_local_t *);
More information about the pypy-commit
mailing list